简体   繁体   English

如何向 Prometheus 公开 Dropwizard 指标

[英]How to expose Dropwizard Metrics to Prometheus

I have implemented a Java web service using Dropwizard .我已经使用Dropwizard实现了一个 Java Web 服务。 Now I want it to also expose Prometheus metrics .现在我希望它也公开Prometheus 指标

I have followed this pretty straight-forward example.我遵循了这个非常简单的例子。 However, the endpoint at http://localhost:9090/metrics is still not exposed.但是, http://localhost:9090/metrics的端点仍然没有暴露。

Here's the relevant code:以下是相关代码:

Dependencies in the pom.xml : 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>

The Java code: 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> {

@Override
public 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");
}

Any pointers to what I'm doing wrong?任何指向我做错了什么的指针?

Remember default dropwizard configuration has the admin app on a different port.请记住,默认的 dropwizard 配置在不同的端口上有管理应用程序。 That's where you'd find the metrics servlet.这就是您可以找到度量 servlet 的地方。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM