I want to collect bandwidth usage statistics on my linux server. What I want to do, is to write a function (probably will use php exec) that will return the number of bytes, and then store it in DB.

I had tried several methods, but all return complex data. Is there a method to get simple bandwidth usage in bytes for the server. I don't need to know which ip or service using it.
I need only in going and out going usage.

  • 1
    Use ifconfig command for TX and RX bytes. – Ipor Sircer Jun 21 '18 at 16:09

See if this will work for you.

This will list the received bytes for eth0

ifconfig eth0 | grep 'RX b' | sed 's/:/ /g' | awk '{print $3}'

This will list the sent bytes for eth0

ifconfig eth0 | grep 'RX b' | sed 's/:/ /g' | awk '{print $8}'

If you need for other interfaces you can change the name.

  • This is great, but it gives me the total transmitted. Is there a way to get current transmitted on total over the last X time? Or the only way is to get delta over time? – matisa Jun 21 '18 at 17:02
  • The amount of data per second must bae implemented at the level of the visualization program : grafana have a derivative function. – MUY Belgium Jun 21 '18 at 17:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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