I’m looking for a way to count monthly traffic. I guess it’s not the most difficult thing to do, but I don’t get any forward at the moment (well, my skills are also limited…). I tried netacct but the logfile confused me too much, Knemo claims it’d count also the monthly traffic but mine turned out to be senile (and crashes)…
My computer is conected over a router to the internet and what interests me is just my traffic. To get the data from the router is not possible. Most solutions I found were dealing with servers or routers.
If it matters I’m using KDE 4.1 (openSUSE 11.1), but the program doesn’t have to be colourful . A nice CLI program would do. Even if it just can display the traffic per session. But the output should be in a nice format.
I wrote a very basic script to sum up all traffic (up and down together) which is enough for my needs. What’s left is to make it run on start-up.
The only thing which worries me a bit is to run something self-scripted as root… What could I do to prevent it causing harm? w-permisson just for root and maybe use AppAmor to protect it?
It evaluates (well, sums using awk) the informations since the last boot, could this slow the boot process down significantly? (The computer doesn’t run days, so the log-file is somewhat limited).
Hi
Your probably better off to use snmp to get the in and out octets of
the interface. Is this to keep track of bandwith usage? If so then you
need to look at the router and if it has snmp capabilities to get the
information.
thank you for the idea. Well, all I need is to keep some kind of track how much traffic I used (no need to be in real-time) as soon I’ll have a monthly limit (no need for 100% exact data) and I’ll connect to the internet via (um, no clue how one calls that…) well, some network in which I’m just a small user without any kind of special rights. So I guess one can’t use snmp? Besides I just understood the iptraf output ;).
Or I could try to use a cronjob every hour (and before shut-down) to evaluate the data. But it’ll take a while to figure it out… (I wrote my first bash-script just one week ago ;))
Here is my script btw, the only problem could be a slowdown if the log is very long, what do you think?
#!/bin/bash
# this script collects traffic in bytes with iptraf and
# writes the sums to a file
Log=/var/log/iptraf
TrafCol=/tmp/TrafCalc.col
TrafTot=/tmp/TrafCalc.tot
TrafSum=/var/log/TrafSum
text="Datum Traffic Total"
# read log + parse traffic in bytes + sum it up
cat $Log | cut '-d;' -f4 | cut '-d ' -f2 > $TrafCol
summe=$(awk '{sum += $1} END {print sum}' $TrafCol)
rm $Log
# create TrafSum if not already existing
if ! -e $TrafSum ]
then
echo -e $text > $TrafSum
fi
# caluclate total traffic in MByte
cat $TrafSum | cut '-d ' -f8 > $TrafTot
summe_total=$$summe+$(awk '{sum += $1} END {print sum}' $TrafTot)]
rm $TrafCol
rm $TrafTot
summe_total=$$summe_total/1024] #in MByte
# output in TrafSum
echo -e "$(date) $summe $summe_total MByte" >> $TrafSum
# start iptraf
iptraf -i br0 -L $Log -B
KarlaKa wrote:
> Hi,
>
> I’m looking for a way to count monthly traffic. I guess it’s not the
> most difficult thing to do, but I don’t get any forward at the moment
> (well, my skills are also limited…). I tried netacct but the logfile
> confused me too much, Knemo claims it’d count also the monthly traffic
> but mine turned out to be senile (and crashes)…
>
> My computer is conected over a router to the internet and what
> interests me is just my traffic. To get the data from the router is not
> possible. Most solutions I found were dealing with servers or routers.
>
> If it matters I’m using KDE 4.1 (openSUSE 11.1), but the program
> doesn’t have to be colourful . A nice CLI program would do. Even if
> it just can display the traffic per session. But the output should be in
> a nice format.
>
> Help is greatly appreciated.
Mh… I see your huge eyes, guys. Vnstat is nothing compared to this visualization. How to configfure rrdtool to easily access the graphics for NETWORK TRAFFIC in real time?
Actually I want rrdtool to continously show me upload/download traffics without eating HDD space.