Created
July 16, 2010 22:38
-
-
Save nstielau/479015 to your computer and use it in GitHub Desktop.
This file contains 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 | |
require 'rubygems' | |
require 'stomp' | |
################################ | |
# Config | |
stage = "dev" | |
host = "example.com" | |
port = 61613 | |
password = '' | |
username = '' | |
heartbeat_queue = "/queue/#{stage.downcase}-HeartbeatQueue" | |
warning_delay = 3 | |
critical_delay = 9 | |
################################ | |
# Create client | |
client = Stomp::Client.new(username, password, host, port) | |
if ARGV[0] == 'config' | |
# Print out config info for the plugin | |
puts "graph_title Queue receive delay on #{stage} message queues" | |
puts "graph_vlabel Delay (seconds)" | |
puts "graph_category #{stage.downcase} Message Queues" | |
puts "queue_delay.label Queue Delay" | |
puts "queue_delay.warning #{warning_delay}" | |
puts "queue_delay.critical #{critical_delay}" | |
else | |
# Setup subscriber | |
client.subscribe(heartbeat_queue) do |msg| | |
heartbeat_time = msg.body.gsub(/[a-zA-Z]/, "").to_i | |
time_diff = Time.now.to_i - heartbeat_time.to_i | |
puts "queue_delay.value #{time_diff}" | |
exit | |
end | |
# Send a heartbeat message | |
client.send(heartbeat_queue, "Heartbeat #{Time.now.to_i}") | |
# sleep for a bit, then close connection and spit out default time_diff | |
sleep (critical_delay + 5) | |
c.close | |
puts "queue_delay.value #{critical_delay + 1}" | |
end | |
This file contains 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 | |
require 'rubygems' | |
require 'hpricot' | |
require 'open-uri' | |
########################################################## | |
# Plugin Configuration | |
url = "http://example.com:8161/admin/xml/queues.jsp" | |
stage = "Production" | |
# leaving out HugeQueue that has so many items it skews the scale | |
ignore = %w(HugeQueue) | |
########################################################## | |
# Get queues from XML | |
doc = Hpricot(open(url)) | |
queue_rows = doc/"queue" | |
if ARGV[0] == 'config' | |
# Print out config info for the plugin | |
puts "graph_title Current items in the #{stage} queues" | |
puts "graph_vlabel Num Current Items" | |
puts "graph_category #{stage.downcase} Message Queues" | |
queue_rows.each do |queue_row| | |
queue_name = queue_row.attributes['name'] | |
puts "#{queue_name}.label #{queue_name}" | |
end | |
# Add warnings for specific queues... | |
%w(ExampleQueue).each do |q| | |
puts "#{q}.warning 30" | |
puts "#{q}.critical 70" | |
end | |
else | |
# Print out queue size for each queue (except the ignored ones..) | |
queue_rows.each do |queue_row| | |
queue_name = queue_row.attributes['name'] | |
if !ignore.include?(queue_name) | |
queue_size = (queue_row/"stats").first.attributes['size'] | |
puts "#{queue_name}.value #{queue_size}" | |
end | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment