Skip to content

Instantly share code, notes, and snippets.

@eric
Created February 25, 2012 20:39
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eric/1910512 to your computer and use it in GitHub Desktop.
Save eric/1910512 to your computer and use it in GitHub Desktop.
#
# Created by Eric Lindvall <eric@sevenscale.com>
#
class KestrelMonitor < Scout::Plugin
OPTIONS=<<-EOS
host:
label: Host
notes: Kestrel host
default: localhost
port:
label: Port
notes: Kestrel admin HTTP port
default: 2223
EOS
needs 'open-uri'
needs 'json'
def build_report
counter 'data_read_per_second', counter_stat(:bytes_read).to_i / 1024.0, :per => :second
counter 'data_written_per_second', counter_stat(:bytes_written).to_i / 1024.0, :per => :second
counter 'gets_per_second', counter_stat(:cmd_get), :per => :second
counter 'peeks_per_second', counter_stat(:cmd_peek), :per => :second
counter 'sets_per_second', counter_stat(:cmd_set), :per => :second
counter 'hits_per_second', counter_stat(:get_hits), :per => :second
counter 'misses_per_second', counter_stat(:get_misses), :per => :second
counter 'connections_per_second', counter_stat(:total_connections), :per => :second
counter 'items_per_second', counter_stat(:total_items), :per => :second
report 'connections' => gauge_stat(:connections)
report 'items' => gauge_stat(:items)
report 'jvm_heap_used' => gauge_stat(:jvm_heap_used).to_i / 1024.0 / 1024.0
report 'jvm_heap_max' => gauge_stat(:jvm_heap_max).to_i / 1024.0 / 1024.0
end
def counter_stat(stat)
stats['counters'][stat.to_s].to_i
end
def gauge_stat(stat)
stats['gauges'][stat.to_s]
end
def stats
@stats ||= JSON.parse(open("http://#{option(:host)}:#{option(:port)}/admin/stats").read)
end
end
#
# Created by Eric Lindvall <eric@sevenscale.com>
#
class KestrelQueueMonitor < Scout::Plugin
OPTIONS=<<-EOS
host:
label: Host
notes: Kestrel host
default: localhost
port:
label: Port
notes: Kestrel admin HTTP port
default: 2223
queue:
label: Queue
notes: Name of Kestrel queue
EOS
needs 'open-uri'
needs 'json'
def build_report
report :items => gauge_stat(:items), :open_transacitons => gauge_stat(:open_transactions),
:mem_items => gauge_stat(:mem_items), :age => gauge_stat(:age_msec).to_f / 1000,
:waiters => gauge_stat(:waiters)
counter(:item_rate, counter_stat(:total_items), :per => :second)
end
def counter_stat(stat)
stats['counters']["q/#{option(:queue)}/#{stat.to_s}"]
end
def gauge_stat(stat)
stats['gauges']["q/#{option(:queue)}/#{stat.to_s}"]
end
def stats
@stats ||= JSON.parse(open("http://#{option(:host)}:#{option(:port)}/admin/stats").read)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment