/usr/sbin/iptotald is in iptotal 0.3.3-13.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | #!/bin/sh
######################################################################
# _ _ _ _
# (_) | | | | | |
# _ _ __ | |_ ___ | |_ __ _| |
# | | '_ \| __/ _ \| __/ _` | |
# | | |_) | || (_) | || (_| | |
# |_| .__/ \__\___/ \__\__,_|_|
# | |
# |_| V0.3 Dec. 13, 2001
# By Antoine Megens
# webmaster@dingetje.homeip.net
#
# RRD daemon script to measure total IP bandwidth usage
# without the need for an SNMP daemon
#
# part of iptotal package for FREESCO
#
######################################################################
. /etc/iptotal/iptotal.cfg
ARCHIVE_DONE=0
do_archive() {
DAYNAME=`${DATECMD} +%d%b%Y`
DOARCHIVE=0
TIMESTAMP=`${DATECMD} +%H%M`
if [ ${TIMESTAMP} -gt 2358 ]; then # Just before Midnight?
if [ ${ARCHIVE_DONE} = 0 ]; then # and not archived yet?
ARCHIVEFILE=${ARCHIVE}/${DAYNAME}.png
DOARCHIVE=1
fi
fi
if [ ${TIMESTAMP} -lt 0005 ]; then # Just after Midnight?
ARCHIVE_DONE=0 # clear flag
fi
if [ ${DOARCHIVE} = 1 ]; then
#
# create a daily graph from the current rrd data in archive
#
/usr/bin/rrdtool graph ${ARCHIVEFILE} \
--title "Total data throughput (${DAYNAME})" \
--imgformat PNG \
--width 600 \
--height 150 \
--end 'now-60s' \
--start 'end-24h' \
DEF:in=/var/lib/iptotal/iptotal.rrd:input:AVERAGE \
DEF:out=/var/lib/iptotal/iptotal.rrd:output:AVERAGE \
DEF:maxin=/var/lib/iptotal/iptotal.rrd:input:MAX \
DEF:maxout=/var/lib/iptotal/iptotal.rrd:output:MAX \
AREA:in#009828:"In kbyte(s)" \
LINE2:out#ff0000:"Out kbyte(s)" \
LINE2:maxin#0030ff:"Max In" \
LINE2:maxout#ff8040:"Max Out"
#
# now remove files older than 30 days from archive
#
${ROOT_DIR}/bin/find ${ARCHIVE}/*.png +30 -type f exec rm -rf {} \;
ARCHIVE_DONE=1
fi
}
######################################################################
#
# go to work....
#
if [ ! -f $ETH_DBASE ]; then
echo Creating new RRD database...
/usr/bin/rrdtool create $ETH_DBASE \
--step ${INTERVAL} \
DS:total:GAUGE:120:0:10000 \
DS:input:GAUGE:120:0:10000 \
DS:output:GAUGE:120:0:10000 \
RRA:AVERAGE:0.5:1:1440 \
RRA:AVERAGE:0.5:60:1200 \
RRA:MIN:0.5:60:1200 \
RRA:MAX:0.5:60:1200 \
RRA:AVERAGE:0.5:1440:365 \
RRA:MIN:0.5:1440:365 \
RRA:MAX:0.5:1440:365
# make it readable for user nobody (HTTP user)
chown www-data:www-data $ETH_DBASE
fi
#
# collect data, but only if..
#
if [ -f $ETH_DBASE ]; then
#
# the database exists, and..
#
if [ -f ${ROOT_DIR}/sbin/iptotal ]; then
#
# iptotal is installed...
#--------------------------------------------------
# save PID of this endless loop, so we can stop it
#--------------------------------------------------
echo $$ > /var/run/iptotal.pid
while true
do
#-------------------------------------------------
# run iptotal and get output in TOTAL
#-------------------------------------------------
RESULT=`${ROOT_DIR}/sbin/iptotal -r ${INTERVAL} ${ETHDEV}`
total=0;
input=0;
output=0;
set $RESULT
#
# $1 $2 $3 $4 $5 $6 $7 $8
#Total: 0 kbyte(s) In: 0 kbyte(s) Out: 0 kbyte(s)
#--------------------------------------------------
# we need 2nd, 5th and 8th element of the output
#--------------------------------------------------
if [ ! -z "$2" ]; then
total=$2
fi
if [ ! -z "$5" ]; then
input=$5
fi
if [ ! -z "$8" ]; then
output=$8
fi
#
# show result in text file for web page to include
#
if [ ! -f /var/lib/iptotal/result.txt ]; then
touch /var/lib/iptotal/result.txt
chown www-data:www-data /var/lib/iptotal/result.txt
fi
echo $RESULT > /var/lib/iptotal/result.txt
#---------------------------
# update the database
#---------------------------
/usr/bin/rrdtool update $ETH_DBASE \
--template total:input:output \
N:$total:$input:$output
#
# check if daily graph should be created in archive
#
do_archive
done
fi
fi
|