Reputation: 323
I was wondering if it is possible to collect all metric from Prometheus with Java client?
For example Go metrics, host metrics etc.
If yes, can these metrics be queried like on HTTP api?
Upvotes: 0
Views: 3342
Reputation: 5932
Could you please clarify: "instrumenting" usually means exposing metrics from your application's code to a Prometheus endpoint. The question reads that you either want to read metrics from an application, or from a Prometheus instance that has already scraped the metrics.
For this answer I assume that you're running a Prometheus instance that has already scraped the metrics.
If you want to read the most current values that Prometheus has scraped from your applications, you can use Prometheus' federation endpoint via HTTP: you can read all metrics with their current readings in one go, or apply a query. I'm not aware of a Java library to parse the format, but you find the definition here. You could use the same approach to query your applications directly.
If you want to receive a JSON that might be easier to parse, you can use Prometheus's HTTP API.
If you want to receive updates on values as soon as Prometheus queries them, you can hook up to the remote write API. There is already existing integrations, but at first glance there is no Java integration. You could use Kafka as an intermediary. Also, this might be more than you've asked for in this questions.
Upvotes: 5