Skip to content

Instantly share code, notes, and snippets.

@PavelVanecek
Created August 29, 2013 14:35
Show Gist options
  • Save PavelVanecek/6378915 to your computer and use it in GitHub Desktop.
Save PavelVanecek/6378915 to your computer and use it in GitHub Desktop.
A simple script to get average CPU load of a group of processes
#!/bin/bash
TMP_FILE=/tmp/cpuload
PNAME="node"
tries=0
while [ $tries -lt 100 ]
do
ps ax -o comm -o %cpu | grep $PNAME | awk '{s+=$2}END{print s}' | tee -a $TMP_FILE
sleep 1
let tries++
done
awk '{total+=$1;count++}END{print total/count "% average CPU load"}' $TMP_FILE
rm $TMP_FILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment