Skip to content

Instantly share code, notes, and snippets.

@KristianLyng
Created March 10, 2014 16:04
Show Gist options
  • Select an option

  • Save KristianLyng/9467917 to your computer and use it in GitHub Desktop.

Select an option

Save KristianLyng/9467917 to your computer and use it in GitHub Desktop.
#!/bin/bash
{ while sleep 1; do cat /proc/stat; done } | awk '
$1 == "cpu" {
sum=$2+$3+$4+$5;
idle=$5;
diff_sum=sum-old_sum;
diff_idle=idle-old_idle;
old_idle=idle;
old_sum=sum
relative_idle =100* diff_idle/diff_sum;
relative_load = 100*1.0 - relative_idle;
printf "CPU Idle %.2f%% CPU load: %.2f%%\n", relative_idle, relative_load;
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment