Nagios監控Sphinx的indexer日志
編者按:作者楚霏由于需要關注sphinx的indexer是不是在要求的時間內更新,編寫個簡答插件。下面是Nagios監控Sphinx的indexer日志的具體方法。
以前寫過一個監控sphinx的searchd的插件,參見http://www.chengyongxu.com/blog/nagios監控sphinx/
因為研發要求關注一下sphinx的indexer是不是在要求的時間內更新了,于是寫一個簡單插件吧
先把更新時間最早的文件和它的改動時間打出來,和規定的時間UPDATE_TIME比較,發現是規定時間之前更新的就報警。
使用方法:
#1.登上運行有sphinx的服務器上,下載腳本放到nagios的libexec目錄下,例如: cd /usr/local/nagios/libexec/ wget http://down.chengyongxu.com/check_indexer_log # #2.改屬主,加執行權限 chown nagios:nagios check_indexer_log chmod 755 check_indexer_log # #3.在nrpe.cfg文件中增加下邊一行,參數根據你的需要修改 #----------------------------增加文字-開始---------------------------- command[check_indexer_log]=/usr/local/nagios/libexec/check_indexer_log #----------------------------增加文字-結束---------------------------- # #4.保存退出后重啟nrpe service nrpe restart # #5.要主監控服務器上增加一個服務監控 #----------------------------增加文字-開始---------------------------- define service{ host_name 10.0.0.166 service_description check_indexer_log check_command check_nrpe!check_indexer_log max_check_attempts 3 check_interval 10 retry_interval 5 check_period 24x7 notification_interval 30 notification_period 24x7 notification_options w,u,c #contacts contacts(*) contact_groups sa_groups } #----------------------------增加文字-結束---------------------------- # #6.保存退出后重啟nagios service nagios restart 插件貼出如下: #!/bin/bash LOG_DIR=/usr/local/sphinx/var/log UPDATE_TIME=40 # 上次改動時間最早的文件和其改動時間,格式為03-0317:25 FILE_A=`ls -t $LOG_DIR/*searchd.log | tail -n 1` TIME_A=`ls -tl $LOG_DIR/*searchd.log | tail -n 1 | awk '{print $6$7}'` # 要求的最近更新時間,格式為03-0317:25 TIME_B=`date +%m-%d%H:%M -d "$UPDATE_TIME min ago"` if [[ "$TIME_A" > "$TIME_B" ]] then echo "OK | All files changed in $UPDATE_TIME minutes" else echo "$FILE_A last update time is $TIME_A" exit 2 fi
原文鏈接:http://www.chengyongxu.com/blog/nagios%E7%9B%91%E6%8E%A7sphinx%E7%9A%84indexer%E6%97%A5%E5%BF%97/
【編輯推薦】