Created
June 16, 2015 07:18
-
-
Save toolmantim/0e76d0377bb23974b06f to your computer and use it in GitHub Desktop.
How to monitor Unicorn and Puma unix socket queues with statsd
This file contains hidden or 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
#!/bin/bash | |
# Logs the queued and active stats from the application's sockets and posts to statsd | |
while true; do | |
proc_lines=`cat /proc/net/unix` | |
for file in /home/deploy/myapp/tmp/sockets/*.sock; do | |
# /proc/net/unix lines are of the format: | |
# Num RefCount Protocol Flags Type St Inode Path | |
# | |
# A queued connection (02) looks like: | |
# 0000000000000000: 00000003 00000000 00000000 0001 02 0 /path/to/socket.sock | |
# | |
# An active connection (03) looks like: | |
# 0000000000000000: 00000003 00000000 00000000 0001 03 132727691 /path/to/socket.sock | |
queued=`echo "$proc_lines" | grep "02 \+[0-9]\+ \+$file" | wc -l` | |
active=`echo "$proc_lines" | grep "03 \+[0-9]\+ \+$file" | wc -l` | |
name=`basename $file .sock` | |
echo -n "myapp.socket.$name.queued.g:$queued|g" > /dev/udp/localhost/8125 | |
echo -n "myapp.socket.$name.active.g:$active|g" > /dev/udp/localhost/8125 | |
done | |
sleep 1 | |
done |
This file contains hidden or 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
description "Monitor the app's socket stats and send to statsd" | |
start on runlevel [2345] | |
stop on runlevel [!2345] | |
setuid app | |
setgid app | |
respawn | |
exec socket_stats_logger |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment