Debian Codegraph @

data/munin/groonga_cpu_load_

raw
1 #!/bin/sh
2
3 #%# family=auto
4 #%# capabilities=autoconf suggest
5
6 case "$1" in
7 autoconf|detect)
8 pid_paths=
9 if [ -n "${pid_path}" ]; then
10 pid_paths="${pid_paths}${pid_paths:+ }${pid_path}"
11 fi
12 # For backward compatibility. Remove me when 5.0.0.
13 if [ -n "${pid_file}" ]; then
14 pid_paths="${pid_paths}${pid_paths:+ }${pid_file}"
15 fi
16 if [ -n "${http_pid_path}" ]; then
17 pid_paths="${pid_paths}${pid_paths:+ }${http_pid_path}"
18 fi
19 if [ -n "${httpd_pid_path}" ]; then
20 pid_paths="${pid_paths}${pid_paths:+ }${httpd_pid_path}"
21 fi
22 if [ -n "${gqtp_pid_path}" ]; then
23 pid_paths="${pid_paths}${pid_paths:+ }${gqtp_pid_path}"
24 fi
25 if [ -z "${pid_paths}" ]; then
26 message="no (No PID path is specified. Specify "
27 message="${message} env.pid_path, env.http_pid_path, "
28 message="${message} env.httpd_pid_path and/or env.gqtp_pid_path.)"
29 echo "${message}"
30 exit 1
31 fi
32
33 for _pid_path in ${pid_paths}; do
34 if [ -f "${_pid_path}" ]; then
35 echo "yes"
36 exit 0
37 fi
38 done
39
40 echo "no (All PID paths don't exist: ${pid_paths})"
41 exit 1
42 ;;
43 suggest)
44 if [ -n "${http_pid_path}" -a -f "${http_pid_path}" ]; then
45 echo "http"
46 fi
47 if [ -n "${httpd_pid_path}" -a -f "${httpd_pid_path}" ]; then
48 echo "httpd"
49 fi
50 if [ -n "${gqtp_pid_path}" -a -f "${gqtp_pid_path}" ]; then
51 echo "gqtp"
52 fi
53 exit 0
54 ;;
55 config)
56 if [ -z "${label}" ]; then
57 title="groonga: CPU load"
58 else
59 title="groonga: ${label}: CPU load"
60 fi
61 cat <<EOF
62 graph_title ${title}
63 graph_vlabel CPU load (%)
64 graph_category groonga
65 graph_info groonga CPU load
66
67 cpu_load.label CPU load
68 cpu_load.type GAUGE
69 EOF
70 exit 0
71 ;;
72 *)
73 ;;
74 esac
75
76 server_type="${0##*_}"
77 if [ -n "${server_type}" ]; then
78 pid_path_variable_name="${server_type}_pid_path"
79 else
80 # For backward compatibility. Remove me when 5.0.0.
81 if [ -z "${pid_path}" -a -n "${pid_file}" ]; then
82 pid_path_variable_name="pid_file"
83 else
84 pid_path_variable_name="pid_path"
85 fi
86 fi
87 _pid_path=$(eval "echo \${${pid_path_variable_name}}")
88 if [ -z "${_pid_path}" ]; then
89 echo "PID path isn't specified by env.${pid_path_variable_name}" 1>&2
90 exit 1
91 fi
92 if [ ! -f "${_pid_path}" ]; then
93 echo "PID path doesn't exist: ${_pid_path}" 1>&2
94 exit 1
95 fi
96
97 groonga_pid=$(cat ${_pid_path})
98 top_for_groonga=$(top -b -n 1 -p ${groonga_pid} | grep ${groonga_pid})
99 load_in_percent=$(echo ${top_for_groonga} | sed -r -e 's/ +/ /g' | cut -d' ' -f 9)
100 echo "cpu_load.value ${load_in_percent}"