/label-supported-dropwizard-metrics

Provides an object name factory for Dropwizard that adds the support for metric labels.

Primary LanguageJavaApache License 2.0Apache-2.0

Label supported JMX metrics

Provides an object name factory for Dropwizard that adds the support for metric labels. Labels are of great value for example on aggregating metrics by Prometheus.

Sample Usage

The client code for referring to a labeled metric is like this:

metricRegistry.counter(LabeledMetric.name("num_records").label("device_id", "1312").toString())
              .mark();

And if you have a metric with no label, you can call metric registry in its normal way:

 metricRegistry.counter("num_records").mark();

But note that to make it work, you should also introduce the LabelSupportedObjectNameFactory (provided by this library) when starting the JMX reporter:

JmxReporter.forRegistry(metricRegistry)
           .createsObjectNamesWith(new LabelSupportedObjectNameFactory())
           .inDomain("my-metrics-domain")
           .build().start();

Add it to your project

You can reference to this library by either of java build systems (Maven, Gradle, SBT or Leiningen) using snippets from this jitpack link: