Search Exchange

Search All Sites

Nagios Live Webinars

Let our experts show you how Nagios can help your organization.

Contact Us

Phone: 1-888-NAGIOS-1


Remember Me

Directory Tree

Check Number Of Connections

1 vote
Network Monitoring Software - Download Nagios XI
Log Management Software - Nagios Log Server - Download
Netflow Analysis Software - Nagios Network Analyzer - Download
Perl script that checks the number of established network connections using lsof
You can check the number of established network connections of a specific user or the number of network connections of a given command. Those two options can be combined.

Note: This script uses lsof with sudo.
Make sure your /etc/sudoers is properly configured.
For example put the following line into /etc/sudoers

nagios ALL=NOPASSWD: /usr/sbin/lsof

Please refer to the manpages for further options.

Examples of usage:
/usr/local/nagios/libexec/ -w 200 -c 250 -C httpd
Will check the number of network connections for any command containig httpd. If the number of established connections is equal to or exceeds 200 a warning is reported, if it's more or equal to 250 the an error.

/usr/local/nagios/libexec/ -w 200 -c 250 -u apache
Same as above except not commands containing httpd will be checked but any commands owned by user apache. You can also use uids instead of login names.

/usr/local/nagios/libexec/ -w 200 -c 250 -u apache -C httpd
This checks only commands containing httpd owned by user apache.

Released under the LGPL, visit for details.

Tested on:
- Redhat Linux 7.3 (x86)
- Fedora Core 4 (x86)
- Gentoo Linux 2006.1 (x86)
- Solaris 10 (sparc)
Reviews (1)
bysardar, January 15, 2015
It works perfectly fine but facing problem by using script with NRPE. It returns zero connection count.
./check_nrpe -H host-name -c command-name
OK - Established connections: 0

help would be appreciated, THANKS