Total Bandwidth Via SSH

quackweb

Verified User
Joined
Nov 16, 2003
Messages
165
Location
Denver, Colorado
Hello,

Does anyone know of a way to calculate the entire bandwidth usage on a server for the current month (and end of month) via SSH without using DA's api? If there is not a current way to do this, how would one go about doing this?
 
Correct me if I am wrong but doesn't MRTG only check eth0 every x minutes? Wouldn't this make an inaccurate reading in bandwidth total? Is it possible to access the same totals the admin in DA would see through SSH?
 
MRTG is most likely what your upstream provider is using to charge you; therefore it's probably the most accurate your'e going to get :) .

And then there's the issue that DA definitely doesn't log all traffic.

Jeff
 
Alright, thanks for the info Jeff, we use mostly HP Procurve switches and a few Cisco switches. All of them are compatible with SNMP so it might be easier to setup mrtg to monitor the switches instead of every server (we have a ton of servers and it would take forever to setup on each individual one). Thanks again!
 
Although we decided to go the other route using MRTG on our switches, we did come across how to do it via SSH incase anyone in the future would like to do something similar. It is also the most accurate way to calculate bandwidth.

Tell IPtables what to do:

iptables -I INPUT ! -i lo; iptables -I OUTPUT ! -o lo

To reset the data, create a cron job that runs once a month with the following command:

iptables -R INPUT 1 ! -i lo; iptables -R OUTPUT 1 ! -o lo

Next create another cron job that runs regularly (recommended: every 30 minutes) to protect current data and chain incase a server needs to be rebooted

iptables-save -c > /etc/iptables

You can set the output file to any name you want (/etc/iptables)

In your rc.local, add:

iptables-restore -c < /etc/iptable

This will restore settings and data upon system boot.

To check the bandwidth you have used during the month:

iptables -L -v

You can set this up to output the data before it is reset once a month. You will want to look at the rule counters, NOT the chain counters.

Tada! Now you can check your bandwidth usage for the entire server.

Will post this later to How-To Guides section
 
This looks good. Don't forget to re-enter the commands after setting either APF or KISS, or after starting/restarting iptables, as all of these completely rewrite the ruleset.

Can you assure us that the numbers continue to be saved even if iptables is restarted, or KISS or APF change it?

Jeff
 
I''m still working on the How-To, there are a few problems with what I posted as I discovered this morning, the settings and data disappeared. Hopefully I'll have it done before end of next week along with an auto-install program.
 
Back
Top