Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
munin plugin to monitor unicorn connection queue
#!/usr/bin/env ruby
# Copyright: 2011 Opscode, Inc.
# Author: Bryan McLellan <btm@loftninjas.org>
# Solomon White <rubysolo@gmail.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
require 'rubygems'
require 'raindrops'
def collect(type, target)
stats = case type
when 'tcp'
collect_tcp(target)
when 'socket'
collect_socket(target)
end
puts "active.value #{ stats.active }"
puts "queued.value #{ stats.queued }"
end
def collect_tcp(port)
addr = [ "0.0.0.0:#{ port }" ]
stats = Raindrops::Linux.tcp_listener_stats(addr)
stats[addr[0]]
end
def collect_socket(sock)
sockets = [ "/tmp/#{ sock }" ]
stats = Raindrops::Linux.unix_listener_stats(sockets)
stats[sockets[0]]
end
if ARGV[0] == "config"
puts "graph_title Unicorn - connections"
puts "graph_args -l 0"
puts "graph_printf %6.0lf"
puts "graph_vlabel connections"
puts "graph_category Unicorn"
puts "active.label active"
puts "queued.label queued"
exit 0
end
type, target = *$0.scan(/unicorn_(tcp|socket)_connections_?(.*)/).first
target = ARGV[0] if target.empty? && ARGV.size > 0
if target.empty?
usage = "Usage: unicorn_(tcp|socket)_connections (port|socket)"
abort usage
end
collect(type, target)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment