Monit。我所使用的系統及服務監控軟體
- 這是免費的!免費版的設定檔得自己去編寫,沒有網頁介面可以去設定,但是這點對我影響不大。
- 有WEB介面可以查看即時的狀態,並且可以透過網頁進行「enable」與「disable」的動作。
- 內建有retry的機制,可以自己設定行為動作,避免誤判的發生。
- 可以幫您重新啟動服務,若是發現WEB服務中斷了,能達成重新啟動服務的動作。
- 監控System、Process、FileSystem、File、Fifo、Directory和Host。
- 不同觸發事件,可以指定寄信給不同的收件者。
ScreenShots:http://mmonit.com/monit/screenshots/
文件:http://mmonit.com/monit/documentation/其實我覺得能監控的項目真的不少,大家可以看官方的ScreenShots參考一下,設定檔的部分就自己努力的編寫一次囉!官方也有很充足的文件可以參考,我想達成系統的監控絕對沒有問題的!不過這監控是屬於即時的狀態,並不會有長期的數據統計,只會留下系統紀錄。
Usage: monit [options] {arguments}
Options are as follows:
-c file Use this control file
-d n Run as a daemon once per n seconds
-g name Set group name for start, stop, restart, monitor and unmonitor
-l logfile Print log information to this file
-p pidfile Use this lock file in daemon mode
-s statefile Set the file monit should write state information to
-I Do not run in background (needed for run from init)
-t Run syntax check for the control file
-v Verbose mode, work noisy (diagnostic output)
-H [filename] Print SHA1 and MD5 hashes of the file or of stdin if the
filename is omited; monit will exit afterwards
-V Print version number and patchlevel
-h Print this text
Optional action arguments for non-daemon mode are as follows:
start all - Start all services
start name - Only start the named service
stop all - Stop all services
stop name - Only stop the named service
restart all - Stop and start all services
restart name - Only restart the named service
monitor all - Enable monitoring of all services
monitor name - Only enable monitoring of the named service
unmonitor all - Disable monitoring of all services
unmonitor name - Only disable monitoring of the named service
reload - Reinitialize monit
status - Print full status information for each service
summary - Print short status information for each service
quit - Kill monit daemon process
validate - Check all services and start if not running
(Action arguments operate on services defined in the control file)
基本的command秀給大家看一下,基本上我是將主要設定檔寫在/usr/local/etc/monitrc,因為此軟體不能透過snmp監控遠端主機的CPU資訊等等,像是ping或http的監控定我就會放在/usr/local/etc/monit.d目錄下。基本設定項目:
set logfile /var/log/monit.log # 設定log寫入的檔案,不設定會寫入/var/log/message
set mailserver msa.hinet.net # 寄信的mailserverset mail-format {
From: taipei@$HOST
Subject: [ monit通知 ] - $EVENT $SERVICE message:$EVENT 監控項目 $SERVICE 時間:$DATE
動作:$ACTION
主機:$HOST
描述:$DESCRIPTION
} # 設定發信出來的Format,若是記出來為亂碼,請更改編碼set alert [email protected] # [email protected]會收到所有的異常通知
set alert [email protected] only on { timeout } # [email protected]收到timeout的異常通知set httpd port 2812 and # 預設WEB Listen 2182 port
allow 帳號:密碼 # WEB介面設定帳號與密碼check system taipei.easylife.tw # 監控主機CPU、Memory、Swap以及Uptime的數值
if loadavg (1min) > 4 then alert
if loadavg (5min) > 2 then alert
if memory usage > 75% then alert
if swap usage > 25% then alert
if cpu usage (user) > 70% then alert
if cpu usage (system) > 30% then alert
if cpu usage (wait) > 20% then alertcheck file shadow with path /etc/shadow # 監控密碼檔案,有人改密碼則會通知,或是被更改了屬性及權限
if failed checksum and
expect the sum f456845a152cdc7339f2282641a9df2c then unmonitor
if failed permission 400 then unmonitor
if failed uid root then unmonitor
if failed gid root then unmonitorcheck process mysqld with pidfile /var/run/httpd.pid # 監控apache,並且可以設定alert與重新啟動服務
start program = "/etc/init.d/httpd start" with timeout 60 seconds
stop program = "/etc/init.d/httpd stop"
if cpu > 60% for 2 cycles then alert
if cpu > 80% for 5 cycles then restart
if totalmem > 200.0 MB for 5 cycles then restart
if children > 250 then restart
if loadavg(5min) greater than 10 for 8 cycles then stopcheck filesystem root-filesystem with path /dev/sda2 # 監控硬碟空間的使用
if space usage > 40% for 5 times within 15 cycles then alert
if space usage > 99% then stop
if inode usage > 300000 then alert
if inode usage > 50% then stopcheck host taipei-HTTP with address 220.132.12.209 # WEB的監控,會監控80 port的狀態,10秒沒回應就算Fail
if failed port 80 protocol http with timeout 10 seconds then alertcheck host taipei-PING with address 220.132.12.209 # 最基本的ping監控,可以設定ping幾次及timeout值
if failed icmp type echo count 3 with timeout 3 seconds then alert
我這裡是最簡易的設定,若是多多參考官方的文件,會發現真的可以監控到非常多的東西,而且可以設定一些執行的動作,若是不當成監控軟體,也可以設定系統執行一些動作,反正我覺得還算強大!可惜就是設定要自己動手打,還好設定檔的語法算是簡單,若是看得懂英文應該都很容易懂吧!我在這裡推薦大家可以使用看看,若你也有監控需求的話!官方其實還有【M/Monit】付費的版本,功能就整個非常的不錯,甚至可以監控到多台主機的狀態,也可以藉由WEB去設定,看了真的很想使用看看,而且還有iPhone的版本!但是還好免費版本沒有限制監控的數量,雖然設定較麻煩,但是功能也算超值了!Moint:http://mmonit.com/monit/
ScreenShots:http://mmonit.com/monit/screenshots/
文件:http://mmonit.com/monit/documentation/