How to expose Prometheus custom metrics to specific server using Prometheus Java Client?

92 views
Skip to first unread message

Nikunj Gohil

unread,
Jan 6, 2022, 1:14:41 AM1/6/22
to Prometheus Users

We have automation project which is not hosted basically and we are executing our github branches using Jenkins.

So when out jobs executes through Jenkins then the execution has Prometheus instrumentation and needs to expose metrics but how Prometheus scrape it??

HTTPServer httpServer = new HTTPServer.Builder().withPort(8001).build();

One way found which is setup Prometheus HttpServer to specific port and Prometheus scraps metrics from this port but when Jenkins executions starts, HttpServer up and running and when ends then HttpServer goes down and next time same happens.

So need to overcome this problem. Is there any way for it using Prometheus Java Client library?

Nikunj Gohil

unread,
Jan 6, 2022, 1:15:03 AM1/6/22
to Prometheus Users

Brian Candler

unread,
Jan 6, 2022, 6:24:32 AM1/6/22
to Prometheus Users
PushGateway is one possible solution here.  Get your Jenkins job to write metric(s) to PushGateway before it terminates.  Those metrics can be scraped by the prometheus server whenever it likes, and will always remain "fresh" (i.e. it will see the most-recently pushed values).
Reply all
Reply to author
Forward
0 new messages