diff options
Diffstat (limited to 'sbin')
-rwxr-xr-x[-rw-r--r--] | sbin/iptables-rrdtool | 53 |
1 files changed, 36 insertions, 17 deletions
diff --git a/sbin/iptables-rrdtool b/sbin/iptables-rrdtool index 2cbbf00..ae1b8a9 100644..100755 --- a/sbin/iptables-rrdtool +++ b/sbin/iptables-rrdtool @@ -7,7 +7,7 @@ if ! grep -q /usr/bin/lckdo /proc/$PPID/cmdline; then fi [ -s /etc/default/iptables-rrdtool ] && . /etc/default/iptables-rrdtool -RRDDIR="${RRDDIR:-/var/lib/iptables-rrdtools}" +RRDDIR="${RRDDIR:-/var/lib/iptables-rrdtool}" PNGDIR="${PNGDIR:-$RRDDIR}" set -e @@ -16,6 +16,29 @@ set -e # "Internal Field Separator" for composing arguments from command substitution, among other things IFS=$'\n' +update () { + + name="${1}" + counter="${2}" + + if ! [ -s "${RRDDIR}/${name}.rrd" ]; then + rrdtool create "${RRDDIR}/${name}.rrd" \ + DS:rule:DERIVE:600:0:U \ + RRA:AVERAGE:0.5:1:576 \ + RRA:AVERAGE:0.5:6:720 \ + RRA:AVERAGE:0.5:24:720 \ + RRA:AVERAGE:0.5:288:730 + fi + + rrdtool update "${RRDDIR}/${name}.rrd" "N:${counter}" + + if [ "${GENPNG}" = "1" ]; then + for interval in d w m y; do + rrdtool graph "${PNGDIR}/${name}:${interval}.png" --full-size-mode -w 640 -h 480 --units=si --logarithmic --start -1${interval} DEF:rule="${RRDDIR}/${name}.rrd":rule:AVERAGE LINE1:rule#0080ff:rule VDEF:total=rule,TOTAL GPRINT:total:Total\\\:%8.3lf\ %s + done + fi +} + for table in $(cat /proc/net/ip_tables_names); do for rule in $(/sbin/iptables-save -c -t ${table}); do # iptables-save has inconsistent output for no sane reason; we grab rematch @@ -31,23 +54,19 @@ for table in $(cat /proc/net/ip_tables_names); do name="iptables -t ${table}${name}" counter="${BASH_REMATCH[2]}" - if ! [ -s "${RRDDIR}/${name}.rrd" ]; then - rrdtool create "${RRDDIR}/${name}.rrd" \ - DS:rule:DERIVE:600:0:U \ - RRA:AVERAGE:0.5:1:576 \ - RRA:AVERAGE:0.5:6:720 \ - RRA:AVERAGE:0.5:24:720 \ - RRA:AVERAGE:0.5:288:730 - fi - - rrdtool update "${RRDDIR}/${name}.rrd" "N:${counter}" - - if [ "${GENPNG}" = "1" ]; then - for interval in d w m y; do - rrdtool graph "${PNGDIR}/${name}:${interval}.png" --full-size-mode -w 640 -h 480 --units=si --logarithmic --start -1${interval} DEF:rule="${RRDDIR}/${name}.rrd":rule:AVERAGE LINE1:rule#0080ff:rule VDEF:total=rule,TOTAL GPRINT:total:Total\\\:%8.3lf\ %s - done - fi + update "${name}" "${counter}" fi done done +for interface in $(ls /sys/class/net/); do + for gress in tx rx; do + read counter < /sys/class/net/"${interface}"/statistics/"${gress}"_bytes + # what the hell are allowed characters for interface names, anyway? + interface="${interface//\//slash}" # replace instances of POSIX-unsafe '/' + interface="${interface//:/colon}" # remove colon because rrdtool can't deal with POSIX fileinterfaces + name="${interface} ${gress}" + update "${name}" "${counter}" + done +done + |