25/05/2005
Simple Port Accounting – part 2
A small addition to the previous post about port accounting with iptables and mrtg.
A new script to count tcp and udp connections.
conns.sh
#!/bin/bash
HOSTNAME="/bin/hostname"
NETSTAT="/bin/netstat"
UPTIME="/usr/bin/uptime"
$NETSTAT -ant | grep -v LISTEN | grep -v Active | grep -v Proto | wc -l
$NETSTAT -anu | grep -v LISTEN | grep -v Active | grep -v Proto | wc -l
$UPTIME | awk '{ print $3, $4, $5 }'
$HOSTNAME
and the part that goes inside your mrtg.conf
Target[conns]: `/etc/mrtg/conns.sh`
Options[conns]: growright, nopercent, gauge
MaxBytes[conns]: 20000
Title[conns]: Connections
YLegend[conns]: Connections
LegendI[conns]: TCP:
LegendO[conns]: UDP:
ShortLegend[conns]: conns
PageTop[conns]: <h1>Connection Stats </h1 >
enjoy 🙂 It works for me..I hope it works for you too 🙂
Filed by kargig at 18:51 under General,Linux
No Comments | 2,360 views