Skip to content

Instantly share code, notes, and snippets.

@jqlblue
Created October 1, 2014 10:18
Show Gist options
  • Save jqlblue/c7473473f8a7357167b8 to your computer and use it in GitHub Desktop.
Save jqlblue/c7473473f8a7357167b8 to your computer and use it in GitHub Desktop.
collection monitor metrics to graphite
#!/bin/sh
HOST=$(hostname | awk -F'.' '{print $1}')
IDC="local"
SYSTEM_LOAD=$(awk '{print $1}' /proc/loadavg)
SYSTEM_MEMORY_FREE=$(free -m | grep 'buffers/cache' | awk '{print $NF}')
SYSTEM_SWAP_USE=$(free -m | grep 'Swap' | awk '{print $(NF-1)}')
SYSTEM_DISK_USED=$(df -h | grep '/' | awk 'BEGIN{_max=0}{len=length($5);i=substr($5,0,len-1);if(_max<i){_max=i}}END{print _max}')
#NGINX_CONNECTIONS=$(curl -s http://127.0.0.1/nginx_status | head -n 1 | awk '{print $NF}')
#FPM_CONNECTIONS=$(curl -s http://127.0.0.1/fpm_status | grep active | head -n 1 | awk '{print $NF}')
TIMESTAMP=$(date +%s)
### new garphite########
echo -n "server.$IDC.$HOST.system.load $SYSTEM_LOAD $TIMESTAMP" > /dev/udp/127.0.0.1/2003
echo -n "server.$IDC.$HOST.system.memory_free $SYSTEM_MEMORY_FREE $TIMESTAMP" > /dev/udp/127.0.0.1/2003
echo -n "server.$IDC.$HOST.system.swap_used $SYSTEM_SWAP_USED $TIMESTAMP" > /dev/udp/127.0.0.1/2003
echo -n "server.$IDC.$HOST.system.disk_used $SYSTEM_DISK_USED $TIMESTAMP" > /dev/udp/127.0.0.1/2003
#echo -n "server.$IDC.$HOST.nginx.connections $NGINX_CONNECTIONS $TIMESTAMP" > /dev/udp/127.0.0.1/2003
#echo -n "server.$IDC.$HOST.fpm.connections $FPM_CONNECTIONS $TIMESTAMP" > /dev/udp/127.0.0.1/2003
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment