Domanda

I have a simple Controller to which I've added some codahale metrics. All I need is to use a Meter to show the requests per second. I currently have this, which works:

private static final MetricRegistry REGISTRY = new MetricRegistry();
private static final Meter METER = REGISTRY.meter(MetricRegistry.name(DCSEmailTracker.class, "get-requests"));
private static final JmxReporter REPORTER = JmxReporter.forRegistry(REGISTRY).build();

I then use METER.mark() inside the method that serves the GET requests.

I now need to use Spring injection instead of static fields. I've checked http://www.ryantenney.com/metrics-spring/ but was not able to get it to work.

Would anyone be able to help on how to use annotations to achieve the same functionality?

È stato utile?

Soluzione 2

Extend MetricsConfigurerAdapter in a class annotated with @EnableMetrics and override configureReporters:

@Override
public void configureReporters(MetricRegistry metricRegistry) {
    JmxReporter.forRegistry(metricRegistry).build().start();
}

Then annotate the metered method with @Metered.

Altri suggerimenti

If you want check sample project which report all metrics data in console.

https://github.com/kailapiyush/Metrics-POC/releases/tag/0.1

Configuration using annotation (also XML file available you want to use XML Configuration remove comment)

//Metrics Data retrieve using following annotations
    @Timed, 
    @Metered 
    @Counted
    @ExceptionMetered
    @RequestMapping

This is Maven Project. You can Test it After Just Import it. not any other configuration required.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top