I am using custom timers to instrument a ton of fields via Micrometer. Ideally I do not want the metrics reported for this specific meter that have a count of zero between the configured step interval. This is not crucial but would love to potentially reduce noise of what is getting sent to NR every x seconds.
I've created an extension off NewRelicMeterRegistry that overrides the publish()
method to add the functionality before the default behavior.
public class FilteringNewRelicMeterRegistry extends NewRelicMeterRegistry {
public FilteringNewRelicMeterRegistry(NewRelicConfig config, Clock clock) {
super(config, clock);
}
/**
* Remove field metrics that have not been used since the last publish.
*/
@Override
protected void publish() {
getMeters().stream()
.filter(filterByMeterId(...)))
.filter(meter -> ((Timer) meter).count() == 0)
.forEach(this::remove);
super.publish();
}
}
But for the life of me, I can't figure out how to get the AutoConfiguration to prefer this implementation over the default NewRelicMeterRegistry
.
How do I get spring-boot or micrometer to honor my implementation and use that as the designated bean in the application context for autowiring purposes?
Also if there is an out of the box way to override this behavior via micrometer abstractions or utility, awesome that would be even better! Please let me know. I've tried using MeterRegistryCustomizer
but that didn't seem to have what I needed.
I want to avoid using Spring's scheduling functionality via @Scheduled
, would like to do this on an "on publish" basis.