Views: 11
能夠即時監控系統或網路服務並顯示監控狀態的自動化監控軟體是不可或缺的工具。在此分享我們的做法
Apache2|Nginx + PHP + Linux Shell Scripts
(1).專案名稱
(2).監測運作 PORT埠,背景色就是最後的狀態。
(3).可依年月查詢
(4).會自動重載頁面
(5).一些資訊
(6).其它連結
Linux Shell Scripts 程式碼內容
#!/bin/bash
# 用日期為檔名一部份
fday=`date +%Y-%m`
runtime=`date +%H-%M`
serverip="bonkids.net"
for svip in $serverip
do
chkip1=`telnet "$svip" 80 <<!
^]
quit
!
`
if [ "`echo -e $chkip1 | awk '{print $4}'`" == "to" ]; then
echo -e $chkip1 | awk '{print $4 " =OK"}'
echo "`date '+%Y-%m-%d %H:%M:%S'` $svip OK" >> /XXX_CKLOG/"$fday".log
else
# 再測一次 sleep 1或3秒
echo -e $chkip1 | awk '{print $4 " =NG1"}'
sleep 1
chkip2=`telnet "$svip" 80 <<!
^]
quit
!
`
if [ "`echo -e $chkip2 | awk '{print $4}'`" == "to" ]; then
echo -e $chkip2 | awk '{print $4 " =OK"}'
echo "`date '+%Y-%m-%d %H:%M:%S'` $svip OK" >> /XXX_CKLOG/"$fday".log
else
echo -e $chkip2 | awk '{print $4 " =NG2"}'
# echo "`date '+%Y-%m-%d %H:%M:%S'` httpd on $svip - - - Failed!!" | mail -s $runtime" XXX Server Check: httpd failed." chungg.lin@gmail.com
echo "`date '+%Y-%m-%d %H:%M:%S'` $svip NG" >> /XXX_CKLOG/"$fday".log
fi
fi
done
XXXX年-XX月.log 記錄檔案內容
2011-08-25 00:04:28 XXX.net OK
2012-08-25 00:14:26 XXX.net OK
2013-08-25 00:24:29 XXX.net OK
2014-08-25 00:34:27 XXX.net OK
2015-08-25 00:44:28 XXX.net OK
2016-08-25 00:54:31 XXX.net NG
2017-08-25 01:04:29 XXX.net NG
2018-08-25 01:14:25 XXX.net OK
2019-08-25 01:24:25 XXX.net OK
2020-08-25 01:34:27 XXX.net OK
2021-08-25 01:44:23 XXX.net OK
2022-08-25 01:54:23 XXX.net OK