Prometheus client libraries don't just export metrics in our format, they can parse that format too.

Even if you don't run Prometheus, the Prometheus exposition format can be useful to you. By having a standard format exposed by a wide variety of integrations, you gain access to metrics that you'd have to otherwise figure out how to extract yourself. You might use this as part of an auto-scaling system, or even to send the metrics on to another monitoring system like Graphite.

Let's look at an example where we pull down metrics from a node exporter.

 

First install the python client and requests, if you don't already have them:

$ pip install prometheus_client requests

Then we can fetch the data we need, and print it:

from prometheus_client.parser import text_string_to_metric_families
import requests

metrics = requests.get("http://demo.robustperception.io:9100/metrics").content

for family in text_string_to_metric_families(metrics):
  for sample in family.samples:
    print("Name: {0} Labels: {1} Value: {2}".format(*sample))

These few lines of code can be extended to do whatever you like!

 

Questions about client libraries ? Contact us.