Quote:
Originally Posted by MartenH
Hello,
I'm looking for a way of logging and recovering the total amount of data sent and received for a network interface. The code I currently use resets after a certain period of time which is not desired.
I'm looking for something that even after a reboot will tell me how much data has been received and sent on that interface since the server was first taken into use (i.e. from the time a solution was implemented).
This is my current code
Code:
echo $(/sbin/ifconfig eth1 | grep 'RX bytes' | head -n1 | awk '{print $3 $4}' | cut -d '(' -f2 | cut -d ')' -f1
Code:
echo $(/sbin/ifconfig eth1 | grep 'RX bytes' | head -n1 | awk '{print $7 $8}' | cut -d '(' -f2 | cut -d ')' -f1)
|
Check into MRTG and/or RRDTOOL. They can be a bear to set up, but keep good track of such things, and give you good looking graphs to boot.
If you want a quick-and-dirty solution, fire up MySQL, define a database and table (very easy to do), and shovel those values into a table, say every minute or so. I.E:, under MySQL prompt, "create database NetworkStats;", "use NetworkStats;", "create table traffic (DateTime char(26), IF char(10), RX int, TX int);". Then your script can just append a mysql command-line insert, and shove a record in every time it runs.
Use OpenOffice Spreadsheet or Excel to make an ODBC connection to it, for graphing, trending, etc. Can keep as much data as you've got disk space for.