Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to create a script that runs on a linux server, that script should read bandwidth usage of NICs installed on other servers and then store them in memcached.

So I need a command that reads bandwidth usage of other servers on the same LAN, and the command should be as quick as possible.


share|improve this question

There's no magical command that can just read parameters of other servers. Unless you setup and use SNMP. Note that you can't read a rate, you can only read a total so far of transmitted/received traffic.

mrtg may just be the route you want to take to get there though. It'll do the calculations for bandwidth rates and store them in an RRD. You can then 'instantly' query the RRDs.

share|improve this answer

I would create a shell script that uses SSH to run an ifconfig command remotely and parse the output to grab the RX bytes: and TX bytes: values (standard grep/sed/awk). I would pass these values to a PHP/Python/Perl/Ruby script (whatever your preference is) that stores them in to memcached. Alternatively you could write the entire script in that language. I would setup SSH to use public/private keys to avoid having to use passwords in your scripts.

The other option, as MikeyB, mentioned would be setup a more complete monitoring app on your servers which would record the network bandwidth usage directly.

share|improve this answer
It is taking too long to make an SSH authentication, we have many servers SSH will take lot of time. – wael34218 May 3 '11 at 9:55

Installing munin-node on your servers and configuring a munin server will get you graphical output by interface per machine. Resolution of the data is fixed at five minute intervals. As noted, data for current bandwidth resolution is not available as such. It needs to be derived by sampling counters over time. Utilization is derived from (actual delta) / (rate * period).

Munin will gather a bunch of other information which can be useful when tracing bottlenecks and other problems. It can also be configured to alarm when values stray outside configured limits.

EDIT: If you want the latest values, you could write a script that will extract the lastest sample from the rrd file(s). This would be for the latest 5 minute sample.

Unfortunately, bandwidth usage is not tracked directly. If you need relatively instantaneous readings you will need to query the counters, wait some period of time, and query the counters again. You could then calculate the bandwidth usage. You could use munin-node to query the counters. The command to fetch the counters is fetch ip_eth0. The config data contains the baseline data for full utilization. The shorter the period you wait, the higher the error you will get in your sample.

share|improve this answer
Munin is already installed on the servers, but I dont need graphs nor alerts. I need to read BW usage as a simple number at any moment. Is it possible to create a script around munin to get what I need? – wael34218 Mar 27 '11 at 6:53
@wael34218: See my edit for results. Instantaneous bandwidth is not available. If it was the values would be 0% or 100%. Think of a point location on a road. It will be either occupied or not. You need to sample over time to determine utilization. – BillThor Mar 27 '11 at 17:16

About 12 years ago I was working on a project for ISP and I wrote a script in Perl + SMNP that would read number of bytes transmitted/received from dozen of access servers every minute, store it in a database and then do all sort of statistical calculations on this data. Nowadays there is RRDtool package for this (MRTG is a predecessor). But the general idea remains - you can read number of received/transmitted bytes pretty much from any device through SNMP. If you are reading this from a NIC there may be other options available but principle I think is the same.

share|improve this answer
Sampling rate of 1 minute is perfect thats what I want. How often does MRTG and RRDtool sample? can they provide accurate results for the latest 1 minute? – wael34218 Mar 28 '11 at 7:57
Essentially you define interval yourself - you just run RRDtool on your own schedule and every time it runs it collects current stats and adds it to the database. – dtoubelis Mar 29 '11 at 16:10

I use two programs in bash scripts just a few lines long to give me bandwidth averages for 30 secs in addition to the 5 min averages from MRTG (which is great for historical bandwidth usage rather than 'live' usage).

bwm-ng and ifstat are both easy to script around. The first let's you output to HTML and CSV too.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.