Skip to content

Instantly share code, notes, and snippets.

@infertux
Created August 11, 2015 12:56
Show Gist options
  • Save infertux/ce3123ffbf5ac97410d3 to your computer and use it in GitHub Desktop.
Save infertux/ce3123ffbf5ac97410d3 to your computer and use it in GitHub Desktop.
Munin plugin to monitor the number of Unicorn connections on a socket
#!/bin/bash
# -*- sh -*-
# vim: ft=sh
: << =cut
=head1 NAME
unicorn_connections - Plugin to monitor the number of Unicorn connections
=head1 CONFIGURATION
[unicorn*]
env.socket /var/lib/unicorn.sock
=head1 AUTHOR
Cedric Felizard
=head1 LICENSE
AGPLv3+
=head1 MAGIC MARKERS
#%# family=auto
#%# capabilities=autoconf
=cut
SOCKET=$socket
CONNECTION_TYPES="listening active queued"
function connection_count
{
local type;
case "$1" in
listening) type=01;;
queued) type=02;;
active) type=03;;
esac
[ -z $type ] && return;
cat /proc/net/unix | grep -c -E ": [0-9]{8} 0{8} [0-9]{8} [0-9]{4} ${type} [0-9 ]+ ${SOCKET}$"
}
if [ "$1" = "autoconf" ]; then
autoconf="yes"
[ -S $SOCKET ] || autoconf="no"
echo $autoconf
exit 0
fi
if [ "$1" = "config" ]; then
echo 'graph_title Unicorn connections'
echo 'graph_vlabel number of connections'
echo 'graph_category unicorn'
echo 'graph_info This graph shows the number of Unicorn connections.'
for type in $CONNECTION_TYPES; do
echo "_${type}.label ${type}"
done
exit 0
fi
for type in $CONNECTION_TYPES; do
echo "_${type}.value $(connection_count ${type})"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment