| 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: memory usage" |
| 58 |
else |
| 59 |
title="groonga: ${label}: memory usage" |
| 60 |
fi |
| 61 |
cat <<EOF |
| 62 |
graph_title ${title} |
| 63 |
graph_vlabel memory usage |
| 64 |
graph_category groonga |
| 65 |
graph_info groonga memory usage |
| 66 |
|
| 67 |
rss.label resident set size |
| 68 |
rss.type GAUGE |
| 69 |
vsz.label virtual memory size |
| 70 |
vsz.type GAUGE |
| 71 |
EOF |
| 72 |
exit 0 |
| 73 |
;; |
| 74 |
*) |
| 75 |
;; |
| 76 |
esac |
| 77 |
|
| 78 |
server_type="${0##*_}" |
| 79 |
if [ -n "${server_type}" ]; then |
| 80 |
pid_path_variable_name="${server_type}_pid_path" |
| 81 |
else |
| 82 |
# For backward compatibility. Remove me when 5.0.0. |
| 83 |
if [ -z "${pid_path}" -a -n "${pid_file}" ]; then |
| 84 |
pid_path_variable_name="pid_file" |
| 85 |
else |
| 86 |
pid_path_variable_name="pid_path" |
| 87 |
fi |
| 88 |
fi |
| 89 |
_pid_path=$(eval "echo \${${pid_path_variable_name}}") |
| 90 |
if [ -z "${_pid_path}" ]; then |
| 91 |
echo "PID path isn't specified by env.${pid_path_variable_name}" 1>&2 |
| 92 |
exit 1 |
| 93 |
fi |
| 94 |
if [ ! -f "${_pid_path}" ]; then |
| 95 |
echo "PID path doesn't exist: ${_pid_path}" 1>&2 |
| 96 |
exit 1 |
| 97 |
fi |
| 98 |
|
| 99 |
groonga_pid=$(cat ${_pid_path}) |
| 100 |
read rss_in_kb vsz_in_kb <<EOC |
| 101 |
$(ps h -o rss,vsz -p ${groonga_pid}) |
| 102 |
EOC |
| 103 |
echo "rss.value ${rss_in_kb}000" |
| 104 |
echo "vsz.value ${vsz_in_kb}000" |