#!/usr/bin/gawk -f # # netsample -- 2007-12-05, last edit 2008-05-13 # # script to snatch interface receive and transmit byte counts to a data # file, needs to be run from user's crontab in order to write to # sample data file, the data file data sample frequency set by crontab # entry to: 4,9,14,19,24,29,34,39,44,49,54,59 minutes past the hour # # Copyright (C) 2007 Grant Coady GPLv2 # # Credits comp.lang.awk: Kenny McCormack and Ed Morton # # pull rx and tx bytes from /proc/net/dev: # rx tx # ppp0:22921966 17725 0 0 0 0 0 0 444056 10437 0 0 0 0 0 0 # # output line: date rx_bytes tx_bytes, or date 0 0 when interface down # # also calls 'netdraw' to update the monitor image # BEGIN { ARGV[ARGC++] = "/etc/netdraw.conf" # grab configuration file ARGV[ARGC++] = "/proc/net/dev" # where to read the sample data } NR == FNR { if ($1 == "datapath") datapath = $2 if ($1 == "datafile") samplefile = datapath "/" $2 if ($1 == "interface") interface = $2 if ($1 == "codepath") codepath = $2 next } $0 ~ interface { sub(/:/," "); rx = $2; tx = $10 } END { printf "%s %d %d\n", strftime("%F.%H:%M"), rx + 0, tx + 0 >> samplefile close(samplefile) system(codepath "/netdraw") system(codepath "/netdrawdaysum") }