简体   繁体   中英

Spring 4 + Jersey 2 + Metrics

I'm trying to use Coda Hale's Metrics framework to time methods in my application. I've configured the InstrumentedResourceMethodApplicationListener to integrate Metrics with Jersey 2, but now I'd like my Spring injected services and repositories to also be timed. I know there's a metrics-spring integration but it looks like I would end up having separate MetricRegistry instances for Spring and Jersey. Has anyone been able to configure a single registry for both: the Jersey 2 resources and the Spring injected beans?

If you configure Jersey to use Spring you will be able to use metrics-spring for instrumenting spring beans. This should enable you define the InstrumentedResourceMethodApplicationListener using a constructor argument to inject the Spring configured metrics repository:

<bean id="metricsListener" class="com.codahale.metrics.jersey2.InstrumentedResourceMethodApplicationListener">
  <constructor-arg ref="metricsRegistry" />
</bean>

You may also want to configure the MetricsServlet .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM