browbeat/ansible/install/roles/collectd-openstack/files/collectd_gnocchi_status.py
akrzos 39cf6ce92e Collectd plugin: Gnocchi status
Initial commit to add a plugin to collectd for obtaining and storing
Gnocchi status metrics.  This plug obtains the two metrics provided
by Gnocchi's REST API for "the number of metrics having measures to be
processed" and "the number of measures to process".

This also addes an associated graph in the General OpenStack System
Performance Dashboard and the Controller specific dashboard.

* no longer requires authentication details in the collectd config
* removing the redis exec plugin
* configurable interval for the python plugin now

Change-Id: Idfc5c719e9b0fbaad5db0632a3e5293bf03d7ab6
2016-12-20 16:14:06 +00:00

62 lines
1.9 KiB
Python

#!/usr/bin/env python
"""Collectd python plugin to read gnocchi status on an OpenStack Controller."""
from gnocchiclient.v1 import client
from keystoneauth1.identity import v2
from keystoneauth1 import session
import collectd
import os
import time
def configure(configobj):
global INTERVAL
config = {c.key: c.values for c in configobj.children}
INTERVAL = 10
if 'interval' in config:
INTERVAL = config['interval'][0]
collectd.info('gnocchi_status: Interval: {}'.format(INTERVAL))
collectd.register_read(read, INTERVAL)
def read(data=None):
starttime = time.time()
auth = v2.Password(username=os_username,
password=os_password,
tenant_name=os_tenant,
auth_url=os_auth_url)
sess = session.Session(auth=auth)
gnocchi = client.Client(session=sess)
status = gnocchi.status.get()
metric = collectd.Values()
metric.plugin = 'gnocchi_status'
metric.interval = INTERVAL
metric.type = 'gauge'
metric.type_instance = 'measures'
metric.values = [status['storage']['summary']['measures']]
metric.dispatch()
metric = collectd.Values()
metric.plugin = 'gnocchi_status'
metric.interval = INTERVAL
metric.type = 'gauge'
metric.type_instance = 'metrics'
metric.values = [status['storage']['summary']['metrics']]
metric.dispatch()
timediff = time.time() - starttime
if timediff > INTERVAL:
collectd.warning('gnocchi_status: Took: {} > {}'.format(round(timediff, 2),
INTERVAL))
os_username = os.environ.get('OS_USERNAME')
os_password = os.environ.get('OS_PASSWORD')
os_tenant = os.environ.get('OS_TENANT_NAME')
os_auth_url = os.environ.get('OS_AUTH_URL')
collectd.info('gnocchi_status: Connecting with user={}, password={}, tenant={}, '
'auth_url={}'.format(os_username, os_password, os_tenant, os_auth_url))
collectd.register_config(configure)