]> git.pld-linux.org Git - packages/cacti-template-snmp_tcp_connection_status.git/commitdiff
- script to export tcp statistics summary
authorElan Ruusamäe <glen@pld-linux.org>
Fri, 23 Oct 2009 13:44:02 +0000 (13:44 +0000)
committercvs2git <feedback@pld-linux.org>
Sun, 24 Jun 2012 12:13:13 +0000 (12:13 +0000)
Changed files:
    tcpstat -> 1.1

tcpstat [new file with mode: 0644]

diff --git a/tcpstat b/tcpstat
new file mode 100644 (file)
index 0000000..e274df6
--- /dev/null
+++ b/tcpstat
@@ -0,0 +1,42 @@
+#!/bin/sh
+# NT: print netstat statistics
+# Author: glen@delfi.ee
+# $Id$
+
+# closing:0 time_wait:0 time_close:0 listen:13 syn_sent:0 syn_recv:0 established:4 fin_wait1:0 fin_wait2:0 closewait:0 lastack:0
+# closing:1 syn_sent:0 established:1887 closewait:0 time_close:0 fin_wait1:28 lastack:4 fin_wait2:725 time_wait:25025 syn_recv:22 listen:14
+
+LC_ALL=C ss -ant | PERL_BADLANG=0 perl -ane '
+BEGIN {
+       my %m = (
+               established => "ESTAB",
+               syn_sent => "SYN-SENT",
+               syn_recv => "SYN-RECV",
+               fin_wait1 => "FIN-WAIT-1",
+               fin_wait2 => "FIN-WAIT-2",
+               time_wait => "TIME-WAIT",
+               time_close => "UNCONN",
+               closewait => "CLOSE-WAIT",
+               lastack => "LAST-ACK",
+               listen =>  "LISTEN",
+               closing => "CLOSING",
+       );
+
+       # reset values to 0
+       %a = map { $_ => 0 } values %m;
+
+       # create reverse map for pretty print
+       %r = map { $m{$_} => $_ } keys %m;
+}
+
+++$a{$F[0]} if $F[0] =~ /^[A-Z0-9-]+$/;
+
+END {
+       my $t = $p = 0;
+       while (my($k, $v) = each %a) {
+               $k = $r{$k};
+               $t += $v;
+               $p = $p > length($v) ? $p : length($v);
+               printf("%s:%d ", $k, $v);
+       }
+}'
This page took 0.090725 seconds and 4 git commands to generate.