Created
August 29, 2013 14:35
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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