¿Monitorear el número de sockets establecidos con Monit?

¿Monitorear el número de sockets establecidos con Monit?

No puedo entender cómo hacer que Monit supervise la cantidad de conexiones TCP/IP abiertas/establecidas en un servidor para que se pueda enviar una alerta cuando haya "demasiadas" abiertas. ¿Sabes cómo se puede configurar esto?

Respuesta1

aquí hay otra solución

Defina el siguiente monitor de configuración:

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

Guión: 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

Registros de monitorización

[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

Respuesta2

No parece ser compatible directamente, pero se me ocurrió un truco.

Determine la cantidad de conexiones ESTABLECIDAS cada minuto y escriba un archivo con la misma cantidad de cero bytes.

Luego, configure Monit para verificar el tamaño de este archivo de ceros. Si se pone alerta "demasiado grande".

En crontab para algún usuario:

* * * * * /bin/sh -c '/bin/dd if=/dev/zero of=/tmp/tcp_connections.monit count=$(/bin/netstat -t | /bin/grep ESTABLISHED | /usr/bin/wc -l) bs=1 >/dev/null 2>&1'

En la configuración de Monit:

check file tcp_connections with path /tmp/tcp_connections.monit
    if size > 16KB then alert

información relacionada