[perl] TCP Connection Status

Templates, scripts for templates, scripts and requests for templates.

Moderators: Developers, Moderators

User avatar
gandalf
Developer
Posts: 22383
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

[perl] TCP Connection Status

Post by gandalf »

This work is based on the nice tcp connections script from jbrooks. It is based on the snmpnetstat command producing output like

Code: Select all

 snmpnetstat -v 1  -c xxx -an -P tcp <target>
Active Internet (tcp) Connections (including servers)
Proto Local Address                Foreign Address              (state)
tcp    *.443                        *.*                          LISTEN
...
tcp    127.0.0.1.80                 *.*                          LISTEN
tcp    127.0.0.1.1024               *.*                          LISTEN
tcp    127.0.0.1.1024               127.0.0.1.4327               ESTABLISHED
tcp    127.0.0.1.1024               127.0.0.1.4329               ESTABLISHED
tcp    127.0.0.1.1024               127.0.0.1.4331               ESTABLISHED
tcp    127.0.0.1.1024               127.0.0.1.4332               ESTABLISHED
tcp    127.0.0.1.4312               127.0.0.1.8989               ESTABLISHED
tcp    127.0.0.1.4324               127.0.0.1.8989               ESTABLISHED
tcp    127.0.0.1.4325               127.0.0.1.8989               ESTABLISHED
tcp    127.0.0.1.4327               127.0.0.1.1024               ESTABLISHED
tcp    127.0.0.1.4329               127.0.0.1.1024               ESTABLISHED
tcp    127.0.0.1.4331               127.0.0.1.1024               ESTABLISHED
tcp    127.0.0.1.4332               127.0.0.1.1024               ESTABLISHED
tcp    127.0.0.1.4532               *.*                          LISTEN
tcp    127.0.0.1.8989               *.*                          LISTEN
tcp    127.0.0.1.8989               127.0.0.1.4312               ESTABLISHED
tcp    127.0.0.1.8989               127.0.0.1.4324               ESTABLISHED
tcp    127.0.0.1.8989               127.0.0.1.4325               ESTABLISHED
tcp    127.0.0.1.18196              *.*                          LISTEN
tcp    127.0.0.1.18281              *.*                          LISTEN
tcp    127.0.0.1.65535              *.*                          LISTEN
I've rewritten this shell script with perl to make it usable for windows guys as well. It will not use any temporary file.
Please put the script into <path_cacti>/scripts and import the XML as usual. Exporting was done using cacti 0.8.6g; you'll need that version at minimum when importing.
Attention! Please check your RRA definitions after importing! I'm currently using non-standard RRAs!
Attention! On busy servers, this perl script will run for "some" time. I decided to upper the Settings->Poller->Script and Script Server Timeout Value to 50 seconds

happy cactiing
Reinhard
Attachments
lvm_netstat_tcp.pl.txt
the perl script
Please remove extension &quot;.txt&quot;
Corrected Issue with SNMP V2c
(1.64 KiB) Downloaded 8560 times
cacti_graph_template_snmp_get_tcp_connection_status.xml
the XML templates
(36.66 KiB) Downloaded 8593 times
Last edited by gandalf on Tue Apr 03, 2007 7:35 am, edited 3 times in total.
User avatar
gandalf
Developer
Posts: 22383
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

Post by gandalf »

Attention
On some busy server, I noticed that the execution of snmpnetstat will take considerable time. This may required changes of some Settings -> Poller items (Script and Script Server Timeouts). As I'm not aware of the internals of snmpnetstat on the remote host, this may require your attention.
Reinhard
User avatar
dust2k
Cacti User
Posts: 101
Joined: Sun Dec 04, 2005 3:14 am

Post by dust2k »

There is the problem in template, after import the template, I found the running command is

D:\Perl\bin\perl G:/ROOT/WEB/home.ausmis.com/cacti/scripts/lvm_netstat_tcp.pl 192.168.1.10 2 public 161 500

and I got error like this :

Invalid version: 2
Usage: snmpnetstat [options...] hostname [interval]
NET-SNMP version: 5.2
-v [1 | 2c ] SNMP version
-V display version number
-c community specify community name
-t timeout SNMP packet timeout (seconds)
-i show interfaces with packet counters
-o show interfaces with octet counters
-r show routing table
-s show general statistics
-n show IP addresses, not names
-a show sockets in LISTEN mode too
-P proto show only details for this protocol
-I interface show only this interface
-d dump packets
-Ddebugspec
established:0 listen:0 timewait:0 timeclose:0 finwait1:0 finwait2:0 synsent:0 synrecv:0 closewait:0

once I change the data input method by fix value or add 'c', then it's works...
anuraganuj
Cacti User
Posts: 70
Joined: Tue Feb 21, 2006 9:50 am

polling is slow

Post by anuraganuj »

i have used this script in windows 2000k cacti server and i m using cmd.php as poller.i could add this for few servers where no of connections was low but when i create graph for big servers poller almost hangs. what should i do??
User avatar
gandalf
Developer
Posts: 22383
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

Post by gandalf »

dust2k wrote:There is the problem in template, after import the template, I found the running command is

D:\Perl\bin\perl G:/ROOT/WEB/home.ausmis.com/cacti/scripts/lvm_netstat_tcp.pl 192.168.1.10 2 public 161 500

and I got error like this :

Invalid version: 2
This will require some investigation, as snmp_version is a cacti built-in variable, that should yield 2c when choosing SNMP Version 2 from dropdown.
Reinhard
User avatar
gandalf
Developer
Posts: 22383
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

