Created
September 13, 2013 09:09
-
-
Save plexus/6548343 to your computer and use it in GitHub Desktop.
This file contains 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
# put in /etc/init/librato.conf and start with 'sudo start librato' | |
description "collect metrics" | |
start on (local-filesystems and net-device-up IFACE!=lo) | |
respawn | |
env EMAIL=<your email> | |
env TOKEN=<your librato token> | |
env INTERVAL=30 | |
script | |
SOURCE=`hostname` | |
while true ; do | |
CPU_PCT=$(ps aux | awk '{s=s+$3}; END {print s}') | |
MEM_PCT=$(ps aux | awk '{s=s+$4}; END {print s}') | |
# prevent network or API problems from hitting the respawn limit | |
if nc -w 1 -z metrics-api.librato.com 80 ; then | |
curl -u ${EMAIL}:${TOKEN} \ | |
-d 'gauges[0][name]=CPU' \ | |
-d 'gauges[0][value]='$CPU_PCT \ | |
-d 'gauges[0][source]='$SOURCE \ | |
-d 'gauges[1][name]=MEM' \ | |
-d 'gauges[1][value]='$MEM_PCT \ | |
-d 'gauges[1][source]='$SOURCE \ | |
-X POST https://metrics-api.librato.com/v1/metrics | |
fi | |
sleep $INTERVAL | |
done | |
end script |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment