-
-
Save bbrowning/fceeda168f292b921fd7 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
Queue /queues/a-kitchen-sink-queue | |
Total Messages Added: 97 | |
Messages Added in Last 10 Seconds: 11 | |
Current Queue Size: 0 | |
Queue Size Change in Last 10 Seconds: -86 | |
Last Message Added: 10/25/11 10:25:55 AM | |
Last Counter Update: 10/25/11 10:25:55 AM |
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
class StatsService | |
include TorqueBox::Injectors | |
def initialize(options={}) | |
@queue_controls = options['queues'].map { |q| queue_control(q) } | |
@sample_period = options['sample_period'] | |
end | |
def start | |
enable_message_counters | |
Thread.new { run } | |
end | |
def stop | |
@done = true | |
end | |
protected | |
def run | |
until @done | |
@queue_controls.each do |queue_control| | |
counter_info = org.hornetq.api.core.management.MessageCounterInfo.from_json(queue_control.list_message_counter) | |
sample_seconds = @sample_period / 1000 | |
puts <<EOF | |
Queue #{counter_info.name} | |
Total Messages Added: #{counter_info.count} | |
Messages Added in Last #{sample_seconds} Seconds: #{counter_info.count_delta} | |
Current Queue Size: #{counter_info.depth} | |
Queue Size Change in Last #{sample_seconds} Seconds: #{counter_info.depth_delta} | |
Last Message Added: #{counter_info.last_add_timestamp} | |
Last Counter Update: #{counter_info.udpate_timestamp} | |
EOF | |
end | |
sleep(10) | |
end | |
end | |
def enable_message_counters | |
server_control = hornetq_server.hornet_qserver_control | |
server_control.message_counter_max_day_count = 1 | |
server_control.message_counter_sample_period = @sample_period | |
server_control.enable_message_counters | |
end | |
def queue_control(name) | |
management_service = hornetq_server.management_service | |
management_service.getResource("jms.queue.#{name}") | |
end | |
def hornetq_server | |
@hornetq_server ||= inject('jboss.messaging.default') | |
end | |
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
services: | |
StatsService: | |
config: | |
sample_period: 10_000 | |
queues: | |
- '/queues/a-kitchen-sink-queue' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment