Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/387.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何向Prometheus提供Java应用程序代码度量_Java_Prometheus - Fatal编程技术网

如何向Prometheus提供Java应用程序代码度量

如何向Prometheus提供Java应用程序代码度量,java,prometheus,Java,Prometheus,我正在尝试将Java应用程序的定制值指标导出到Prometheus。我已经读到可以使用Push Gateway完成,下面是我使用下一种方法的示例: static void executeBatchJob() throws Exception { CollectorRegistry registry = new CollectorRegistry(); Gauge duration = Gauge.build() .name("my_batch_job_dur

我正在尝试将Java应用程序的定制值指标导出到Prometheus。我已经读到可以使用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");
     }
   }
但当我运行项目时,我遇到了下一个错误: 线程“main”java.lang.NoClassDefFoundError中出现异常:io/prometheus/client/exporter/common/TextFormat 位于io.prometheus.client.exporter.PushGateway.doRequest(PushGateway.java:299) 位于io.prometheus.client.exporter.PushGateway.pushAdd(PushGateway.java:158) 位于nemshelloworld.nemshelloworld.executeBatchHjob2(nemshelloworld.java:78) 位于nemshelloworld.nemshelloworld.main(nemshelloworld.java:33) 原因:java.lang.ClassNotFoundException:io.prometheus.client.exporter.common.TextFormat 位于java.net.URLClassLoader.findClass(URLClassLoader.java:381) 位于java.lang.ClassLoader.loadClass(ClassLoader.java:424) 位于sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
在java.lang.ClassLoader.loadClass(ClassLoader.java:357)中,您缺少了
simpleclient\u common
模块,它是
simpleclient\u pushgateway
的一个列出的依赖项,因此听起来您的pom.xml或等效项不正确。

您应该使用导出器,而不是推送网关。您也可能需要考虑MyMeTel.IO。facade@Marged我使用导出器,但只导出JVM默认度量,我想在Java代码中导出自定义度量。千分尺不用于弹簧?我可以用Java来使用吗?谢谢!我添加了simpleclient_common,它在完美的库中工作