Agnus Dei (jackal) wrote,
Agnus Dei
jackal

Nagios Plugin - check_tcp_states

I wrote a Nagios Plugin that's basically a wrapper for lsof that lets you pass it a username and process name so you can have it tell you the tcp states for a process running owned by that username.

It also lets you specify what metric you want to threshold alarm against.  Sometimes you might want to threshold alarm on ESTABLISHED connections.  Sometimes you might want to threshold alarm again TOTAL_SOCKET connections used by that process.

In either case it's returned in perfdata format so all metrics are passed to Nagios/Opsview for graphing.  So no matter what you threshold against, you can graph all the metrics.


[root@host-01 libexec]# ./check_tcp_states -v -u tomcat -p java -m TOTAL_SOCKETS -w 20 -c 30
lsof -n -P -a -u tomcat -c java -i |egrep -o '\(.*\)' | sort | uniq -c
*** VERBOSE MODE is enabled!
*** Running system command: lsof -n -P -a -u tomcat -c java -i |egrep -o '\(.*\)' | sort | uniq -c
*** Username = tomcat
*** Process name = java
*** System command output:
*** ---------------------------------------------------------------------
***      27 (ESTABLISHED)
***       8 (LISTEN)
*** ---------------------------------------------------------------------
*** ESTABLISHED   = 27
*** CLOSE_WAIT    = 0
*** LISTEN        = 8
*** TOTAL_SOCKETS = 35
M2_TCP_STATES CRITICAL - TOTAL_SOCKETS = 35 sockets | TOTAL_SOCKETS=35;20;30 CLOSE_WAIT=0;; ESTABLISHED=27;; LISTEN=8;;



[root@host-01 libexec]# ./check_tcp_states -v -u tomcat -p java -m ESTABLISHED  -w 20 -c 30
lsof -n -P -a -u tomcat -c java -i |egrep -o '\(.*\)' | sort | uniq -c
*** VERBOSE MODE is enabled!
*** Running system command: lsof -n -P -a -u tomcat -c java -i |egrep -o '\(.*\)' | sort | uniq -c
*** Username = tomcat
*** Process name = java
*** System command output:
*** ---------------------------------------------------------------------
***      23 (ESTABLISHED)
***       8 (LISTEN)
*** ---------------------------------------------------------------------
*** ESTABLISHED   = 23
*** CLOSE_WAIT    = 0
*** LISTEN        = 8
*** TOTAL_SOCKETS = 31
M2_TCP_STATES WARNING - ESTABLISHED = 23 sockets | TOTAL_SOCKETS=31;; CLOSE_WAIT=0;; ESTABLISHED=23;20;30 LISTEN=8;;
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

  • 0 comments