Re: polling is slow

Post by gandalf »

anuraganuj wrote:i have used this script in windows 2000k cacti server and i m using cmd.php as poller.i could add this for few servers where no of connections was low but when i create graph for big servers poller almost hangs. what should i do??
Please run the snmpnetstat from command line. I suppose, this will take a lot of time as I stated above. I'm not aware of any fact that would make it faster. Supression of DNS name lookup (option: -n) is already given.
Reinhard
User avatar
dust2k
Cacti User
Posts: 101
Joined: Sun Dec 04, 2005 3:14 am

Post by dust2k »

lvm wrote:This will require some investigation, as snmp_version is a cacti built-in variable, that should yield 2c when choosing SNMP Version 2 from dropdown.
Reinhard
I guess so, but don't know the value is 2 not 2c, but anyway, so far my script is running alright. thanks for your great work.
anuraganuj
Cacti User
Posts: 70
Joined: Tue Feb 21, 2006 9:50 am

problem with poller

Post by anuraganuj »

i am able to create graph for my squid server which is not busy. i m using cmd.php as poller in win2k but when i use this graph some time poller gives error which is attached . also graphs starts cutting in between.
poller doesnt run properly.pls help i want this graph badly :(
Attachments
error.jpg
error.jpg (41.12 KiB) Viewed 106577 times
anuraganuj
Cacti User
Posts: 70
Joined: Tue Feb 21, 2006 9:50 am

problem with cactid also

Post by anuraganuj »

i switched to CACTID but in log it says
04/21/2006 05:59:15 PM - CACTID: Poller[0] Host[122]

ERROR: Empty result [221.171.85.228]: 'c:/perl/perl C:/cacti/scripts/lvm_netstat_tcp.pl
host 1 test 161 4000'

pls help
User avatar
gandalf
Developer
Posts: 22383
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

Post by gandalf »

I'm quite sure this is related to the runtime problem I stated above. Please allow for a longer runtime of the poller as given above
Reinhard
stlaw
Posts: 4
Joined: Fri Jul 28, 2006 7:00 am

Post by stlaw »

I used this perl scripts, but I cant get the ESTABLISTHED connections.
snmpnetstat -v 1 -c public -t 500 -an -P tcp 127.0.0.1:161
Active Internet (tcp) Connections (including servers)
Proto Local Address Foreign Address (state)
tcp *.111 *.* LISTEN
tcp *.199 *.* LISTEN
tcp *.3306 *.* LISTEN
tcp *.32768 *.* LISTEN
tcp 127.0.0.1.25 *.* LISTEN
tcp 127.0.0.1.631 *.* LISTEN

at Net-SNMP site, http://www.net-snmp.org/docs/man/snmpnetstat.html
it said
"-a normally sockets used by server processes are not shown."
I wonder how can get these sockets info.

thanks
stlaw
Posts: 4
Joined: Fri Jul 28, 2006 7:00 am

Post by stlaw »

the above question hs been resolved . I guess it only occurs in localhost when using snmpwalk.
now another question :oops: , how can get connection information from IPV6?
some program such as ssh and apache will make its listening port showed with IPV6 format.
tcp 0 0 :::80 :::* LISTEN 2527/httpd
tcp 0 0 :::22 :::* LISTEN 1983/sshd

such infos cant be gotten from normal snmpnetstat.
I searched how to get these infos through snmpnetstat, but I failed.
if someone can get it, please show yr methods, thanks ~ :)
mcutting
Cacti Guru User
Posts: 1884
Joined: Mon Oct 16, 2006 5:57 am
Location: United Kingdom
Contact:

Post by mcutting »

I had exactly the same problem as dust2k. The snmp_value is actually "2" in the log, and not "2c" as it should be. Changing this value in the script seems to rectify this issue, although now I'm not able to poll data from SNMP 1 hosts.

Does anyone have any idea as to why this is ?

Thanks
Cacti Version 0.8.8b
Cacti OS Ubuntu LTS
RRDTool Version RRDTool 1.4.7
Poller Information
Type SPINE 0.8.8b
sllywhtboy
Posts: 42
Joined: Sun Jul 09, 2006 1:51 am
Location: detroit'ish
Contact:

Post by sllywhtboy »

i added/inserted the following lines below the initial "set statements" (line 16)

Code: Select all

if ($in_version == 2)
{
        $in_version = "2c";
}
I also updated the "Data Input Method" input string.

Code: Select all

/usr/bin/perl <path_cacti>/scripts/lvm_netstat_tcp.pl <host> <snmp_version> <snmp_community> <snmp_port> <snmp_timeout>

once i did that, my "SNMP V2" hosts worked! thanks for the template! :)
mcutting
Cacti Guru User
Posts: 1884
Joined: Mon Oct 16, 2006 5:57 am
Location: United Kingdom
Contact:

Post by mcutting »

i added/inserted the following lines below the initial "set statements" (line 16)

Code:
if ($in_version == 2)
{
$in_version = "2c";
}



I also updated the "Data Input Method" input string.

Code:
/usr/bin/perl <path_cacti>/scripts/lvm_netstat_tcp.pl <host> <snmp_version> <snmp_community> <snmp_port> <snmp_timeout>
Could you be a bit more specific about while files you changed to get this to work ?

Thanks
Cacti Version 0.8.8b
Cacti OS Ubuntu LTS
RRDTool Version RRDTool 1.4.7
Poller Information
Type SPINE 0.8.8b
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests