muninã§ãã«ã¹ãã§ãã¯(æ»æ´»ç£è¦/çåç£è¦/ãµã¤ãç£è¦ã¨ã)
muninæ´¾ã¨nagiosæ´¾ã¨ZABBIXæ´¾ãæ¦ãã¨ãã«ããã¦ãç¦ç¹ã«ãªãã®ãæ»æ´»ç£è¦ãªã©ã®ç£è¦ã ã¨æãã
ãmuninã£ã¦ã°ã©ããæ¸ãããã§ããªããã!ã ã¨ããããããããããã alert ã®ã¡ã¼ã«éä¿¡ã§ãã¾ããã¿ãããªã
ãããããmuninã£ã¦URLã®ãã§ãã¯ã¨ããããã»ã¹ã®çåãã§ãã¯ã¨ããlogã®ãã§ãã¯ã¨ãã§ããã®ï¼ãã£ã¦ãããã㨠muninæ´¾ã¯ãã¬ã¬ã¬ã»ã»ã»ã¨ãããªãããããªãã£ãã
æã httpç£è¦ãã奴ãä½ã£ããã¯ãããã©ãã¡ãã£ã¨æ¬æ ¼çã«ä½ã£ã¦ã¿ããã¨ã«ããã
ãã¦ã³ãã¼ãããå ´å
ããã»ã¹ç£è¦
http://rtilabs.net/files/2011_06_05/healthcheck_process
URLç£è¦(ãµã¤ãç£è¦/ã³ã³ãã³ãç£è¦)
http://rtilabs.net/files/2011_06_05/healthcheck_url
ãã°ç£è¦
http://rtilabs.net/files/2011_06_05/healthcheck_log
ã¤ã³ã¹ãã¼ã«æ¹æ³ãªã©
#ãã©ã°ã¤ã³ãã£ã¬ã¯ããªã¾ã§ç§»å cd /usr/share/munin/plugins #éå»ã®ã´ããæ¶ã /bin/rm healthcheck_* #ãã¦ã³ãã¼ã wget 'http://rtilabs.net/files/2011_06_05/healthcheck_process' wget 'http://rtilabs.net/files/2011_06_05/healthcheck_url' wget 'http://rtilabs.net/files/2011_06_05/healthcheck_log' wget 'http://rtilabs.net/files/2011_06_05/healthcheck_ping' #å®è¡æ¨©éä»ä¸ chmod +x healthcheck_* #muninã¸ç»é² ln -s /usr/share/munin/plugins/healthcheck_process /etc/munin/plugins/ ln -s /usr/share/munin/plugins/healthcheck_log /etc/munin/plugins/ ln -s /usr/share/munin/plugins/healthcheck_url /etc/munin/plugins/ ln -s /usr/share/munin/plugins/healthcheck_ping /etc/munin/plugins/ #è¨å®ãæ¸ã. vim /etc/munin/plugin-conf.d/munin-node ä¾ ------------------------------------------------------ [healthcheck_process] env.process_1 httpd env.process_2 mysqld [healthcheck_url] env.url_1 http://www.google.com/ env.slowspeed_1 5 #limit time(sec) #env.htmlgrep_1 google #check egrep string env.url_2 http://www.yahoo.com/ env.slowspeed_2 5 #limit time(sec) #env.htmlgrep_2 yahoo #check egrep string #env.htmlsize_2 10000 #check html size(byte). #env.proxy_2 127.0.0.1:8080 #over proxy [healthcheck_log] user root env.log_1 /var/log/messages [healthcheck_ping] env.ping_1 192.168.1.1 ------------------------------------------------------ #muninãã¼ãåèµ·å /etc/init.d/munin-node restart
ããã»ã¹ç£è¦
healthcheck_process ãã¡ã¤ã«ã
ãµã¤ã¼ã«åããã¨ãè¨å®ããããã»ã¹å㧠ps -C httpd ã¨ããã£ã¦ããã®ããã»ã¹ãå©ç¨ãã¦ããã¡ã¢ãªå®¹éã®åç®ãMBåä½ã§è¡¨ç¤ºããã
ãã ããããã»ã¹ãè½ã¡ã¦ããå ´åã¯ã-10 ã¨ããå¤ã«ãªããã¢ã©ã¼ãããããä»çµã¿ã«ãªã£ã¦ããã
è¤æ°ã®ããã»ã¹ãã¾ã¨ãã¦æ»æ´»ãã§ãã¯ã§ããã
ããã§munin ã£ã¦ããã»ã¹ç£è¦ã§ããªããã!! ã¨ããã®ã¯éå»ã®ãã®ã«ãªãã¯ãã ã
#!/bin/bash # #healthcheck on munin #check process and alert. # #programed by rti (hiroyuki fujie) [email protected] @super_rti #LICENSE: NYSL (public domain) # #config file # /etc/munin/plugin-conf.d/munin-node # #example minimum config #--------------------------------------------------- #[healthcheck_process] #env.process_1 httpd #--------------------------------------------------- # #chcek two process #--------------------------------------------------- #[healthcheck_process] #env.process_1 httpd #env.process_2 samba #--------------------------------------------------- # #chcek three process #--------------------------------------------------- #[healthcheck_process] #env.process_1 httpd #env.process_2 samba #env.process_3 mysqld #--------------------------------------------------- # # # #edakari speed up. CHECKMAX=`env | grep process_ | wc -l` let CHECKMAX="$CHECKMAX + 1" if [ "$1" = "autoconf" ]; then if [ $CHECKMAX -le 1 ]; then echo no exit 1 fi echo yes exit 0 fi if [ "$1" = "config" ]; then echo 'graph_title process memory Usage(MB)' echo "graph_args --base 1000 -l 0 --vertical-label MB" echo 'graph_scale no' echo 'graph_vlabel process memory' echo 'graph_category healthcheck' echo 'graph_info This graph shows the Memory used by process' for(( I = 1; I < $CHECKMAX; ++I )) do eval process=\$process_${I} eval alertmemory=\$alertmemory_${I} if [ "x${process}" = "x" ]; then continue fi echo "$process.label $process" echo "$process.info Memory used by $process" echo "$process.draw LINE2" echo "$process.min -10" echo "$process.critical 0:" done exit 0 fi for(( I = 1; I < $CHECKMAX; ++I )) do eval process=\$process_${I} if [ "x${process}" = "x" ]; then continue fi vrets=(`ps u --no-headers -C $process | awk 'BEGIN { count = 0 ; sum = 0; } { count ++ ; sum += $6/1024 ; } END { printf("%d %d\n",count,sum); }'`) count=${vrets[0]} value=${vrets[1]} if [ $count -le 0 ]; then echo "$process.value -10" echo "$process.extinfo process down" else echo "$process.value $value" fi done
URLç£è¦
healthcheck_url ãã¡ã¤ã«ã
æå®ããURL ã« curl ã§ã¢ã¯ã»ã¹ãã¦å¦çæé(ç§)ãè¨é²ããã
ãã¾ãã«é
ãã¨é
ããã¨ãããã¨ã§ã¢ã©ã¼ãããããã
ã§ããããã¢ã¯ã»ã¹åºæ¥ãªãå ´å㯠-10 ã¨ããå¤ã«ãªãã¢ã©ã¼ããä¸ããã
ã¤ãã§ã«ã³ã³ãã³ãã®ä¸èº«ãegrepãã¦ãç¹å®ã®æååãå
¥ã£ã¦ããªãã¨ãã¢ã©ã¼ããä¸ãããã¨ãã§ããã(ãã°ã£ã¦ããã®ã§ç´ãããããããªãã)
ããã«ãå¿çã®htmlã®ãµã¤ãºããã§ãã¯ãããªãã·ã§ã³ãä»ãã¾ãããã¨ã©ã¼ç»é¢ã®htmlã帰ã£ã¦ãã¦ãã¾ã£ã¦æ°ãã¤ããªãã¿ãããªãã¨ããªãããã«ãã¾ãããå¿çã®htmlãç¹å®ã®ãµã¤ãºä»¥ä¸ã ã¨ã¢ã©ã¼ããä¸ãã¾ãã
ã¾ããproxyã対å¿ãã¦ããã®ã§ãã¤ã³ã¿ã¼ãããçµç±(å¤åã)ã§ã®ãµã¤ãç£è¦ãã§ããã¨ã
ãã¡ãããè¤æ°ãµã¤ããä¸ã¤ã®ã°ã©ãã§ã¾ã¨ãã¦ç®¡çãããã¨ãå¯è½ã
æ´åæ§ãã§ãã¯ã®phpã¨ãã¨çµã¿åãããã°ãçµæ§é¢ç½ããã¨ãã§ããããªæ°ãããã
ãã㧠munin ã£ã¦ãµã¤ãç£è¦ã§ããªããã! ã£ã¦ããã®ã¯éå»ã®ãã®ã«ãªãã¯ãã ã
#!/bin/bash # #healthcheck on munin #check site speed. #egrep contents string # ... and alert. # #programed by rti (hiroyuki fujie) [email protected] @super_rti #LICENSE: NYSL (public domain) # #config file # /etc/munin/plugin-conf.d/munin-node # #example minimum config #--------------------------------------------------- #[healthcheck_url] #env.url_1 http://127.0.0.1/ #--------------------------------------------------- # #chcek two site #--------------------------------------------------- #[healthcheck_url] #env.url_1 http://127.0.0.1/ #env.url_2 http://www.google.com/ #--------------------------------------------------- # #chcek three site #--------------------------------------------------- #[healthcheck_url] #env.url_1 http://127.0.0.1/ #env.url_2 http://www.google.com/ #env.url_3 http://www.yahoo.com/ #--------------------------------------------------- # #set name #--------------------------------------------------- #[healthcheck_url] #env.url_1 http://127.0.0.1/ #env.name_1 homhom #--------------------------------------------------- # #check over proxy #--------------------------------------------------- #[healthcheck_url] #env.url_1 http://127.0.0.1/ #env.proxy_1 127.0.0.1:8080 #--------------------------------------------------- # #set slow speed(second) #--------------------------------------------------- #[healthcheck_url] #env.url_1 http://127.0.0.1/ #env.slowspeed_1 30 #--------------------------------------------------- # #grep string #--------------------------------------------------- #[healthcheck_url] #env.url_1 http://127.0.0.1/ #env.htmlgrep_1 saysaya #--------------------------------------------------- # #check html contents byte size. #--------------------------------------------------- #[healthcheck_url] #env.url_1 http://127.0.0.1/ #env.htmlsize_1 50000 #check 50000 bytes over. #--------------------------------------------------- # #full option #/etc/munin/plugin-conf.d/munin-node #--------------------------------------------------- #[healthcheck_url] #env.url_1 http://127.0.0.1/ #check url #env.htmlgrep_1 apache #check egrep string #env.name_1 127.0.0.1 #set line name. default by url domain #env.proxy_1 127.0.0.1:8080 #over proxy #env.slowspeed_1 30 #slow time on alert #env.htmlsize_1 50000 #check 50000 bytes over. #--------------------------------------------------- # # #edakari speed up. CHECKMAX=`env | grep url_ | wc -l` let CHECKMAX="$CHECKMAX + 1" CURL=/usr/bin/curl if [ "$1" = "autoconf" ]; then if [ $CHECKMAX -le 1 ]; then echo no exit 1 fi echo yes exit 0 fi if [ "$1" = "config" ]; then echo 'graph_title site speed (second)' echo "graph_args --base 1000 -l 0 --vertical-label second" echo 'graph_scale no' echo 'graph_vlabel second' echo 'graph_category healthcheck' echo 'graph_info This graph shows the site speed' for(( I = 1; I < $CHECKMAX; ++I )) do eval url=\$url_${I} eval name=\$name_${I} eval slowspeed=\$slowspeed_${I} if [ "x${url}" = "x" ]; then continue fi if [ "x${name}" = "x" ]; then #default name by domain name=`echo $url | sed 's#\.#_#g' | sed -e 's/[^/]*\/\/\([^@]*@\)\?\([^:/]*\).*/\2/'` fi if [ "x${slowspeed}" = "x" ]; then slowspeed=10 fi let slowspeed15="slowspeed * 3 / 2" #slowspeed * 1.5 echo "$name.label $name" echo "$name.info $url" echo "$name.draw LINE2" echo "$name.min -10" echo "$name.max ${slowspeed15}" echo "$name.critical 0:${slowspeed}" done exit 0 fi for(( I = 1; I < $CHECKMAX; ++I )) do eval url=\$url_${I} eval grep=\$htmlgrep_${I} eval size=\$htmlsize_${I} eval name=\$name_${I} eval proxy=\$proxy_${I} eval slowspeed=\$slowspeed_${I} if [ "x${url}" = "x" ]; then continue fi if [ "x${name}" = "x" ]; then #default name by domain name=`echo $url | sed 's#\.#_#g' | sed -e 's/[^/]*\/\/\([^@]*@\)\?\([^:/]*\).*/\2/'` fi PROXY_CMD="" if [ "x${proxy}" != "x" ]; then PROXY_CMD=" --proxy ${proxy} " fi if [ "x${slowspeed}" = "x" ]; then slowspeed=10 fi let timeout="${slowspeed} + 1" START=`date +%s` HTML_RESULT=`$CURL "${url}" -s --connect-timeout ${timeout} ${PROXY_CMD}` CURLEXITCODE=$? END=`date +%s` if [ $CURLEXITCODE -ne 0 ]; then echo "$name.value -10" echo "$name.extinfo curl return $CURLEXITCODE" continue fi GREPEXITCODE=0 if [ "x${grep}" != "x" ]; then echo $HTML_RESULT | egrep -i "${grep}" > /dev/null GREPEXITCODE=$? if [ $GREPEXITCODE -ne 0 ]; then echo "$name.value -9" echo "$name.extinfo can not found $grep regex strings" continue fi fi if [ "x${size}" != "x" ]; then if [ ${#HTML_RESULT} -lt ${size} ]; then echo "$name.value -8" echo "$name.extinfo html size ${#HTML_RESULT} is smaller than ${size}" continue fi fi let SPEED="$END - $START" echo "$name.value $SPEED" done
ãã°ç£è¦
healthcheck_log ãã¡ã¤ã«ã
ãã°ã egrep ãã¦ç¹å®ã®æååãå«ã¾ãã¦ããªãããã§ãã¯ãããã¨ãã§ããã
ããã§æ·±å»ãªã¨ã©ã¼ããã°ã«ã¯åºã¦ãããã©ããã§ãã¯å¿ããã¦æ°ãä»ãã¾ããã§ããã¨ãããã¨ããªããªãã¨ã
#!/bin/bash # #healthcheck on munin #egrep system log and alert. # #programed by rti (hiroyuki fujie) [email protected] @super_rti #LICENSE: NYSL (public domain) # # #config file # /etc/munin/plugin-conf.d/munin-node # #example minimum config #--------------------------------------------------- #[healthcheck_log] #user root #env.log_1 /var/log/messages #--------------------------------------------------- # #check two log #--------------------------------------------------- #[healthcheck_log] #user root #env.log_1 /var/log/messages #env.log_2 /var/log/syslog #--------------------------------------------------- # #check two three #--------------------------------------------------- #[healthcheck_log] #user root #env.log_1 /var/log/messages #env.log_2 /var/log/syslog #env.log_3 /var/log/dmesg #--------------------------------------------------- # #set name #--------------------------------------------------- #[healthcheck_log] #user root #env.log_1 /var/log/messages #env.name_1 my_server_messages #--------------------------------------------------- # #set egrep string #--------------------------------------------------- #[healthcheck_log] #user root #env.log_1 /var/log/messages #env.grep_1 alert|warning #--------------------------------------------------- # #set egrep string #--------------------------------------------------- #[healthcheck_log] #user root #env.log_1 /var/log/messages #env.grep_1 alert|warning #--------------------------------------------------- # #full option #/etc/munin/plugin-conf.d/munin-node #--------------------------------------------------- #[healthcheck_log] #user root #log file is read only root user. #env.log_1 /var/log/messages #target log filename #env.grep_1 critical|error #egrep string. #defualt by critical|error|warning|crash|fatal|kernel #--------------------------------------------------- # #edakari speed up. CHECKMAX=`env | grep log_ | wc -l` let CHECKMAX="$CHECKMAX + 1" MINUTE_BY_GREP_RANGE=10 if [ "$1" = "autoconf" ]; then if [ $CHECKMAX -le 1 ]; then echo no exit 1 fi echo yes exit 0 fi if [ "$1" = "config" ]; then echo 'graph_title log grep (match count)' echo "graph_args --base 1000 -l 0 --vertical-label match_count" echo 'graph_scale no' echo 'graph_vlabel match_count' echo 'graph_category healthcheck' echo 'graph_info This graph shows the bad event count on log' for(( I = 1; I < $CHECKMAX; ++I )) do eval log=\$log_${I} eval name=\$name_${I} eval grep=\$grep_${I} if [ "x${log}" = "x" ]; then continue fi if [ "x${name}" = "x" ]; then name=`echo $log | sed 's#[/|\.]#_#g'` fi if [ "x${name}" = "x" ]; then grep="critical|error|warning|crash|fatal|kernel" fi echo "$name.label $name" echo "$name.info egrep $grep $log | wc -l" echo "$name.draw LINE2" echo "$name.min 0" echo "$name.max 20" echo "$name.critical 0:0" done exit 0 fi NOWTIME=`date --date "$MINUTE_BY_GREP_RANGE minute ago" +%s` for(( I = 1; I < $CHECKMAX; ++I )) do eval log=\$log_${I} eval name=\$name_${I} eval grep=\$grep_${I} if [ "x${log}" = "x" ]; then continue fi if [ "x${name}" = "x" ]; then name=`echo $log | sed 's#[/|\.]#_#g'` fi if [ "x${grep}" = "x" ]; then grep="critical|error|warning|crash|fatal|kernel" fi COUNT=0 MESSAGE= IFS=$'\n' MATCHLINES=(`egrep -i "$grep" "$log"`) for(( N = ${#MATCHLINES[@]} - 1; N >= 0 ; --N )) do LINE=${MATCHLINES[$N]} DATESTRING=`echo $LINE | awk '{ printf("%s %s %s",$1,$2,$3)}'` LOGTIME=`date --date "$DATESTRING" +%s` if [ $LOGTIME -lt $NOWTIME ]; then break fi let COUNT="$COUNT + 1" MESSAGE="$MESSAGE$LINE //@LINE@// " done if [ $COUNT -eq 0 ]; then echo "${name}.value 0" else echo "${name}.value ${COUNT}" echo "${name}.extinfo ${MESSAGE}" fi done
pingç£è¦(追å )
ã¤ãã§ã« ping ç£è¦ãä½ã£ã¦ã¿ãã
healthcheck_ping ãã¡ã¤ã«ã
ping ããªãã¦å¿çé度ãè¦ã¾ãã
#!/bin/bash # #healthcheck on munin #check ping speed. #egrep contents string # ... and alert. # #programed by rti (hiroyuki fujie) [email protected] @super_rti #LICENSE: NYSL (public domain) # #config file # /etc/munin/plugin-conf.d/munin-node # #example minimum config #--------------------------------------------------- #[healthcheck_ping] #env.ping_1 127.0.0.1 #--------------------------------------------------- # #chcek two site #--------------------------------------------------- #[healthcheck_ping] #env.ping_1 127.0.0.1 #env.ping_2 www.google.com #--------------------------------------------------- # #chcek three site #--------------------------------------------------- #[healthcheck_ping] #env.ping_1 127.0.0.1 #env.ping_2 www.google.com #env.ping_3 192.168.1.1 #--------------------------------------------------- # #set name #--------------------------------------------------- #[healthcheck_ping] #env.ping_1 127.0.0.1 #env.name_1 homhom #--------------------------------------------------- ## #set slow speed(second) #--------------------------------------------------- #[healthcheck_ping] #env.ping_1 127.0.0.1 #env.slowspeed_1 3 #--------------------------------------------------- # #full option #/etc/munin/plugin-conf.d/munin-node #--------------------------------------------------- #[healthcheck_ping] #env.ping_1 127.0.0.1 #check ping #env.name_1 sayasaya #set line name. default by ping domain #env.slowspeed_1 3 #slow time on alert #--------------------------------------------------- # # #edakari speed up. CHECKMAX=`env | grep ping_ | wc -l` let CHECKMAX="$CHECKMAX + 1" if [ "$1" = "autoconf" ]; then if [ $CHECKMAX -le 1 ]; then echo no exit 1 fi echo yes exit 0 fi if [ "$1" = "config" ]; then echo 'graph_title ping speed (mili second)' echo "graph_args --base 1000 -l 0 --vertical-label milisecond" echo 'graph_scale no' echo 'graph_vlabel milisecond' echo 'graph_category healthcheck' echo 'graph_info This graph shows the site speed' for(( I = 1; I < $CHECKMAX; ++I )) do eval ping=\$ping_${I} eval name=\$name_${I} eval slowspeed=\$slowspeed_${I} if [ "x${ping}" = "x" ]; then continue fi if [ "x${name}" = "x" ]; then #default name by domain name=`echo $ping | sed 's#\.#_#g'` fi if [ "x${slowspeed}" = "x" ]; then slowspeed=3 fi let slowspeedMS="slowspeed * 1000" #convert milisecond. let slowspeedMS15="slowspeed * 3 / 2 * 1000" #slowspeedMS * 1.5 echo "$name.label $name" echo "$name.info $ping" echo "$name.draw LINE2" echo "$name.min -10" echo "$name.max ${slowspeedMS15}" echo "$name.critical 0:${slowspeedMS}" done exit 0 fi for(( I = 1; I < $CHECKMAX; ++I )) do eval ping=\$ping_${I} eval name=\$name_${I} eval slowspeed=\$slowspeed_${I} if [ "x${ping}" = "x" ]; then continue fi if [ "x${name}" = "x" ]; then #default name by domain name=`echo $ping | sed 's#\.#_#g'` fi if [ "x${slowspeed}" = "x" ]; then slowspeed=3 fi let timeout="${slowspeed} + 1" PING_RESULT=`ping -c 1 -n -w ${timeout} "${ping}" | grep "icmp_seq=1"` PINGRESULT=$? if [ $PINGRESULT -ne 0 ]; then if [ "x$PING_RESULT" = "x" ]; then PING_RESULT="ping can not respons. timeout $slowspeed second" fi echo "$name.value -10" echo "$name.extinfo $PING_RESULT" continue fi TIMEMS=`echo $PING_RESULT | sed 's/.*time=\([^ ]*\).*/\1/g'` if [ "x$TIMEMS" = "x" ]; then echo "$name.value -8" echo "$name.extinfo bad time: $PING_RESULT" continue fi echo "$name.value $TIMEMS" done