def fetch_stats(user, password): cmd = 'mysqladmin extended --user=%s --password=%s' % (user, password) stdout = pygmetric.shell.run(cmd) metrics = {} for line in stdout.split("\n"): parts = line.split() if len(parts) != 5: continue mysql_name, value = parts[1], parts[3] if mysql_name in COUNT_METRICS: prototype = COUNT_METRICS[mysql_name] metrics[prototype['name']] = { 'name': prototype['name'], 'value': int(value), 'type': prototype['type'], 'units': prototype['units'], } elif mysql_name in RATE_METRICS: prototype = RATE_METRICS[mysql_name] current_value = int(value) value = pygmetric.get_rate(prototype['name'], current_value, 1) if value: metrics[prototype['name']] = { 'name': prototype['name'], 'value': value, 'type': prototype['type'], 'units': prototype['units'], } return metrics
def fetch_stats(vhost, queue): """ Fetch stats of a given queue """ cmd = '/usr/sbin/rabbitmqctl list_queues -p %s' % vhost stdout = pygmetric.shell.run(cmd) lines = stdout.split("\n") metrics = {} for line in lines: if "\t" not in line: continue queue_name, count = line.split("\t") if queue_name == queue: value = int(count) name = 'rabbitmq_queue_%s' % queue metrics[name] = { 'name': name, 'value': value, 'type': 'uint32', 'units': 'Queue size', } rate_name = "%s_rate" % name rate = pygmetric.get_rate(rate_name, value, period=60) if rate is not None: metrics[rate_name] = { 'name': rate_name, 'value': rate, 'type': 'float', 'units': 'Items per minute', } return metrics