client_python icon indicating copy to clipboard operation
client_python copied to clipboard

API for simple readonly queries?

Open mecampbellsoup opened this issue 4 years ago • 5 comments

My use case is fairly simple:

I'm looking for a Prometheus client in Python because I'm going to be doing some queries, e.g. (a picture is worth a thousand words, right?):

image

This project seems mostly designed for easily registering new metrics, gauges, etc., and pushing data to a Prom backend.

Am I missing something? Should I just use a generic HTTP client?

mecampbellsoup avatar Apr 19 '21 15:04 mecampbellsoup

Hello, you are correct that this project is designed for easily registering and exposing data to a Prometheus instance to gather right now. You could take a look at https://github.com/AICoE/prometheus-api-client-python for a Python client to implement with a Prometheus server for querying, there might be other projects as well.

I would have to give it a bit of thought as to whether or not to include code to interact with the API in this project or not. I think that it should at least be a separate package since most ~users~ services will just need their code instrumented and not need to query Prometheus as well. https://github.com/prometheus/client_golang does provide an api client as part of the project, and I will gather some input from them.

csmarchbanks avatar Apr 19 '21 19:04 csmarchbanks

most users will just want to instrument their code and not need to query Prometheus as well.

Is this because they're just using standard interfaces like Grafana to read Prometheus data? In our case we're a cloud provider and are building a user-facing dashboard to give our tenants a snapshot of their usage & billing data, which we periodically push to Prometheus.

mecampbellsoup avatar Apr 19 '21 19:04 mecampbellsoup

Yea, from the official Go client:

It has two separate parts, one for instrumenting application code, and one for creating clients that talk to the Prometheus HTTP API.

https://github.com/prometheus/client_golang/tree/master/api

mecampbellsoup avatar Apr 19 '21 19:04 mecampbellsoup

most users will just want to instrument their code and not need to query Prometheus as well.

Is this because they're just using standard interfaces like Grafana to read Prometheus data? In our case we're a cloud provider and are building a user-facing dashboard to give our tenants a snapshot of their usage & billing data, which we periodically push to Prometheus.

I think users was not the correct word for me to use there. A majority of services just need to expose their data to Prometheus, and then a user would use interfaces like Grafana or the Prometheus UI to query for data. It is much less common for a service to also need to query for metrics in Prometheus. There are certainly use cases though such as your case, autoscaling, or other adaptive behavior based on metrics.

csmarchbanks avatar Apr 19 '21 19:04 csmarchbanks

+1 for this, essentially similar use case and I've also gone down the path of using that other repository. It feels weird to have a repository to read and a repository to write even though they are interacting with the same service.

jeubis avatar Feb 21 '22 17:02 jeubis