【问题标题】:Expose Prometheus Metrics in Dropwizard在 Dropwizard 中公开 Prometheus 指标
【发布时间】:2018-10-22 14:04:09
【问题描述】:

我使用Dropwizard 实现了一个Java Web 服务。现在我想让它也暴露Prometheus metrics

我遵循了this 非常简单的示例。但是,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> {

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

任何指向我做错了什么的指针?

【问题讨论】:

  • 什么是管理端口? /metrics 嵌套在管理应用程序下。
  • 感谢指点,端点localhost:8081/metrics确实存在。

标签: java dropwizard prometheus


【解决方案1】:

请记住,默认的 dropwizard 配置在不同的端口上有管理应用程序。在那里您可以找到指标 servlet。

【讨论】:

    猜你喜欢
    • 2022-08-11
    • 2022-06-20
    • 1970-01-01
    • 2019-03-08
    • 1970-01-01
    • 2020-10-02
    • 1970-01-01
    • 1970-01-01
    • 2019-12-13
    相关资源
    最近更新 更多