# Monit 簡介及建置教程

# Monit 簡介 官網

Monit 是一個常用來管理監控 Linux 系統的小工具,經過簡單的設定就可以在系統異常時採取行動,包括警報、重啟、執行腳本等等。Monit 能夠進行自動維護,修復,並在錯誤情況下運行有意義的因果操作。M/Monit 則是與其配套的網頁監控服務。

# 部屬


# 安裝

apt-get update && apt-get install -y monit

# 指令

設定檔檢測:
monit -t
重新加載:
monit reload
開啟:
service monit start
關閉:
service monit stop
重啟:
service monit restart

# 配置

官網文件: https://mmonit.com/monit/documentation/monit.html

# 配置文件位置

/etc/monit/monitrc

# 檢測周期

set daemon  60 # check services at 60 seconds intervals
   with start delay 60

# 警報 mail smtp

set mailserver smtp.gmail.com port 587
    username "username" password "password"
    using tls

# 警報 mail 格式

set mail-format {
    from:    Monit Alert <monit@$HOST>
    subject: 通知 專題伺服器 --  $EVENT $SERVICE
    message:
    $SERVICE => $EVENT    
    日期: $DATE
    動作: $ACTION
    主機: $HOST
    說明: $DESCRIPTION
}

# 連接 M/Monit

set mmonit http://monit:monit@127.0.0.1:80/collector
    with timeout 30 seconds              # Default timeout is 5 seconds
    and register without credentials

# 系統效能監控

check system $HOST
    if loadavg (1min) per core > 2 for 5 cycles then alert
    if loadavg (5min) per core > 1.5 for 10 cycles then alert
    if cpu usage > 75% for 5 cycles then alert
    if memory usage > 80% for 1 cycles then alert

# 系統效能監控

check file bashrc with path /etc/bash.bashrc
    if changed checksum then alert

# 單一檔案 hash 監控

check file passwd with path /etc/passwd
    if changed checksum then alert

# 目錄修改時間監控

check directory ssh_folder with path /root/.ssh
    if changed timestamp then alert

# 檔案系統讀寫速度監控

check filesystem root_directory PATH /
    if write rate > 50 MB/s for 10 cycles then alert
    if read rate > 50 MB/s for 10 cycles then alert

# 網路介面卡上下行速度監控

check network enp3s0 with interface enp3s0
    if download > 20 MB/s for 10 cycles then alert
    if upload > 20 MB/s for 10 cycles then alert
更新於

請我喝咖啡~( ̄▽ ̄)~*