Search code examples
javadropwizardcodahale-metrics

Reading metrics configuration from YAML file within a dropwizard REST application


My Metrics configuration goes like this in my dropwizard rest application, (hello-world.yml)

metrics:
  reporters:
    - type: log
      logger: metrics
      markerName: <marker name>

This one is a SLF4J Reporter I have places this in my YAML config file. Now that when I want to fetch this value and use it in my Application file. The only option i see is to read this as Map<String, List<Map<String, String>> metrics; What is the correct way to read this configuration and use it in the dropwizard Application class. Please help me out.

This issue is same as Dropwizard Yaml for graphite server configuration. But again no answer to that question hence trying my luck by creating a new question.


Solution

  • I posted this question in dropwizard user and got the answer. https://groups.google.com/forum/#!topic/dropwizard-user/yxceCS1CEns

     final ImmutableList<ReporterFactory> reporters = configuration.getMetricsFactory().getReporters();
            final Slf4jReporterFactory slf4jReporterFactory = (Slf4jReporterFactory) reporters.get(0);
            slf4jReporterFactory.getMarkerName();
            slf4jReporterFactory.getLoggerName();