Skip to content

Instantly share code, notes, and snippets.

@kescherCode
Last active December 4, 2023 11:18
Show Gist options
  • Save kescherCode/92c74b74a20debaf52a53e2d1e1478be to your computer and use it in GitHub Desktop.
Save kescherCode/92c74b74a20debaf52a53e2d1e1478be to your computer and use it in GitHub Desktop.
A rrdtool network graph generator, as seen on https://mirror.kescher.at.
#!/usr/bin/env bash
while :; do
bash loop
sleep 5
done
#!/usr/bin/env bash
rrdtool=/usr/bin/rrdtool
db0=/srv/rrdtool/eth0.rrd
img=/dev/shm/mirror-page
if [[ ! -e $db0 ]]; then
$rrdtool create $db0 \
-s 10 \
DS:in:DERIVE:10:0:1250000000 \
DS:out:DERIVE:10:0:1250000000 \
RRA:MAX:0.5:1:360 \
RRA:MAX:0.5:6:1440 \
RRA:MAX:0.5:24:2520 \
RRA:MAX:0.5:144:1800
fi
in0=$(ifconfig ens3 | grep bytes | awk '{print $5}' | sed -n '1p')
out0=$(ifconfig ens3 | grep bytes | awk '{print $5}' | sed -n '2p')
$rrdtool updatev $db0 -t in:out N:"$in0":"$out0" > /dev/null
if [[ ! -d $img ]]; then
mkdir -p $img
fi
for period in hour
do
$rrdtool graph $img/kalos-1$period.png -s -1$period \
-t "kalos: Traffic last $period" \
--lazy -l 0 -M -Y -R light \
-c BACK#181A1B -c CANVAS#25282A -c FONT#E8E6E3 -c AXIS#E8E6E3 -c FRAME#E8E6E3 -c ARROW#E8E6E3 \
DEF:in=$db0:in:MAX \
DEF:out=$db0:out:MAX \
CDEF:outei=out,8,* \
CDEF:in_ei=in,8,* \
"TEXTALIGN:left" \
"COMMENT:Max " \
"COMMENT:Avg\\r" \
"AREA:outei#008000:Outgoing\\l" \
"COMMENT:\\u" \
"GPRINT:outei:MAX:%7.1lf %Sbps" \
"GPRINT:outei:AVERAGE:%7.1lf %Sbps\\r" \
"LINE:in_ei#0000FFA0:Incoming\\l" \
"COMMENT:\\u" \
"GPRINT:in_ei:MAX:%7.1lf %Sbps" \
"GPRINT:in_ei:AVERAGE:%7.1lf %Sbps\\r" \
-h 102 -w 500 -l 0 -a PNG > /dev/null
done
[Unit]
Description=rrdtool network graph generator
[Service]
ExecStart=/usr/local/lib/rrdtool/daemon
WorkingDirectory=/usr/local/lib/rrdtool
Type=simple
[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment