Created
June 4, 2012 21:12
-
-
Save svperfecta/2870878 to your computer and use it in GitHub Desktop.
Unicorn Active Connection Monitoring
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
#!/usr/bin/env ruby | |
# Copyright: 2011 Opscode, Inc. | |
# Author: Bryan McLellan <[email protected]> | |
# Modified by: Brian Corrigan 2012 | |
# | |
# 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' | |
# Grab all the Rails sockets | |
@sockets = Dir.glob("/root/of/all/rails/*/tmp/sockets/*.sock").collect do |socket| | |
file, site, environment = socket.match(/.*rails\/(.*)\/tmp.*sockets\/(.*)\.sock/).to_a | |
{:file => file, :site => site, :environment => environment} | |
end | |
# Might as well track PHP too | |
@sockets << {:file => '/var/run/php5-fpm.sock', :site => "PHP", :environment => "unknown"} | |
# Get stats | |
def collect | |
# raindrops requires an array of strings, even if it denies this | |
stats = @sockets.each do |socket| | |
stats = Raindrops::Linux.unix_listener_stats(socket[:file]) | |
puts "#{socket[:site]}_#{socket[:environment]}.value #{stats[socket[:file]].active}" | |
end | |
exit 0 | |
end | |
# Return the config | |
def config | |
puts "graph_title Unicorn - Active Connections" | |
puts "graph_args -l 0" | |
puts "graph_printf %6.0lf" | |
puts "graph_vlabel connections" | |
puts "graph_category Unicorn" | |
@sockets.each do |socket| | |
puts "#{socket[:site]}_#{socket[:environment]}.label #{socket[:site]}_#{socket[:environment]}_active" | |
end | |
exit 0 | |
end | |
if ARGV[0] == "config" | |
config | |
else | |
collect | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment