Skip to content

Instantly share code, notes, and snippets.

@neilmillard
Last active August 20, 2019 14:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neilmillard/43eafc4d9a4f201202a08719b39f0cc7 to your computer and use it in GitHub Desktop.
Save neilmillard/43eafc4d9a4f201202a08719b39f0cc7 to your computer and use it in GitHub Desktop.
metrics-graphite for sensu on centos/redhat
cpu () {
echo $HOSTNAME.cpu $(mpstat 1 1 | awk '$13 ~ /[0-9.]+/ { print 100 - $13 }') $(date +%s)
}
disk_io () {
echo $HOSTNAME.disk_io $(iostat -d -z ALL | awk 'NF==6 {s+=$2} END {print s}') $(date +%s)
}
disk_usage () {
echo $HOSTNAME.disk_usage $(df -k / | awk 'NR > 1 {print $5}' | cut -d "%" -f 1) $(date +%s)
}
heartbeat () {
echo $HOSTNAME.heartbeat 1 $(date +%s)
}
memory () {
echo $HOSTNAME.memory $(free -m | awk 'NR==2{printf "%.2f", $3*100/$2 }') $(date +%s)
}
network_io () {
echo $HOSTNAME.network_in $(($((`date "+%s"`)) % 60)) $(date +%s)
echo $HOSTNAME.network_out $(($((`date "+%s"`+ 30 )) % 60)) $(date +%s)
}
ping_ok () {
ping -c 1 $PING_REMOTE_HOST > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo $HOSTNAME.ping_ok 1 $(date +%s)
else
echo $HOSTNAME.ping_ok 0 $(date +%s)
fi
}
HOSTNAME=$(hostname)
cpu
disk_io
disk_usage
heartbeat
memory
network_io
ping_ok
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment