I am trying to monitor a system load average using uptime
. On my debian box, I used the following:
$ for ((i=0;i<=1000000000;i++)); do uptime; done
However looking at top
, 18% of CPU was allocated to bash
! This means that my uptime checking is way too agressive.
How do I gently check the load average ?
Have you tried
watch
?Isn't this a good case for running a lightweight monitoring daemon like Monit? You can set a threshold and have the system email you under certain conditions...
Also, is
top
an option here?Your sample code is querying the uptime as fast as the system can issue serial uptime commands, which is not what you want.
You need to utilize a tool that will query at an interval (polling).
Your existing code could be "fixed" by adding a sleep statement. This would cause the polling granularity to be lessened, but your overhead caused by your monitoring would be reduced. This sample would check every minute.
That said, you really want to use a tool that was built for monitoring rather than writing your own.