
It's possible for Prometheus to return multiple metrics, where each of them has different labels. Before this the client would fail with error when using the default table formatter, because of for example: Row has incorrect number of values, (actual) 8!=9 (expected) It was also possible to mismatch the label keys and values for some of the rows. This patch makes sure the label values are matched to the correct keys. It also makes sure it uses all labels and it fills missing values with empty strings for metrics, which don't have that label defined. Example table output: +------------+----------+------------+----------------+-------+ | group | __name__ | job | instance | value | +------------+----------+------------+----------------+-------+ | | up | sg-core | localhost:3000 | 1 | | production | up | prometheus | localhost:9090 | 1 | +------------+----------+------------+----------------+-------+ Example json output: [ { "__name__": "up", "group": "", "job": "sg-core", "instance": "localhost:3000", "value": "1" }, { "__name__": "up", "group": "production", "job": "prometheus", "instance": "localhost:9090", "value": "1" } ] Change-Id: Id0dfabf52fe0a21194c498f4aefa1bff1d3eeea9
python-observabilityclient
observabilityclient is an OpenStackClient (OSC) plugin implementation that implements commands for management of Prometheus.
Development
Install your OpenStack environment and patch your openstack
client application using python.
# if using standalone, the following commands come after 'sudo dnf install -y python3-tripleoclient'
su - stack
# clone and install observability client plugin
git clone https://github.com/infrawatch/python-observabilityclient
cd python-observabilityclient
sudo python setup.py install --prefix=/usr
Usage
Use openstack metric query somequery
to query for metrics in prometheus.
To use the python api do the following:
from observabilityclient import client
c = client.Client(
'1', keystone_client.get_session(conf),
adapter_options={
'interface': conf.service_credentials.interface,
'region_name': conf.service_credentials.region_name})
c.query.query("somequery")
List of commands
openstack metric list - lists all metrics openstack metric show - shows current values of a metric openstack metric query - queries prometheus and outputs the result openstack metric delete - deletes some metrics openstack metric snapshot - takes a snapshot of the current data openstack metric clean-tombstones - cleans the tsdb tombstones
List of functions provided by the python library
c.query.list - lists all metrics c.query.show - shows current values of a metric c.query.query - queries prometheus and outputs the result c.query.delete - deletes some metrics c.query.snapshot - takes a snapshot of the current data c.query.clean-tombstones - cleans the tsdb tombstones