<dependency> <groupId>io.prometheus</groupId> <artifactId>simpleclient</artifactId> <version>0.11.0</version> </dependency> MeterRegistry registry = new SimpleMeterRegistry(); Counter requests = Counter.builder("requests_total") .description("Total number of requests") .register(registry); Prometheus.server(registry).httpServer() .bind(8080); import io.prometheus.client.Counter; import io.prometheus.client.exporter.HTTPServer; import io.prometheus.client.hotspot.DefaultExports; import io.prometheus.client.SimpleCollector; public class Main { public static void main(String[] args) throws Exception { MeterRegistry registry = new SimpleMeterRegistry(); Counter requests = Counter.builder("requests_total") .description("Total number of requests") .register(registry); DefaultExports.initialize(); HTTPServer server = new HTTPServer(8080); while (true) { processRequest(); requests.increment(); Thread.sleep(1000); } } private static void processRequest() { System.out.println("Processing request..."); } }


上一篇:
下一篇:
切换中文