<dependency> <groupId>io.prometheus</groupId> <artifactId>simpleclient</artifactId> <version>0.13.0</version> </dependency> import io.prometheus.client.Gauge; //... public class MyLibraryMetrics { private static final Gauge methodExecutionTime = Gauge.build() .name("mylibrary_method_execution_time") .help("Execution time of my library methods") .register(); public static void recordMethodExecutionTime(double time) { methodExecutionTime.set(time); } } import io.prometheus.client.exporter.HTTPServer; //... public class MyLibraryMetricsExporter { public static void main(String[] args) throws IOException { HTTPServer server = new HTTPServer(1234); System.out.println("Prometheus Metrics Exporter started"); } } yaml scrape_configs: - job_name: 'my_library' static_configs: - targets: ['localhost:1234'] bash ./prometheus mylibrary_method_execution_time max(mylibrary_method_execution_time) count_over_time(mylibrary_method_execution_time{le="1"}[1m])


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