Monit

用 Monit 監控已建立的套接字數?

  • September 12, 2013

我無法弄清楚如何讓 Monit 監控伺服器上打開/建立的 TCP/IP 連接的數量,以便在打開“太多”時發送警報。你知道如何設置嗎?

這是另一個解決方案

定義以下配置監視器:

check program OpenSocket with path "/bin/checkn_socket.sh"
   if status > 0 then alert
               group admin

腳本:checkn_socket.sh

#!/bin/bash

Threshold=4 # Set Threshold

TotalEstSocket=$(netstat -t | awk '{/ESTABLISHED/ && n++} END{ print n }')

if (( TotalEstSocket >= Threshold ))
then
       echo >&2 "Too Many OpenSocket"
       exit $TotalEstSocket
else
       exit 0
fi

監控日誌

[IST Sep 12 22:32:14] error    : 'OpenSocket' status failed (4) for /bin/checkn_socket.sh. Error: Too Many OpenSocket
..
[IST Sep 12 22:32:17] info     : 'OpenSocket' status succeeded
[IST Sep 12 22:32:26] error    : 'OpenSocket' status failed (4) for /bin/checkn_socket.sh. Error: Too Many OpenSocket
..
[IST Sep 12 22:32:29] error    : 'OpenSocket' status failed (4) for /bin/checkn_socket.sh. Error: Too Many OpenSocket
..
[IST Sep 12 22:32:32] error    : 'OpenSocket' status failed (4) for /bin/checkn_socket.sh. Error: Too Many OpenSocket
..
[IST Sep 12 22:32:35] info     : 'OpenSocket' status succeeded

引用自:https://serverfault.com/questions/538418