简体   繁体   English

通过 servlet 访问 Dropwizard JVM 指标的问题

[英]Issue accessing Dropwizard JVM metrics via servlet

I'm adding Dropwizard Metrics to a web application.我正在将 Dropwizard Metrics 添加到 web 应用程序中。 I'm using the metrics servlet to retrieve the data.我正在使用度量 servlet 来检索数据。 However, I cannot get the JVM details to be returned.但是,我无法返回 JVM 详细信息。

I've set the following on the MetricRegistry我在 MetricRegistry 上设置了以下内容

metrics.register("jvm.memory", new MemoryUsageGaugeSet());
metrics.register("jvm.gc", new GarbageCollectorMetricSet());
metrics.register("jvm.attribute", new JvmAttributeGaugeSet());
metrics.register("jvm.threads", new ThreadStatesGaugeSet());
metrics.register("jvm.buffers", new BufferPoolMetricSet(ManagementFactory
                    .getPlatformMBeanServer()));
metrics.register("jvm.classloader", new ClassLoadingGaugeSet());
metrics.register("jvm.filedescriptor", new FileDescriptorRatioGauge());

According to the following javadoc, it says the Metrics Servlet takes a parameter.根据以下 javadoc,它说 Metrics Servlet 需要一个参数。 https://metrics.dropwizard.io/4.1.2/manual/servlets.html https://metrics.dropwizard.io/4.1.2/manual/servlets.html

MetricsServlet
.....
MetricsServlet also takes an initialization parameter, show-jvm-metrics, which if "false" will disable the outputting of JVM-level information in the JSON object.

I've done this but I still am not getting the JVM stats returned.我已经这样做了,但我仍然没有返回 JVM 统计信息。 The docs seem to infer that it should be true by default.文档似乎推断默认情况下它应该是真的。

<servlet>
        <servlet-name>metrics</servlet-name>
        <servlet-class>com.codahale.metrics.servlets.MetricsServlet</servlet-class>
        <init-param>
            <param-name>show-jvm-metrics</param-name>
            <param-value>true</param-value>
        </init-param>
    </servlet>

Am I missing another step?我错过了另一个步骤吗?

Thanks谢谢

Ok, so turns out this is correct.好的,事实证明这是正确的。 No missing step.没有遗漏的步骤。 For some reason after trying it again today the exact same code worked with no changes.由于某种原因,今天再次尝试后,完全相同的代码没有任何变化。 Go figure. Go 图。

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

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