Skip to content

Instantly share code, notes, and snippets.

@natanaeljr
Created September 5, 2020 19:10
Show Gist options
  • Save natanaeljr/3689a3bdc6afd40459a1f0b493f3d9bd to your computer and use it in GitHub Desktop.
Save natanaeljr/3689a3bdc6afd40459a1f0b493f3d9bd to your computer and use it in GitHub Desktop.
BEGIN {
getline < "/tmp/cpu-usage-cache"
close("/tmp/cpu-usage-cache")
prev_idle = $1
prev_total = $2
getline < "/proc/stat"
close("/proc/stat")
idle = $5
total = 0
for (i=2; i<=NF; i++)
total += $i
printf "%d", (1-(idle-prev_idle)/(total-prev_total))*100"%"
printf "%d %d", idle, total > "/tmp/cpu-usage-cache"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment