<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient</artifactId>
<version>0.9.0</version>
</dependency>
import io.prometheus.client.CollectorRegistry;
import io.prometheus.client.Counter;
import io.prometheus.client.exporter.HTTPServer;
import io.prometheus.client.exporter.MetricsServlet;
public class Main {
private static final Counter requestsTotal = Counter.build()
.name("http_requests_total")
.help("Total number of HTTP requests.")
.register();
public static void main(String[] args) throws Exception {
CollectorRegistry registry = new CollectorRegistry();
requestsTotal.register(registry);
HTTPServer server = new HTTPServer(8080);
server.getContext("/metrics").addServlet(new MetricsServlet(registry), "/");
requestsTotal.inc();
Thread.sleep(60000);
}
}