Each of the main types of Metrics (Gauges, Counters, Histograms, Meters, Timers) have all available data (percentiles, min, max, etc. as applicable) reported as "custom metrics" in New Relic.
To upload all metrics in your
MetricRegistry with all available data (not filtering at all), this will do:
NewRelicReporter reporter = NewRelicReporter.forRegistry(registry) .name("new relic reporter") .filter(MetricFilter.ALL) .attributeFilter(new AllEnabledMetricAttributeFilter()) .rateUnit(TimeUnit.SECONDS) .durationUnit(TimeUnit.MILLISECONDS) .metricNamePrefix("foo/") .build(); reporter.start(1, TimeUnit.MINUTES);
This will report all attributes of all metrics to New Relic using seconds as the rate unit and milliseconds as the duration unit. Data will be reported via the New Relic Java API once a minute.
Custom metrics in New Relic
As an example, a Histogram would have the following custom metrics recorded:
A Timer would have the above attributes as well as the various calculated rates, like:
In this case, the trailing
second means that the rate unit is set to seconds.
You can then proceed to use those metrics in New Relic custom dashboards.
You can also specify a non-empty metric name prefix if you wish to further segregate your various metrics. With a prefix of
foo/, your metrics would appear as
Custom/foo/metricName/max, for instance.
Limiting what's reported to New Relic
According to New Relic's custom metric best practices, they want to keep the number of custom metrics under 2000 or so. Since each Timer might generate a dozen custom metrics in New Relic, it's pretty easy to hit this limit.
There are two ways you can keep the number of custom metrics under control. To choose which specific metrics to report on, use a MetricFilter. If you want to report on all metrics, use
MetricFilter.ALL; otherwise, provide your own implementation of
To limit which attributes of each metric will be reported to New Relic, MetricAttributeFilter has boolean methods for every attribute, such as
boolean recordTimerMedian(String name, Timer metric). All such methods will be passed the metric name and the metric object itself for arbitration on whether or not the relevant attribute will be reported. For convenient implementation of both whitelist and blacklist approaches, AllEnabledMetricAttributeFilter, AllDisabledMetricAttributeFilter and AllDisabledMetricAttributeFilter are provided.