#!/bin/bash

cd /var/www/htdocs/domains/rc6.org/subdomains/intranet.rc6.org/rrd/traffic

TZ='Europe/Oslo'; export TZ

rrdtool graph eth0_day.png --start -86400 -e -300 \
  DEF:eth0_in_bytes=interfaces.rrd:eth0_in:AVERAGE \
  DEF:eth0_out_bytes=interfaces.rrd:eth0_out:AVERAGE \
  "CDEF:eth0_in_bits=eth0_in_bytes,8,*" \
  "CDEF:eth0_out_bits=eth0_out_bytes,8,*" \
  "CDEF:eth0_out_bits_neg=eth0_out_bits,-1,*" \
  "CDEF:eth0_bytes_in=eth0_in_bytes,0,12500000,LIMIT,UN,0,eth0_in_bytes,IF,86400,*" \
  "CDEF:eth0_bytes_out=eth0_out_bytes,0,12500000,LIMIT,UN,0,eth0_out_bytes,IF,86400,*" \
  "CDEF:eth0_bytes=eth0_bytes_in,eth0_bytes_out,+" \
  AREA:eth0_in_bits#00dd00:eth0_in \
  AREA:eth0_out_bits_neg#0000ff:eth0_out \
  COMMENT:"                          +--------------------------\n" \
  COMMENT:"             maximum       average       current" \
  COMMENT:"| `date +\"%b %d %H:%M:%S %Y\"`\n" \
  COMMENT:"in    " \
  GPRINT:eth0_in_bits:MAX:'%7.2lf %sb/s' \
  GPRINT:eth0_in_bits:AVERAGE:"%7.2lf %Sb/s" \
  GPRINT:eth0_in_bits:LAST:"%7.2lf %Sb/s" \
  COMMENT:"| `uptime | sed 's/.*\(up[^,]*,[^,]*\).*/\1 hours/g'`\n" \
  COMMENT:"out   " \
  GPRINT:eth0_out_bits:MAX:"%7.2lf %Sb/s" \
  GPRINT:eth0_out_bits:AVERAGE:"%7.2lf %Sb/s" \
  GPRINT:eth0_out_bits:LAST:"%7.2lf %Sb/s" \
  COMMENT:"|\n" \
  GPRINT:eth0_bytes_in:AVERAGE:"totals  %7.2lf %sB i" \
  GPRINT:eth0_bytes_out:AVERAGE:"%7.2lf %sB o" \
  GPRINT:eth0_bytes:AVERAGE:"%7.2lf %sB t" \
  COMMENT:"|" \
  -v "bits/sec" -t "rewt - traffic - day (5 min avg)" -h 100 -w 392 -x "HOUR:1:HOUR:6:HOUR:2:0:%H" \

rrdtool graph eth0_week.png --start -604800 -e -1800 \
  DEF:eth0_in_bytes=interfaces.rrd:eth0_in:AVERAGE \
  DEF:eth0_out_bytes=interfaces.rrd:eth0_out:AVERAGE \
  "CDEF:eth0_in_bits=eth0_in_bytes,8,*" \
  "CDEF:eth0_out_bits=eth0_out_bytes,8,*" \
  "CDEF:eth0_out_bits_neg=eth0_out_bits,-1,*" \
  "CDEF:eth0_bytes_in=eth0_in_bytes,0,12500000,LIMIT,UN,0,eth0_in_bytes,IF,604800,*" \
  "CDEF:eth0_bytes_out=eth0_out_bytes,0,12500000,LIMIT,UN,0,eth0_out_bytes,IF,604800,*" \
  "CDEF:eth0_bytes=eth0_bytes_in,eth0_bytes_out,+" \
  AREA:eth0_in_bits#00dd00:eth0_in \
  AREA:eth0_out_bits_neg#0000ff:eth0_out \
  COMMENT:"                          +--------------------------\n" \
  COMMENT:"             maximum       average       current" \
  COMMENT:"| `date +\"%b %d %H:%M:%S %Y\"`\n" \
  COMMENT:"in    " \
  GPRINT:eth0_in_bits:MAX:'%7.2lf %sb/s' \
  GPRINT:eth0_in_bits:AVERAGE:"%7.2lf %Sb/s" \
  GPRINT:eth0_in_bits:LAST:"%7.2lf %Sb/s" \
  COMMENT:"| `uptime | sed 's/.*\(up[^,]*,[^,]*\).*/\1 hours/g'`\n" \
  COMMENT:"out   " \
  GPRINT:eth0_out_bits:MAX:"%7.2lf %Sb/s" \
  GPRINT:eth0_out_bits:AVERAGE:"%7.2lf %Sb/s" \
  GPRINT:eth0_out_bits:LAST:"%7.2lf %Sb/s" \
  COMMENT:"|\n" \
  GPRINT:eth0_bytes_in:AVERAGE:"totals  %7.2lf %sB i" \
  GPRINT:eth0_bytes_out:AVERAGE:"%7.2lf %sB o" \
  GPRINT:eth0_bytes:AVERAGE:"%7.2lf %sB t" \
  COMMENT:"|" \
  -v "bits/sec" -t "rewt - traffic - week (30 min avg)" -h 100 -w 392 -x "HOUR:6:DAY:1:DAY:1:0:%a" \

