Prometheus

Prometheus API Client in Python

Seems like we have everything in Python :)).

Donald Le
Jan 19, 2021

--

When it comes to metrics analyzing, Prometheus is a popular choice. For getting metrics from Prometheus we can use its HTTP API. Consider this http for getting query range in Prometheus:

Prometheus Query Range

For convenience, we can install Python Prometheus API client library.

pip install prometheus-api-client

For example we can get all metrics from prometheus

def print_metrics():
from prometheus_api_client import PrometheusConnect
prom = PrometheusConnect(url="http://3.19.55.237:9090", disable_ssl=True)

# Get the list of all the metrics that the Prometheus host scrapes
print(prom.all_metrics())


# Press the green button in the gutter to run the script.
if __name__ == '__main__':
print_metrics()

The console will show all the metrics

['CodeGenerator_compilationTime_count', 'CodeGenerator_compilationTime_max', 'CodeGenerator_compilationTime_mean', 'CodeGenerator_compilationTime_min', 'CodeGenerator_compilationTime_p50', 'CodeGenerator_compilationTime_p75', ....

There’s a lot more features so take your time to explore.

Happy coding ~~

--

--

Donald Le
Donald Le

Written by Donald Le

A passionate automation engineer who strongly believes in “A man can do anything he wants if he puts in the work”.

No responses yet