Created
February 28, 2014 13:07
-
-
Save wido/9270758 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 python | |
import time | |
import socket | |
import subprocess | |
import json | |
graphite_host = 'my.graphite.machine' | |
graphite_port = 2003 | |
prefix = 'ceph' | |
def collect_metric(name, value, timestamp): | |
sock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM, 0) | |
sock.connect((graphite_host, graphite_port, 0, 0)) | |
sock.send("%s %d %d\n" % (name, int(value), timestamp)) | |
sock.close() | |
def execute(command): | |
p = subprocess.Popen(command, stdout=subprocess.PIPE, shell=False) | |
(result, err) = p.communicate() | |
return result.strip() | |
status = json.loads(execute(["ceph", "-s", "--format", "json-pretty"])) | |
stats = { | |
"pgmap.data_bytes": status['pgmap']['data_bytes'], | |
"pgmap.bytes_used": status['pgmap']['bytes_used'], | |
"pgmap.bytes_avail": status['pgmap']['bytes_avail'], | |
"pgmap.bytes_total": status['pgmap']['bytes_total'], | |
"pgmap.read_bytes_sec": status['pgmap']['read_bytes_sec'], | |
"pgmap.write_bytes_sec": status['pgmap']['write_bytes_sec'], | |
"pgmap.op_per_sec": status['pgmap']['op_per_sec'], | |
"osdmap.num_osds": status['osdmap']['osdmap']['num_osds'], | |
"osdmap.num_up_osds": status['osdmap']['osdmap']['num_up_osds'], | |
"osdmap.num_in_osds": status['osdmap']['osdmap']['num_in_osds'] | |
} | |
now = int(time.time()) | |
for key in stats.keys(): | |
print "%s:%d" % (key, int(stats[key])) | |
collect_metric(prefix + "." + key, int(stats[key]), now) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment