Skip to content

Instantly share code, notes, and snippets.

@nlinker
Forked from oremj/amo_rabbit_prod_report.php
Created October 31, 2012 15:54
Show Gist options
  • Save nlinker/3987848 to your computer and use it in GitHub Desktop.
Save nlinker/3987848 to your computer and use it in GitHub Desktop.
Rabbit ganglia metrics
<?php
/* Pass in by reference! */
function graph_amo_rabbit_prod_report ( &$rrdtool_graph ) {
global $context,
$hostname,
$mem_shared_color,
$mem_cached_color,
$mem_buffered_color,
$mem_swapped_color,
$mem_used_color,
$cpu_num_color,
$range,
$rrd_dir,
$size,
$strip_domainname;
if ($strip_domainname) {
$hostname = strip_domainname($hostname);
}
$title = 'RabbitMQ Status';
if ($context != 'host') {
$rrdtool_graph['title'] = $title;
} else {
$rrdtool_graph['title'] = "$hostname $title last $range";
}
$rrdtool_graph['height'] += $size == 'medium' ? 28 : 0 ; // Fudge to account for number of lines in the chart legend
$rrdtool_graph['lower-limit'] = '0';
$rrdtool_graph['vertical-label'] = 'messages';
$rrdtool_graph['extras'] = '--rigid';
$series =
"DEF:'celunack'='${rrd_dir}/rabbit_zamboni_prod_celery_messages_unacknowledged.rrd':'sum':AVERAGE "
. "DEF:'celready'='${rrd_dir}/rabbit_zamboni_prod_celery_messages_ready.rrd':'sum':AVERAGE "
. "DEF:'devunack'='${rrd_dir}/rabbit_zamboni_prod_devhub_messages_unacknowledged.rrd':'sum':AVERAGE "
. "DEF:'devready'='${rrd_dir}/rabbit_zamboni_prod_devhub_messages_ready.rrd':'sum':AVERAGE "
. "DEF:'imgunack'='${rrd_dir}/rabbit_zamboni_prod_images_messages_unacknowledged.rrd':'sum':AVERAGE "
. "DEF:'imgready'='${rrd_dir}/rabbit_zamboni_prod_images_messages_ready.rrd':'sum':AVERAGE "
. "LINE2:'celready'#0E8290:'Celery Ready' "
. "LINE2:'celunack'#0066FF:'Celery Unack' "
. "LINE2:'devready'#FF00FF:'Devhub Ready' "
. "LINE2:'devunack'#990099:'Devhub Unack' "
. "LINE2:'imgready'#00FF00:'Images Ready' "
. "LINE2:'devunack'#006600:'Images Unack' ";
$rrdtool_graph['series'] = $series;
return $rrdtool_graph;
}
?>
#!/usr/bin/python
from subprocess import Popen, PIPE
GMETRIC="/usr/bin/gmetric"
RABBITMQCTL="/usr/sbin/rabbitmqctl"
def run_gmetric(vhost, queue, qtype, value, prefix="rabbit", vtype="uint32"):
cmd = [GMETRIC,
'-t', vtype,
'-u', 'messages',
'-n', "%s_%s_%s_%s" % (prefix, vhost, queue, qtype),
'-v', "%d" % value]
Popen(cmd).communicate()
def get_vhost_stats(vhost, qtypes):
data = {}
VALID_TYPES = ['messages_ready', 'messages_unacknowledged']
qtypes = [t for t in qtypes if t in VALID_TYPES]
cmd = [RABBITMQCTL,
'list_queues',
'-p', vhost, 'name']
cmd.extend(qtypes)
stdout, stderr = Popen(cmd, stdout=PIPE, stderr=PIPE).communicate()
for l in stdout.split("\n")[1:-2]:
l = l.split()
name = l.pop(0)
data[name] = {}
for i, t in enumerate(qtypes):
data[name][t] = int(l[i])
return data
def graph(vhost, queues):
stats = get_vhost_stats(vhost, ('messages_ready', 'messages_unacknowledged') )
for q in queues:
qstats = stats[q]
for qtype, value in qstats.iteritems():
run_gmetric(vhost, q, qtype, value)
graph('zamboni_prod', ('celery', 'images', 'devhub'))
graph('zamboni_preview', ('celery', 'images', 'devhub'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment