#!/bin/sh # # Record network device counters every 1 second and write in RRD or plain text. # # Copyright 2016 Ludovic Pouzenc # # This file is part of if_rrd_fast. # # if_rrd_fast is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # if_rrd_fast is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with if_rrd_fast. If not, see . # rsync -i stg.chd.sx:out.rrd /tmp/ statements=" DEF:ds0=/tmp/out.rrd:rx:AVERAGE DEF:ds1=/tmp/out.rrd:tx:AVERAGE DEF:ds2=/tmp/out.rrd:rx:MAX DEF:ds3=/tmp/out.rrd:tx:MAX CDEF:ds0b=ds0,8,* CDEF:ds1b=ds1,8,* CDEF:ds2b=ds2,8,* CDEF:ds3b=ds3,8,* CDEF:inbound=ds0b,-1,* CDEF:outbound=ds1b,1,* CDEF:in_peak=ds2b,-1,* CDEF:out_peak=ds3b,1,* VDEF:ds0max=ds0b,MAXIMUM VDEF:ds0avg=ds0b,AVERAGE VDEF:ds0pct=ds0b,95,PERCENT VDEF:ds1max=ds1b,MAXIMUM VDEF:ds1avg=ds1b,AVERAGE VDEF:ds1pct=ds1b,95,PERCENT VDEF:ds2max=ds2b,MAXIMUM VDEF:ds3max=ds3b,MAXIMUM LINE1:0#cccc00 COMMENT:              COMMENT:Maximum     COMMENT:Average     COMMENT:95th%tile\l AREA:inbound#0099ff:inbound   GPRINT:ds0max:%6.2lf %Sbps GPRINT:ds0avg:%6.2lf %Sbps GPRINT:ds0pct:%6.2lf %Sbps\l AREA:outbound#44ff44:outbound  GPRINT:ds1max:%6.2lf %Sbps GPRINT:ds1avg:%6.2lf %Sbps GPRINT:ds1pct:%6.2lf %Sbps\l LINE1:in_peak#0066bb:in_peak   GPRINT:ds2max:%6.2lf %Sbps\l LINE1:out_peak#00aa00:out_peak  GPRINT:ds3max:%6.2lf %Sbps\l " if [ $# -eq 1 ] then ts=$1 else #read -p "Last timestamp ? " ts [ -z "$ts" ] && ts=now fi for res in 1 60 300 3600 do rrdtool graph /var/www/lpo/out$res.png --imgformat PNG --width 1152 --height 720 \ --start "end-$((1152*$res))s" --end $ts --lower-limit -190000000 --upper-limit 190000000 --rigid \ --title "Network traffic" $statements done