Skip to content

Instantly share code, notes, and snippets.

@Ciaran0
Last active August 29, 2015 14:25
Show Gist options
  • Save Ciaran0/eb626d0336498f8bedc6 to your computer and use it in GitHub Desktop.
Save Ciaran0/eb626d0336498f8bedc6 to your computer and use it in GitHub Desktop.
Send core usage stats to StatsD
#!/bin/bash
#For this script to run first run top command. press 1 to see core information. Press W to set this a default
#hostname is a parametre
NUM_CPUS=$(top -bn 1 | grep -c "Cpu")
while true;
do
top -bn 2 | grep -o "Cpu.........." | tail -n $NUM_CPUS > /tmp/topLog.txt;
sed -e "s/Cpu[[:alnum:]] : //g" -e "s/Cpu[[:alnum:]][[:alnum:]] : //g" -e "s/ //g" /tmp/topLog.txt > /tmp/topLog2.txt;
COUNTER=1
while IFS='' read -r line || [[ -n $line ]]; do
echo "oat1.processor1.coreUsageInPercent$COUNTER:$line|g" | nc -w 1 -u $1 8125;
COUNTER=$[COUNTER +1]
done < /tmp/topLog2.txt;
sleep 1m;
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment