Skip to content

Instantly share code, notes, and snippets.

@wido
Last active June 16, 2020 07:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wido/e815faedb393195c5a25 to your computer and use it in GitHub Desktop.
Save wido/e815faedb393195c5a25 to your computer and use it in GitHub Desktop.
Send Ceph pool statistics to Graphite
#!/usr/bin/env python
'''
This script gathers pool statistics from RADOS and sends them to a Graphite server
It allows you to graph and see what each pool is doing.
Author: Wido den Hollander <wido@widodh.nl>
'''
import time
import socket
import rados
GRAPHITE = ('graphite.mydomain.tld', 2003)
CEPH_CONF = '/etc/ceph/ceph.conf'
PREFIX = 'ceph'
def send_over_socket(destination, key, value, timestamp):
sock = socket.create_connection(destination)
sock.send("%s %0.3f %d\n" % (key, value, timestamp))
sock.close()
def gather_pool_statistics(ceph_conf):
r = rados.Rados(conffile=ceph_conf)
r.connect()
pools = r.list_pools()
now = int(time.time())
for pool in pools:
io = r.open_ioctx(pool)
pool_stats = io.get_stats()
io.close()
# Due to dot (.) at beginning of RGW pools
pool = pool.lstrip(".")
for key in pool_stats.keys():
name = "%s.pool.%s.%s" % (PREFIX, pool, key)
print "%s:%0.3f" % (name, pool_stats[key])
send_over_socket(GRAPHITE, name, pool_stats[key], now)
# Graphite doesn't seem happy if you flood it
time.sleep(0.1)
r.shutdown()
if __name__ == '__main__':
gather_pool_statistics(CEPH_CONF)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment