2017-06-13 57 views
0

我一直在試圖找出MetricRegistry細節根據我的項目之一上dropwizard:1.1.0Dropwizard默認使用哪些指標核心?

enter image description here

這裏的一個小的困惑是,我看到我的服務用於localhost:8181/metrics(adminConnector)的版本3.1.3這不是最新的,並列入dropwizard-core注意:+ - io.dropwizard.metrics:指標核心中:jar:3.2.2的依賴關係:下樹)的一個

相對POM依賴使用dencies是:

<dependency> 
    <groupId>io.dropwizard</groupId> 
    <artifactId>dropwizard-core</artifactId> 
    <version>1.1.0</version> 
</dependency> 
<dependency> 
    <groupId>io.federecio</groupId> 
    <artifactId>dropwizard-swagger</artifactId> 
    <version>0.7.0</version> 
</dependency> 

mvn dependency:tree的項目如下:

+- io.dropwizard:dropwizard-core:jar:1.1.0:compile 
[INFO] | +- io.dropwizard:dropwizard-util:jar:1.1.0:compile 
[INFO] | | +- com.fasterxml.jackson.core:jackson-annotations:jar:2.8.0:compile 
[INFO] | | +- com.google.code.findbugs:jsr305:jar:3.0.1:compile 
[INFO] | | \- joda-time:joda-time:jar:2.9.7:compile 
[INFO] | +- io.dropwizard:dropwizard-jackson:jar:1.1.0:compile 
[INFO] | | +- com.fasterxml.jackson.core:jackson-core:jar:2.8.7:compile 
[INFO] | | +- com.fasterxml.jackson.core:jackson-databind:jar:2.8.7:compile 
[INFO] | | +- com.fasterxml.jackson.datatype:jackson-datatype-guava:jar:2.8.7:compile 
[INFO] | | +- com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar:2.8.7:compile 
[INFO] | | +- com.fasterxml.jackson.datatype:jackson-datatype-jdk8:jar:2.8.7:compile 
[INFO] | | +- com.fasterxml.jackson.module:jackson-module-parameter-names:jar:2.8.7:compile 
[INFO] | | +- com.fasterxml.jackson.module:jackson-module-afterburner:jar:2.8.7:compile 
[INFO] | | +- com.fasterxml.jackson.datatype:jackson-datatype-joda:jar:2.8.7:compile 
[INFO] | | +- org.slf4j:slf4j-api:jar:1.7.24:compile 
[INFO] | | \- ch.qos.logback:logback-classic:jar:1.2.1:compile 
[INFO] | +- io.dropwizard:dropwizard-validation:jar:1.1.0:compile 
[INFO] | | +- org.hibernate:hibernate-validator:jar:5.3.4.Final:compile 
[INFO] | | | +- org.jboss.logging:jboss-logging:jar:3.3.0.Final:compile 
[INFO] | | | \- com.fasterxml:classmate:jar:1.3.1:compile 
[INFO] | | \- org.glassfish:javax.el:jar:3.0.0:compile 
[INFO] | +- io.dropwizard:dropwizard-configuration:jar:1.1.0:compile 
[INFO] | | \- com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:jar:2.8.7:compile 
[INFO] | |  \- org.yaml:snakeyaml:jar:1.17:compile 
[INFO] | +- io.dropwizard:dropwizard-logging:jar:1.1.0:compile 
[INFO] | | +- io.dropwizard.metrics:metrics-logback:jar:3.2.2:compile 
[INFO] | | +- org.slf4j:jul-to-slf4j:jar:1.7.24:compile 
[INFO] | | +- ch.qos.logback:logback-core:jar:1.2.1:compile 
[INFO] | | +- org.slf4j:log4j-over-slf4j:jar:1.7.24:compile 
[INFO] | | +- org.slf4j:jcl-over-slf4j:jar:1.7.24:compile 
[INFO] | | \- org.eclipse.jetty:jetty-util:jar:9.4.2.v20170220:compile 
[INFO] | +- io.dropwizard:dropwizard-metrics:jar:1.1.0:compile 
[INFO] | +- io.dropwizard:dropwizard-jersey:jar:1.1.0:compile 
[INFO] | | +- org.glassfish.jersey.core:jersey-server:jar:2.25.1:compile 
[INFO] | | | +- org.glassfish.jersey.core:jersey-common:jar:2.25.1:compile 
[INFO] | | | | +- org.glassfish.jersey.bundles.repackaged:jersey-guava:jar:2.25.1:compile 
[INFO] | | | | \- org.glassfish.hk2:osgi-resource-locator:jar:1.0.1:compile 
[INFO] | | | +- org.glassfish.jersey.core:jersey-client:jar:2.25.1:compile 
[INFO] | | | +- org.glassfish.jersey.media:jersey-media-jaxb:jar:2.25.1:compile 
[INFO] | | | +- javax.annotation:javax.annotation-api:jar:1.2:compile 
[INFO] | | | +- org.glassfish.hk2:hk2-api:jar:2.5.0-b32:compile 
[INFO] | | | | +- org.glassfish.hk2:hk2-utils:jar:2.5.0-b32:compile 
[INFO] | | | | \- org.glassfish.hk2.external:aopalliance-repackaged:jar:2.5.0-b32:compile 
[INFO] | | | +- org.glassfish.hk2.external:javax.inject:jar:2.5.0-b32:compile 
[INFO] | | | \- org.glassfish.hk2:hk2-locator:jar:2.5.0-b32:compile 
[INFO] | | |  \- org.javassist:javassist:jar:3.20.0-GA:compile 
[INFO] | | +- org.glassfish.jersey.ext:jersey-metainf-services:jar:2.25.1:compile 
[INFO] | | +- org.glassfish.jersey.ext:jersey-bean-validation:jar:2.25.1:compile 
[INFO] | | | +- javax.el:javax.el-api:jar:2.2.4:compile 
[INFO] | | | \- org.glassfish.web:javax.el:jar:2.2.4:compile 
[INFO] | | +- io.dropwizard.metrics:metrics-jersey2:jar:3.2.2:compile 
[INFO] | | +- com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:jar:2.8.7:compile 
[INFO] | | | +- com.fasterxml.jackson.jaxrs:jackson-jaxrs-base:jar:2.8.7:compile 
[INFO] | | | \- com.fasterxml.jackson.module:jackson-module-jaxb-annotations:jar:2.8.7:compile 
[INFO] | | +- org.glassfish.jersey.containers:jersey-container-servlet:jar:2.25.1:compile 
[INFO] | | | \- org.glassfish.jersey.containers:jersey-container-servlet-core:jar:2.25.1:compile 
[INFO] | | +- org.eclipse.jetty:jetty-server:jar:9.4.2.v20170220:compile 
[INFO] | | | +- javax.servlet:javax.servlet-api:jar:3.1.0:compile 
[INFO] | | | \- org.eclipse.jetty:jetty-io:jar:9.4.2.v20170220:compile 
[INFO] | | +- org.eclipse.jetty:jetty-webapp:jar:9.4.2.v20170220:compile 
[INFO] | | | \- org.eclipse.jetty:jetty-xml:jar:9.4.2.v20170220:compile 
[INFO] | | \- org.eclipse.jetty:jetty-continuation:jar:9.4.2.v20170220:compile 
[INFO] | +- io.dropwizard:dropwizard-servlets:jar:1.1.0:compile 
[INFO] | | \- io.dropwizard.metrics:metrics-annotation:jar:3.2.2:compile 
[INFO] | +- io.dropwizard:dropwizard-jetty:jar:1.1.0:compile 
[INFO] | | +- io.dropwizard.metrics:metrics-jetty9:jar:3.2.2:compile 
[INFO] | | +- org.eclipse.jetty:jetty-servlet:jar:9.4.2.v20170220:compile 
[INFO] | | | \- org.eclipse.jetty:jetty-security:jar:9.4.2.v20170220:compile 
[INFO] | | +- org.eclipse.jetty:jetty-servlets:jar:9.4.2.v20170220:compile 
[INFO] | | \- org.eclipse.jetty:jetty-http:jar:9.4.2.v20170220:compile 
[INFO] | +- io.dropwizard:dropwizard-lifecycle:jar:1.1.0:compile 
[INFO] | +- io.dropwizard.metrics:metrics-core:jar:3.2.2:compile 
[INFO] | +- io.dropwizard.metrics:metrics-jvm:jar:3.2.2:compile 
[INFO] | +- io.dropwizard.metrics:metrics-servlets:jar:3.2.2:compile 
[INFO] | | +- io.dropwizard.metrics:metrics-json:jar:3.2.2:compile 
[INFO] | | \- com.papertrail:profiler:jar:1.0.2:compile 
[INFO] | +- io.dropwizard.metrics:metrics-healthchecks:jar:3.2.2:compile 
[INFO] | +- io.dropwizard:dropwizard-request-logging:jar:1.1.0:compile 
[INFO] | | \- ch.qos.logback:logback-access:jar:1.2.1:compile 
[INFO] | +- net.sourceforge.argparse4j:argparse4j:jar:0.7.0:compile 
[INFO] | \- org.eclipse.jetty.toolchain.setuid:jetty-setuid-java:jar:1.0.3:compile 
[INFO] +- io.federecio:dropwizard-swagger:jar:0.7.0:compile 
[INFO] | +- io.dropwizard:dropwizard-assets:jar:0.8.0:compile 
[INFO] | +- io.dropwizard:dropwizard-views:jar:0.8.0:compile 
[INFO] | +- io.dropwizard:dropwizard-views-freemarker:jar:0.8.0:compile 
[INFO] | | \- org.freemarker:freemarker:jar:2.3.21:compile 
[INFO] | +- com.wordnik:swagger-jersey2-jaxrs:jar:1.5.1-M2:compile 
[INFO] | | \- com.wordnik:swagger-jaxrs:jar:1.5.1-M2:compile 
[INFO] | |  +- com.fasterxml.jackson.dataformat:jackson-dataformat-xml:jar:2.4.2:compile 
[INFO] | |  | \- org.codehaus.woodstox:stax2-api:jar:3.1.4:compile 
[INFO] | |  +- com.wordnik:swagger-core:jar:1.5.1-M2:compile 
[INFO] | |  | \- com.wordnik:swagger-models:jar:1.5.1-M2:compile 
[INFO] | |  |  \- com.wordnik:swagger-annotations:jar:1.5.1-M2:compile 
[INFO] | |  \- org.reflections:reflections:jar:0.9.9:compile 
[INFO] | |  \- com.google.code.findbugs:annotations:jar:2.0.1:compile 
[INFO] | \- xml-apis:xml-apis:jar:1.4.01:compile 
[INFO] +- com.google.inject:guice:jar:4.1.0:compile 
[INFO] | +- javax.inject:javax.inject:jar:1:compile 
[INFO] | +- aopalliance:aopalliance:jar:1.0:compile 
[INFO] | \- com.google.guava:guava:jar:19.0:compile 
[INFO] +- org.apache.httpcomponents:httpclient:jar:4.5.3:compile 
[INFO] | +- org.apache.httpcomponents:httpcore:jar:4.4.6:compile 
[INFO] | +- commons-logging:commons-logging:jar:1.2:compile 
[INFO] | \- commons-codec:commons-codec:jar:1.9:compile 
[INFO] +- javax.ws.rs:javax.ws.rs-api:jar:2.0.1:compile 
[INFO] \- org.junit.jupiter:junit-jupiter-api:jar:5.0.0-M4:test 
[INFO] +- org.opentest4j:opentest4j:jar:1.0.0-M2:test 
[INFO] \- org.junit.platform:junit-platform-commons:jar:1.0.0-M4:test 

只是想知道,如何Dropwizard配置MetricRegistry?


進一步瞭解詳情(如果需要): -

我使用的吉斯注入到MetricRegistry綁定延長AbstractModule作爲

bind(MetricRegistry.class).toInstance(environment.metrics()); 

,並在服務類調用此模塊中注射器爲

public static void main(String[] args) throws Exception { 
    new Service().run(args); 
} 

@Override 
public void run(ServiceConfig config, Environment environment) throws Exception { 
    Injector injector = Guice.createInjector(new ExtendingModule(config, environment)); 
    .... // not altering metrics here 
} 

回答

1

DW只是創建一個度量註冊表,沒有魔法或沒有涉及。看看它的Bootstrap類:

public Bootstrap(Application<T> application) { 
    this.application = application; 
    this.objectMapper = Jackson.newObjectMapper(); 
    this.bundles = new ArrayList<>(); 
    this.configuredBundles = new ArrayList<>(); 
    this.commands = new ArrayList<>(); 
    this.validatorFactory = Validators.newValidatorFactory(); 
    this.metricRegistry = new MetricRegistry(); 
    this.configurationSourceProvider = new FileConfigurationSourceProvider(); 
    this.classLoader = Thread.currentThread().getContextClassLoader(); 
    this.configurationFactoryFactory = new DefaultConfigurationFactoryFactory<>(); 
    this.healthCheckRegistry = new HealthCheckRegistry(); 
} 
特別

this.metricRegistry = new MetricRegistry(); 

這幾乎是它。

忘記,他們還註冊了一些標準模塊:

/** 
    * Registers the JVM metrics to the metric registry and start to report 
    * the registry metrics via JMX. 
    */ 
    public void registerMetrics() { 
     if (metricsAreRegistered) { 
      return; 
     } 
     getMetricRegistry().register("jvm.attribute", new JvmAttributeGaugeSet()); 
     getMetricRegistry().register("jvm.buffers", new BufferPoolMetricSet(ManagementFactory 
                       .getPlatformMBeanServer())); 
     getMetricRegistry().register("jvm.classloader", new ClassLoadingGaugeSet()); 
     getMetricRegistry().register("jvm.filedescriptor", new FileDescriptorRatioGauge()); 
     getMetricRegistry().register("jvm.gc", new GarbageCollectorMetricSet()); 
     getMetricRegistry().register("jvm.memory", new MemoryUsageGaugeSet()); 
     getMetricRegistry().register("jvm.threads", new ThreadStatesGaugeSet()); 

     JmxReporter.forRegistry(metricRegistry).build().start(); 
     metricsAreRegistered = true; 
    } 

版本是不依賴於你使用的是公制庫版本,但與ObjectMapper系列化註冊的MetricsModule。在我的情況下,類看起來像這樣:

public class MetricsModule extends Module { 
    static final Version VERSION = new Version(3, 0, 0, "", "com.codahale.metrics", "metrics-json"); 

在串行器,第一行,做:

@Override 
     public void serialize(MetricRegistry registry, 
           JsonGenerator json, 
           SerializerProvider provider) throws IOException { 
      json.writeStartObject(); 
      json.writeStringField("version", VERSION.toString()); 

這是你的版本是從。

不可否認,這不是很直觀。我認爲這是更多的內部版本控制,只要特定序列化模塊中的代碼發生變化,它就會得到更新 - 但是您必須向DW人員詢問相關細節。我的指標是3.1.2或類似的東西,它爲我打印3.0.0。

- Artur

+0

什麼可能是jar和api響應中列出的版本衝突的原因? – nullpointer

+0

@nullpointer版本在用於序列化的MetricsModule中進行硬編碼。這不代表您使用的庫,而是代表用於序列化的內部模塊的版本。 – pandaadb

+0

@nullpointer我更新了我的答案 – pandaadb