I’m currently designing a graph system for a website that shows current CPU usage, you can see my work in progress here – http://nereus.rikkuness.net/admin/cpu2.php
It’s working exactly as I want it to at the moment, but the problem is the way that I am polling for CPU usage is currently
sar 1 | sed -n '5p' | awk '{ print $8; }'
Which works fine but it takes around a second or so to reply with CPU usage which is making the graph not update as I would expect it to in the browser.
Any help on a command that will give me the same information but much faster would be massively appreciated.
Many thanks,
Steve
You can simply use
sar 0. This will return an immediate result instead of waiting for a 1 second interval like you do withsar 1.\Note that this will only return a single point in time value, so you might need to use javascript to track the previous values (i.e. add new value to array and pop old value off).