I am looking for a way to write the CPU utilization into a text file every 10 seconds.
How might I go about setting this up? I'm running Ubuntu 12.04.
CPU utilisation is easy:
From the command line:
The sleep command will sleep 10 seconds and than return with the return value 0 (aka success). We abuse that to get a compact while( true ) sleep 10.
/proc/loadavg contains the load avarages of now, over the last 5 minutes, and over the last 15 minutes. If you are logging every 10 seconds then you are only interested in the first value.
Or in a script (using bash).
#!/bin/sh # Using /bin/sh which is guaranteed to be present on any posix system. # If you want to add shell specific parts in the script than replace this. # E.g. if you want to use bash specific stuff then change it to: # #!/usr/bin/env bash # Make sure that the shebang is on the first line of the script (no comments above it!) # While true, pause 10 seconds, then append information to Mylogfile # while ( sleep 10 ) ; do cat /proc/loadavg >> mylogfile ; done
The simplest form of that would result in:
If you run