|
|
| Author |
Message |
gandalf Developer
Joined: 02 Dec 2004 Posts: 12604 Location: Muenster, Germany
|
Posted: Sat Apr 01, 2006 9:18 am Post subject: [perl] TCP Connection Status |
|
|
This work is based on the nice tcp connections script from jbrooks. It is based on the snmpnetstat command producing output like | Code: | 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
| Description: |
the perl script Please remove extension ".txt" Corrected Issue with SNMP V2c |
|
 Download |
| Filename: |
lvm_netstat_tcp.pl.txt |
| Filesize: |
1.64 KB |
| Downloaded: |
2201 Time(s) |
| Description: |
|
 Download |
| Filename: |
cacti_graph_template_snmp_get_tcp_connection_status.xml |
| Filesize: |
36.66 KB |
| Downloaded: |
2873 Time(s) |
Last edited by gandalf on Tue Apr 03, 2007 7:35 am; edited 3 times in total |
|
| Back to top |
|
 |
gandalf Developer
Joined: 02 Dec 2004 Posts: 12604 Location: Muenster, Germany
|
Posted: Tue Apr 18, 2006 9:22 am Post subject: |
|
|
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
|
|
| Back to top |
|
 |
dust2k Cacti User
Joined: 04 Dec 2005 Posts: 85
|
Posted: Tue Apr 18, 2006 10:40 pm Post subject: |
|
|
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...
|
|
| Back to top |
|
 |
anuraganuj Cacti User
Joined: 21 Feb 2006 Posts: 70
|
Posted: Wed Apr 19, 2006 12:21 am Post subject: polling is slow |
|
|
| 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??
|
|
| Back to top |
|
 |
gandalf Developer
Joined: 02 Dec 2004 Posts: 12604 Location: Muenster, Germany
|
Posted: Wed Apr 19, 2006 4:17 am Post subject: |
|
|
| 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
|
|
| Back to top |
|
 |
gandalf Developer
Joined: 02 Dec 2004 Posts: 12604 Location: Muenster, Germany
|
Posted: Wed Apr 19, 2006 4:18 am Post subject: Re: polling is slow |
|
|
| 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
|
|
| Back to top |
|
 |
dust2k Cacti User
Joined: 04 Dec 2005 Posts: 85
|
Posted: Fri Apr 21, 2006 1:48 am Post subject: |
|
|
| 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.
|
|
| Back to top |
|
 |
anuraganuj Cacti User
Joined: 21 Feb 2006 Posts: 70
|
|
| Back to top |
|
 |
anuraganuj Cacti User
Joined: 21 Feb 2006 Posts: 70
|
Posted: Fri Apr 21, 2006 7:31 am Post subject: problem with cactid also |
|
|
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
|
|
| Back to top |
|
 |
gandalf Developer
Joined: 02 Dec 2004 Posts: 12604 Location: Muenster, Germany
|
Posted: Sun Apr 23, 2006 2:07 pm Post subject: |
|
|
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
|
|
| Back to top |
|
 |
stlaw
Joined: 28 Jul 2006 Posts: 4
|
Posted: Mon Jul 31, 2006 5:33 am Post subject: |
|
|
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
|
|
| Back to top |
|
 |
stlaw
Joined: 28 Jul 2006 Posts: 4
|
Posted: Thu Aug 24, 2006 9:50 pm Post subject: |
|
|
the above question hs been resolved . I guess it only occurs in localhost when using snmpwalk.
now another question , 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 ~
|
|
| Back to top |
|
 |
mcutting Cacti Guru User
Joined: 16 Oct 2006 Posts: 1007
|
Posted: Fri Dec 15, 2006 9:47 am Post subject: |
|
|
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
|
|
| Back to top |
|
 |
sllywhtboy
Joined: 09 Jul 2006 Posts: 29 Location: detroit'ish
|
Posted: Fri Mar 30, 2007 11:20 am Post subject: |
|
|
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> |
once i did that, my "SNMP V2" hosts worked! thanks for the template!
|
|
| Back to top |
|
 |
mcutting Cacti Guru User
Joined: 16 Oct 2006 Posts: 1007
|
Posted: Tue Apr 03, 2007 5:55 am Post subject: |
|
|
| Quote: | 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
|
|
| Back to top |
|
 |
|