root / plugins / munin / healthcheck_url @ 17f78427
Historique | Voir | Annoter | Télécharger (5,24 ko)
| 1 |
#!/bin/bash |
|---|---|
| 2 |
# |
| 3 |
#healthcheck on munin |
| 4 |
#check site speed. |
| 5 |
#egrep contents string |
| 6 |
# ... and alert. |
| 7 |
# |
| 8 |
#programed by rti (hiroyuki fujie) super.rti@gmail.com @super_rti |
| 9 |
#LICENSE: NYSL (public domain) |
| 10 |
# |
| 11 |
#config file |
| 12 |
# /etc/munin/plugin-conf.d/munin-node |
| 13 |
# |
| 14 |
#example minimum config |
| 15 |
#--------------------------------------------------- |
| 16 |
#[healthcheck_url] |
| 17 |
#env.url_1 http://127.0.0.1/ |
| 18 |
#--------------------------------------------------- |
| 19 |
# |
| 20 |
#check two site |
| 21 |
#--------------------------------------------------- |
| 22 |
#[healthcheck_url] |
| 23 |
#env.url_1 http://127.0.0.1/ |
| 24 |
#env.url_2 http://www.google.com/ |
| 25 |
#--------------------------------------------------- |
| 26 |
# |
| 27 |
#check three site |
| 28 |
#--------------------------------------------------- |
| 29 |
#[healthcheck_url] |
| 30 |
#env.url_1 http://127.0.0.1/ |
| 31 |
#env.url_2 http://www.google.com/ |
| 32 |
#env.url_3 http://www.yahoo.com/ |
| 33 |
#--------------------------------------------------- |
| 34 |
# |
| 35 |
#set name |
| 36 |
#--------------------------------------------------- |
| 37 |
#[healthcheck_url] |
| 38 |
#env.url_1 http://127.0.0.1/ |
| 39 |
#env.name_1 homhom |
| 40 |
#--------------------------------------------------- |
| 41 |
# |
| 42 |
#check over proxy |
| 43 |
#--------------------------------------------------- |
| 44 |
#[healthcheck_url] |
| 45 |
#env.url_1 http://127.0.0.1/ |
| 46 |
#env.proxy_1 127.0.0.1:8080 |
| 47 |
#--------------------------------------------------- |
| 48 |
# |
| 49 |
#set slow speed(second) |
| 50 |
#--------------------------------------------------- |
| 51 |
#[healthcheck_url] |
| 52 |
#env.url_1 http://127.0.0.1/ |
| 53 |
#env.slowspeed_1 30 |
| 54 |
#--------------------------------------------------- |
| 55 |
# |
| 56 |
#grep string |
| 57 |
#--------------------------------------------------- |
| 58 |
#[healthcheck_url] |
| 59 |
#env.url_1 http://127.0.0.1/ |
| 60 |
#env.htmlgrep_1 saysaya |
| 61 |
#--------------------------------------------------- |
| 62 |
# |
| 63 |
#check html contents byte size. |
| 64 |
#--------------------------------------------------- |
| 65 |
#[healthcheck_url] |
| 66 |
#env.url_1 http://127.0.0.1/ |
| 67 |
#env.htmlsize_1 50000 #check 50000 bytes over. |
| 68 |
#--------------------------------------------------- |
| 69 |
# |
| 70 |
#full option |
| 71 |
#/etc/munin/plugin-conf.d/munin-node |
| 72 |
#--------------------------------------------------- |
| 73 |
#[healthcheck_url] |
| 74 |
#env.url_1 http://127.0.0.1/ #check url |
| 75 |
#env.htmlgrep_1 apache #check egrep string |
| 76 |
#env.name_1 127.0.0.1 #set line name. default by url domain |
| 77 |
#env.proxy_1 127.0.0.1:8080 #over proxy |
| 78 |
#env.slowspeed_1 30 #slow time on alert |
| 79 |
#env.htmlsize_1 50000 #check 50000 bytes over. |
| 80 |
#--------------------------------------------------- |
| 81 |
# |
| 82 |
# |
| 83 |
|
| 84 |
#edakari speed up. |
| 85 |
CHECKMAX=`env | grep url_ | wc -l` |
| 86 |
let CHECKMAX="$CHECKMAX + 1" |
| 87 |
|
| 88 |
CURL=/usr/bin/curl |
| 89 |
|
| 90 |
if [ "$1" = "autoconf" ]; then |
| 91 |
if [ $CHECKMAX -le 1 ]; then |
| 92 |
echo no |
| 93 |
exit 1 |
| 94 |
fi |
| 95 |
echo yes |
| 96 |
exit 0 |
| 97 |
fi |
| 98 |
|
| 99 |
if [ "$1" = "config" ]; then |
| 100 |
echo 'graph_title site speed (second)' |
| 101 |
echo "graph_args --base 1000 -l 0 --vertical-label second" |
| 102 |
echo 'graph_scale no' |
| 103 |
echo 'graph_vlabel second' |
| 104 |
echo 'graph_category munin' |
| 105 |
echo 'graph_info This graph shows the site speed' |
| 106 |
|
| 107 |
for(( I = 1; I < $CHECKMAX; ++I )) |
| 108 |
do |
| 109 |
eval url=\$url_${I}
|
| 110 |
eval name=\$name_${I}
|
| 111 |
eval slowspeed=\$slowspeed_${I}
|
| 112 |
if [ "x${url}" = "x" ]; then
|
| 113 |
continue |
| 114 |
fi |
| 115 |
if [ "x${name}" = "x" ]; then
|
| 116 |
#default name by domain |
| 117 |
name=`echo $url | sed 's#\.#_#g' | sed -e 's/[^/]*\/\/\([^@]*@\)\?\([^:/]*\).*/\2/'` |
| 118 |
fi |
| 119 |
if [ "x${slowspeed}" = "x" ]; then
|
| 120 |
slowspeed=10 |
| 121 |
fi |
| 122 |
let slowspeed15="slowspeed * 3 / 2" #slowspeed * 1.5 |
| 123 |
|
| 124 |
echo "$name.label $name" |
| 125 |
echo "$name.info $url" |
| 126 |
echo "$name.draw LINE2" |
| 127 |
echo "$name.min -10" |
| 128 |
echo "$name.max ${slowspeed15}"
|
| 129 |
echo "$name.critical 0:${slowspeed}"
|
| 130 |
done |
| 131 |
|
| 132 |
exit 0 |
| 133 |
fi |
| 134 |
|
| 135 |
for(( I = 1; I < $CHECKMAX; ++I )) |
| 136 |
do |
| 137 |
eval url=\$url_${I}
|
| 138 |
eval grep=\$htmlgrep_${I}
|
| 139 |
eval size=\$htmlsize_${I}
|
| 140 |
eval name=\$name_${I}
|
| 141 |
eval proxy=\$proxy_${I}
|
| 142 |
eval slowspeed=\$slowspeed_${I}
|
| 143 |
|
| 144 |
if [ "x${url}" = "x" ]; then
|
| 145 |
continue |
| 146 |
fi |
| 147 |
if [ "x${name}" = "x" ]; then
|
| 148 |
#default name by domain |
| 149 |
name=`echo $url | sed 's#\.#_#g' | sed -e 's/[^/]*\/\/\([^@]*@\)\?\([^:/]*\).*/\2/'` |
| 150 |
fi |
| 151 |
|
| 152 |
PROXY_CMD="" |
| 153 |
if [ "x${proxy}" != "x" ]; then
|
| 154 |
PROXY_CMD=" --proxy ${proxy} "
|
| 155 |
fi |
| 156 |
if [ "x${slowspeed}" = "x" ]; then
|
| 157 |
slowspeed=10 |
| 158 |
fi |
| 159 |
let timeout="${slowspeed} + 1"
|
| 160 |
|
| 161 |
START=`date +%s` |
| 162 |
HTML_RESULT=`$CURL "${url}" -s --connect-timeout ${timeout} ${PROXY_CMD}`
|
| 163 |
CURLEXITCODE=$? |
| 164 |
END=`date +%s` |
| 165 |
|
| 166 |
if [ $CURLEXITCODE -ne 0 ]; then |
| 167 |
echo "$name.value -10" |
| 168 |
echo "$name.extinfo curl return $CURLEXITCODE" |
| 169 |
continue |
| 170 |
fi |
| 171 |
|
| 172 |
GREPEXITCODE=0 |
| 173 |
if [ "x${grep}" != "x" ]; then
|
| 174 |
echo $HTML_RESULT | egrep -i "${grep}" > /dev/null
|
| 175 |
GREPEXITCODE=$? |
| 176 |
if [ $GREPEXITCODE -ne 0 ]; then |
| 177 |
echo "$name.value -9" |
| 178 |
echo "$name.extinfo can not found $grep regex strings" |
| 179 |
continue |
| 180 |
fi |
| 181 |
fi |
| 182 |
|
| 183 |
|
| 184 |
if [ "x${size}" != "x" ]; then
|
| 185 |
if [ ${#HTML_RESULT} -lt ${size} ]; then
|
| 186 |
echo "$name.value -8" |
| 187 |
echo "$name.extinfo html size ${#HTML_RESULT} is smaller than ${size}"
|
| 188 |
continue |
| 189 |
fi |
| 190 |
fi |
| 191 |
|
| 192 |
|
| 193 |
let SPEED="$END - $START" |
| 194 |
echo "$name.value $SPEED" |
| 195 |
done |
