无法解析config.yml中的DropWizard Graphite Metrics Reporter

L. *_*ker 2 graphite dropwizard codahale-metrics

我尝试在config.yml文件中配置我的dropwizard graphite metrics报告器:

metrics:
  reporters:
     - type: graphite
       host: my.graphite.host.com
       port: 2003
       prefix: my.prefix
Run Code Online (Sandbox Code Playgroud)

我的pom.xml中有dropwizard-metrics和metrics-graphite作为依赖项.我的Application类或Configuration类中没有关于记者的任何内容.我的印象是DropWizard负责MetricRegistry和记者的所有初始化和启动.然而,当我运行我的应用程序时,我收到以下错误:

config.yml has an error:

  * Failed to parse configuration at: metrics.reporters; 
Could not resolve type id 'graphite' into a subtype of [simple type, 
class io.dropwizard.metrics.ReporterFactory]: 
known type ids = [ReporterFactory, console, csv, log] 
at [Source: N/A; line: -1, column: -1] 
(through reference chain: com.example.MyConfiguration["metrics"]-  
>io.dropwizard.metrics.MetricsFactory["reporters"])
Run Code Online (Sandbox Code Playgroud)

为什么'石墨'没有被接受为可接受的类型?我错过了什么?

小智 5

我相信你有答案 - 但我有同样的问题,所以想详细说明.您需要三个库,这些库在文档中并不清楚.

    <dependency>
        <groupId>io.dropwizard.metrics</groupId>
        <artifactId>metrics-core</artifactId>
        <version>${metrics.version}</version>
    </dependency>
    <dependency>
        <groupId>io.dropwizard</groupId>
        <artifactId>dropwizard-metrics-graphite</artifactId>
        <version>${dw.version}</version>
    </dependency>
    <dependency>
        <groupId>io.dropwizard.metrics</groupId>
        <artifactId>metrics-graphite</artifactId>
        <version>${metrics.version}</version>
    </dependency>
Run Code Online (Sandbox Code Playgroud)