Created
June 14, 2012 11:21
-
-
Save gerhard/2929719 to your computer and use it in GitHub Desktop.
TCP port traffic monitoring
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
! pmacctd configuration | |
! | |
! | |
! | |
daemonize: true | |
pidfile: /var/run/pmacctd.pid | |
syslog: daemon | |
! | |
! interested in in and outbound traffic | |
aggregate: src_host,src_port,dst_host,dst_port | |
! on this interface | |
interface: eth0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ pmacct -s | head -2 | |
SRC_IP DST_IP SRC_PORT PACKETS BYTES | |
200.74.77.221 94.23.121.1 57602 4164 180554 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# set -x | |
port="${1:-6201}" | |
pmacctd_uptime="$(ps -eo cmd,etime | awk '/pmacctd.+Core/ && ! /awk/ { print $5 }')" | |
echo -e "pmacctd running for: $pmacctd_uptime\n" | |
echo "PORT: $port" | |
echo -e "\npmacct counters" | |
pmacct -c src_port -N "$port" -n bytes | awk '{ print $1 " Bytes"; print $1 / 2^30 " Gigabytes" }' | |
echo -e "\npmacct + awk counters" | |
pmacct -s | awk '/ '"$port"' / { total+=$5+$6 } END { print total " Bytes"; print total / 2^30 " Gigabytes" }' |
Difference grows over time:
pmacctd running for: 02:31:57
PORT: 6201
pmacct counters
3386469838 Bytes
3.1539 Gigabytes
pmacct + awk counters
7833975334 Bytes
7.29596 Gigabytes
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
PORT: 6201
pmacct counters
883453840 Bytes
0.822781 Gigabytes
pmacct + awk counters
897856077 Bytes
0.836194 Gigabytes