rrdtool graph eth0_month.png --start -2592000 -e -7200 \
  DEF:eth0_in_bytes=interfaces.rrd:eth0_in:AVERAGE \
  DEF:eth0_out_bytes=interfaces.rrd:eth0_out:AVERAGE \
  "CDEF:eth0_in_bits=eth0_in_bytes,8,*" \
  "CDEF:eth0_out_bits=eth0_out_bytes,8,*" \
  "CDEF:eth0_out_bits_neg=eth0_out_bits,-1,*" \
  "CDEF:eth0_bytes_in=eth0_in_bytes,0,12500000,LIMIT,UN,0,eth0_in_bytes,IF,2592000,*" \
  "CDEF:eth0_bytes_out=eth0_out_bytes,0,12500000,LIMIT,UN,0,eth0_out_bytes,IF,2592000,*" \
  "CDEF:eth0_bytes=eth0_bytes_in,eth0_bytes_out,+" \
  AREA:eth0_in_bits#00dd00:eth0_in \
  AREA:eth0_out_bits_neg#0000ff:eth0_out \
  COMMENT:"                          +--------------------------\n" \
  COMMENT:"             maximum       average       current" \
  COMMENT:"| `date +\"%b %d %H:%M:%S %Y\"`\n" \
  COMMENT:"in    " \
  GPRINT:eth0_in_bits:MAX:'%7.2lf %sb/s' \
  GPRINT:eth0_in_bits:AVERAGE:"%7.2lf %Sb/s" \
  GPRINT:eth0_in_bits:LAST:"%7.2lf %Sb/s" \
  COMMENT:"| `uptime | sed 's/.*\(up[^,]*,[^,]*\).*/\1 hours/g'`\n" \
  COMMENT:"out   " \
  GPRINT:eth0_out_bits:MAX:"%7.2lf %Sb/s" \
  GPRINT:eth0_out_bits:AVERAGE:"%7.2lf %Sb/s" \
  GPRINT:eth0_out_bits:LAST:"%7.2lf %Sb/s" \
  COMMENT:"|\n" \
  GPRINT:eth0_bytes_in:AVERAGE:"totals  %7.2lf %sB i" \
  GPRINT:eth0_bytes_out:AVERAGE:"%7.2lf %sB o" \
  GPRINT:eth0_bytes:AVERAGE:"%7.2lf %sB t" \
  COMMENT:"|" \
  -v "bits/sec" -t "rewt - traffic - month (2 hour avg)" -h 100 -w 392 -x "DAY:1:WEEK:1:WEEK:1:0:Week %W" \

rrdtool graph eth0_year.png --start -31536000 -e -86400 \
  DEF:eth0_in_bytes=interfaces.rrd:eth0_in:AVERAGE \
  DEF:eth0_out_bytes=interfaces.rrd:eth0_out:AVERAGE \
  "CDEF:eth0_in_bits=eth0_in_bytes,8,*" \
  "CDEF:eth0_out_bits=eth0_out_bytes,8,*" \
  "CDEF:eth0_out_bits_neg=eth0_out_bits,-1,*" \
  "CDEF:eth0_bytes_in=eth0_in_bytes,0,12500000,LIMIT,UN,0,eth0_in_bytes,IF,31536000,*" \
  "CDEF:eth0_bytes_out=eth0_out_bytes,0,12500000,LIMIT,UN,0,eth0_out_bytes,IF,31536000,*" \
  "CDEF:eth0_bytes=eth0_bytes_in,eth0_bytes_out,+" \
  AREA:eth0_in_bits#00dd00:eth0_in \
  AREA:eth0_out_bits_neg#0000ff:eth0_out \
  COMMENT:"                          +--------------------------\n" \
  COMMENT:"             maximum       average       current" \
  COMMENT:"| `date +\"%b %d %H:%M:%S %Y\"`\n" \
  COMMENT:"in    " \
  GPRINT:eth0_in_bits:MAX:'%7.2lf %sb/s' \
  GPRINT:eth0_in_bits:AVERAGE:"%7.2lf %Sb/s" \
  GPRINT:eth0_in_bits:LAST:"%7.2lf %Sb/s" \
  COMMENT:"| `uptime | sed 's/.*\(up[^,]*,[^,]*\).*/\1 hours/g'`\n" \
  COMMENT:"out   " \
  GPRINT:eth0_out_bits:MAX:"%7.2lf %Sb/s" \
  GPRINT:eth0_out_bits:AVERAGE:"%7.2lf %Sb/s" \
  GPRINT:eth0_out_bits:LAST:"%7.2lf %Sb/s" \
  COMMENT:"|\n" \
  GPRINT:eth0_bytes_in:AVERAGE:"totals  %7.2lf %sB i" \
  GPRINT:eth0_bytes_out:AVERAGE:"%7.2lf %sB o" \
  GPRINT:eth0_bytes:AVERAGE:"%7.2lf %sB t" \
  COMMENT:"|" \
  -v "bits/sec" -t "rewt - traffic - year (1 day avg)" -h 100 -w 392 -x "MONTH:1:MONTH:1:MONTH:1:0:%b"
