Quote: http://www.linuxyes.com/modules.php?name=News&file=article&sid=741
當你覺得Linux伺服器負載很重,你如何分析目前伺服器的CPU及記憶體使用狀況?使用
munin可以將各種伺服器負載資料圖形化,讓你一目了然。
monit則是可以當成watchdog,當發現某些服務出現問題,可以重新啟動它來保持服務不被中斷。
From howtoforge “Server Monitoring With munin And monit“
Quote: http://linuxtoy.org/archives/monit.html
Monit 是用于對系統中的進程、文件、目錄、以及設備等進行監視和管理的工具。Monit 包含一個內嵌的 HTTP(S) Web 界面,你可以使用瀏覽器方便地查看 Monit 所監視的服務器。
Fedora Core release 6 (Zod)
1.) yum install monit
2.) vi /etc/monit.conf
# 背景執行 monit ,且每兩分鐘確認一次服務
set daemon 120
# 設定寄 alert 的 mail server,可設多台以上、不同 port number,連第一個 timeout 五秒後才連第二個
set mailserver localhost, mail.ssorc.tw port 2525,
mail2.ssorc.tw with timeout 5 seconds
# 如果 alert 信寄不出去,monit 會把它存在 /var/monit,檔案以 binary 格式儲存,一個事件一個檔案,檔案名稱為”時間_服務名稱”,
# 還不知道這個100為什麼
set eventqueue
basedir /var/monit
slots 100
# 設定 alert 信件的格式
# 可以這樣設
# 範本:
# From: [email protected]
# Subject: monit alert — Does not exist apache
# To: [email protected]
# Date: Thu, 04 Sep 2003 02:33:03 +0200
# Does not exist Service apache
# Date: Thu, 04 Sep 2003 02:33:03 +0200
# Action: restart
# Host: ssorc.tw
# Your faithful employee,
# monit
#mail-format {
# from: [email protected]
# subject: $SERVICE $EVENT at $DATE
# message: Monit $ACTION $SERVICE at $DATE on $HOST: $DESCRIPTION.
# Yours sincerely,
# monit
#}
# 預設設定
set mail-format { from: [email protected] }
# alert 信件的收件者
set alert [email protected]
# 可以這樣設
#set alert [email protected] with mail-format { from: [email protected]}
mail-format 變數說明 ( quote: man monit )
* $EVENT
A string describing the event that occurred. The values are
fixed and are:Event: | Failure state: | Recovery state:
—————————————————————
CHANGED | “Changed” | “Changed back”
CHECKSUM | “Checksum failed” | “Checksum passed”
CONNECTION | “Connection failed” | “Connection passed”
DATA | “Data access error” | “Data access succeeded”
EXEC | “Execution failed” | “Execution succeeded”
GID | “GID failed” | “GID passed”
ICMP | “ICMP failed” | “ICMP passed”
INSTANCE | “Monit instance changed” | “Monit instance changed not”
INVALID | “Invalid type” | “Type passed”
MATCH | “Regex match” | “No regex match”
NONEXIST | “Does not exist” | “Exists”
PERMISSION | “Permission failed” | “Permission passed”
RESOURCE | “Resource limit matched” | “Resource limit passed”
SIZE | “Size failed” | “Size passed”
TIMEOUT | “Timeout” | “Timeout recovery”
TIMESTAMP | “Timestamp failed” | “Timestamp passed”
UID | “UID failed” | “UID passed”* $SERVICE
The service entry name in monitrc* $DATE
The current time and date (RFC 822 date style).* $HOST
The name of the host monit is running on* $ACTION
The name of the action which was done. Action names are fixed
and are:Action: | Name:
——————–
ALERT | “alert”
EXEC | “exec”
MONITOR | “monitor”
RESTART | “restart”
START | “start”
STOP | “stop”
UNMONITOR | “unmonitor”* $DESCRIPTION
The description of the error condition
3.) service monit start
編譯 Tarball
1.) 下載 http://www.tildeslash.com/monit/download/
2.) 編譯 ./configure
monit has been configured with the following options:
Architecture: LINUX
SSL support: enabled
SSL include directory: /usr/include
SSL library directory: /usr/lib
resource monitoring: enabled
resource code: sysdep_LINUX.c
large files support: enabled
Compiler flags: -g -O2 -Wall -D _REENTRANT -I/usr/include
Linker flags: -lpthread -lcrypt -lresolv -lnsl -L/usr/lib -lssl -lcrypto
pid file location: /var/run
make
make install
3.) 官網有一 Debian 的 plugins template: http://www.tildeslash.com/monit/doc/monitrc_debian_current.tar.gz
mkdir /etc/monit
tar zxvf monitrc_debian_current.tar.gz -C /etc/monit
留言