#!/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:dsrxavg=/tmp/out.rrd:rx:AVERAGE DEF:dstxavg=/tmp/out.rrd:tx:AVERAGE DEF:dsrxmax=/tmp/out.rrd:rx:MAX DEF:dstxmax=/tmp/out.rrd:tx:MAX DEF:dsrxmin=/tmp/out.rrd:rx:MIN DEF:dstxmin=/tmp/out.rrd:tx:MIN CDEF:dsrxavgb=dsrxavg,8,* CDEF:dstxavgb=dstxavg,8,* CDEF:dsrxmaxb=dsrxmax,8,* CDEF:dstxmaxb=dstxmax,8,* CDEF:dsrxminb=dsrxmin,8,* CDEF:dstxminb=dstxmin,8,* CDEF:inbound=dsrxavgb,-1,* CDEF:outbound=dstxavgb,1,* CDEF:in_max=dsrxmaxb,-1,* CDEF:out_max=dstxmaxb,1,* CDEF:in_min=dsrxminb,-1,* CDEF:out_min=dstxminb,1,* VDEF:totrxavgmax=dsrxavgb,MAXIMUM VDEF:totrxavgavg=dsrxavgb,AVERAGE VDEF:totrxavgpct=dsrxavgb,95,PERCENT VDEF:tottxavgmax=dstxavgb,MAXIMUM VDEF:tottxavgavg=dstxavgb,AVERAGE VDEF:tottxavgpct=dstxavgb,95,PERCENT VDEF:totrxmaxmax=dsrxmaxb,MAXIMUM VDEF:tottxmaxmax=dstxmaxb,MAXIMUM LINE1:0#cccc00 COMMENT:              COMMENT:Maximum     COMMENT:Average     COMMENT:95th%tile\l AREA:in_max#0099ff:in_max   GPRINT:totrxmaxmax:%6.2lf %Sbps\l AREA:out_max#44ff44:out_max  GPRINT:tottxmaxmax:%6.2lf %Sbps\l AREA:in_min#ffffff: AREA:out_min#ffffff: LINE1:inbound#0066bb:inbound   GPRINT:totrxavgmax:%6.2lf %Sbps GPRINT:totrxavgavg:%6.2lf %Sbps GPRINT:totrxavgpct:%6.2lf %Sbps\l LINE1:outbound#00aa00:outbound  GPRINT:tottxavgmax:%6.2lf %Sbps GPRINT:tottxavgavg:%6.2lf %Sbps GPRINT:tottxavgpct:%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