简体   繁体   English

如何将Java应用程序代码指标检测到Prometheus

[英]How to instrument Java application code metrics to Prometheus

I am trying to export customized values metrics of my Java application to Prometheus. 我正在尝试将Java应用程序的自定义值指标导出到Prometheus。 I have read that it could be done with Push Gateway, following an example I use the next method: 我读过它可以通过Push Gateway来完成,下面是我使用下一个方法的示例:

static void executeBatchJob() throws Exception {
     CollectorRegistry registry = new CollectorRegistry();
     Gauge duration = Gauge.build()
         .name("my_batch_job_duration_seconds").help("Duration of my batch job in seconds.").register(registry);
     Gauge.Timer durationTimer = duration.startTimer();
     try {
       // Your code here.
       myCode();
       // This is only added to the registry after success,
       // so that a previous success in the Pushgateway isn't overwritten on failure.
       Gauge lastSuccess = Gauge.build()
           .name("my_batch_job_last_success").help("Last time my batch job succeeded, in unixtime.").register(registry);
       lastSuccess.setToCurrentTime();
     } finally {
       durationTimer.setDuration();
       PushGateway pg = new PushGateway("172.16.124.40:9091");
       pg.pushAdd(registry, "my_batch_job");
     }
   }

But when I run the project I am having the next error: Exception in thread "main" java.lang.NoClassDefFoundError: io/prometheus/client/exporter/common/TextFormat at io.prometheus.client.exporter.PushGateway.doRequest(PushGateway.java:299) at io.prometheus.client.exporter.PushGateway.pushAdd(PushGateway.java:158) at nemshelloworld.NemsHelloWorld.executeBatchJob2(NemsHelloWorld.java:78) at nemshelloworld.NemsHelloWorld.main(NemsHelloWorld.java:33) Caused by: java.lang.ClassNotFoundException: io.prometheus.client.exporter.common.TextFormat at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) 但是,当我运行项目时,我遇到下一个错误: Exception in thread "main" java.lang.NoClassDefFoundError: io/prometheus/client/exporter/common/TextFormat at io.prometheus.client.exporter.PushGateway.doRequest(PushGateway.java:299) at io.prometheus.client.exporter.PushGateway.pushAdd(PushGateway.java:158) at nemshelloworld.NemsHelloWorld.executeBatchJob2(NemsHelloWorld.java:78) at nemshelloworld.NemsHelloWorld.main(NemsHelloWorld.java:33) Caused by: java.lang.ClassNotFoundException: io.prometheus.client.exporter.common.TextFormat at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335) at java.lang.ClassLoader.loadClass(ClassLoader.java:357)

你错过了simpleclient_common模块,它是一个上市的依赖simpleclient_pushgateway所以,它听起来就像你的pom.xml或等同是不正确的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从 java 应用程序中以 Prometheus 格式导出指标(由 DropWizard 收集)? - How to export metrics (collected by DropWizard) in Prometheus format from java application? 使用 SimpleClientHttpRequestFactory 时,如何使自定义 RestTemplate 使用标准 Spring Boots 的 Prometheus RestTemplate 指标进行检测? - How to make custom RestTemplate to instrument with standard Spring Boots' Prometheus RestTemplate metrics when using SimpleClientHttpRequestFactory? 如何在 java 程序中收集 Prometheus 指标? - How to collect the Prometheus metrics in a java program? 使用Java客户端检测Prometheus指标 - Instrumenting Prometheus metrics with Java client 如何使用Prometheus的JMX导出器java代理来收集自定义指标 - How to use Prometheus' JMX exporter java agent to collect custom metrics 您如何配置prometheus.yml文件以在Spring-Boot应用程序中收集Prometheus指标? - How do you configure prometheus.yml file to collect Prometheus metrics in a Spring-Boot application? 如何向 Prometheus 公开 Dropwizard 指标 - How to expose Dropwizard Metrics to Prometheus 如何使用java方法? - How to instrument java methods? jersey 应用程序中的千分尺 Prometheus 指标(非弹簧) - Micrometer Prometheus metrics in jersey application (Non spring) Prometheus Java 客户端:导出基于字符串的指标 - Prometheus Java Client : Export String based Metrics
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM