Saggex
Saggex

Reputation: 3500

How to get Network Traffic as one number on Linux

currently I am using this script to get CPU Load, Memory Load and used Diskspace. Now I want to expand it to also give me Network traffic.

top -bn1 | grep "Cpu(s)" | \
           sed "s/.*, *\([0-9.]*\)%* id.*/\1/" | \
           awk '{print "CPU Load> " 100 - $1"%"}'
free | grep Mem | awk '{print "Memory Usage> "$3/$2 * 100.0"%"}'
used=$(df / | awk 'END{print $5}')
echo "Storage Used> "$used

The result should look something like this:

CPU Load> 82.8%
Memory Usage> 98.7924%
Storage Used> 23%
Network Traffic> 281 byte/s

Is there some way to go about that?

Upvotes: 1

Views: 610

Answers (1)

CareFree
CareFree

Reputation: 311

Sorry, I missed the bottom of your comment where you are looking for throughput. in this case, I'd use ifstat

apt-get install ifstat. 

And in your script.

ifstat 1 1 | tail -1 | awk '{ print $1,$2}'. 

this will give you Kb in and out. you can add them together.

Upvotes: 1

Related Questions