我已经使用Dropwizard实现了一个 Java Web 服务。现在我希望它也公开Prometheus metrics。我遵循了这个非常直接的例子。但是,位于http://localhost:9090/metrics的端点仍未公开。这是相关的代码:中的依赖项pom.xml: <dependency> <groupId>io.prometheus</groupId> <artifactId>simpleclient_dropwizard</artifactId> <version>0.5.0</version> </dependency> <!-- https://mvnrepository.com/artifact/io.prometheus/simpleclient_servlet --> <dependency> <groupId>io.prometheus</groupId> <artifactId>simpleclient_servlet</artifactId> <version>0.5.0</version> </dependency>Java代码:import io.dropwizard.Application;import io.dropwizard.setup.Bootstrap;import io.dropwizard.setup.Environment;import io.prometheus.client.CollectorRegistry;import io.prometheus.client.dropwizard.DropwizardExports;import io.prometheus.client.exporter.MetricsServlet;[...]public class MyApplication extends Application<MyServiceConfiguration> {@Overridepublic void run(final MyServiceConfiguration configuration, final Environment environment) { final MyServiceResource resource = createResource(configuration); environment.jersey().register(resource); registerHealthChecks(environment, resource); registerMetrics(environment);}private void registerMetrics(Environment environment) { CollectorRegistry collectorRegistry = new CollectorRegistry(); collectorRegistry.register(new DropwizardExports(environment.metrics())); environment.admin().addServlet("metrics", new MetricsServlet(collectorRegistry)) .addMapping("/metrics");}任何指向我做错了什么的指针?
添加回答
举报
0/150
提交
取消