Skip to content

Instantly share code, notes, and snippets.

@niklasvincent
Created March 22, 2014 12:09
Show Gist options
  • Save niklasvincent/9706202 to your computer and use it in GitHub Desktop.
Save niklasvincent/9706202 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Set Graphite host
GRAPHITE="172.16.20.1"
GRAPHITE_PORT="2003"
stats() {
HOSTNAME="mediacenter"
DATE=$(date +%s)
echo "server.${HOSTNAME}.${1} ${2} ${DATE}" | nc $GRAPHITE $GRAPHITE_PORT -w 1
}
# Loop forever
while :
do
UPTIME=`cat /proc/uptime | awk '{print $1}'`
LOAD=`cat /proc/loadavg | awk '{print $1}'`
CPU_USR=`top -b -d1 -n1|grep -i "CPU" | head -n1|awk '{print $2}'|cut -d'%' -f1`
CPU_SYS=`top -b -d1 -n1|grep -i "CPU" | head -n1|awk '{print $4}'|cut -d'%' -f1`
CPU_IDLE=`top -b -d1 -n1|grep -i "CPU" | head -n1|awk '{print $8}'|cut -d'%' -f1`
MEM=`free -m|egrep "\-"|awk '{print $3}'`
stats "cpu.sys" ${CPU_SYS}
stats "cpu.idle" ${CPU_IDLE}
stats "cpu.usr" ${CPU_USR}
stats "memory.used" ${MEM}
stats "uptime" ${UPTIME}
stats "load" ${LOAD}
sleep 5
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment