Unable to see metrics captured with spring metrics annotations

≡放荡痞女 提交于 2019-12-21 20:26:18

问题


How can I do the equivalent of:

  @Override
  public void init(final ServletConfig config) throws ServletException {
    super.init(config);
    CsvReporter.enable(new File("/tmp/measurements"), 1, TimeUnit.MINUTES);
    GraphiteReporter.enable(1, TimeUnit.MINUTES, "my.host.name", 2003);
  }

  @Override
  protected void doGet(final HttpServletRequest req,
          final HttpServletResponse resp) throws ServletException,
          IOException {
    final TimerContext timerContext = Metrics.newMeter(CreateSessionServlet.class,"myservlet-meter", "requests", TimeUnit.SECONDS).time();
    try {
...
  } finally {
      timerContext.stop();
    }

with spring annotations and codahale metrics as mentioned here?

I thought it would be as simple as:

-annotating my servlet like this (I will need gauges and metering eventually):

@Timed
@Gauge
@Metered
@Override
protected void doGet(final HttpServletRequest req,
        final HttpServletResponse resp) throws ServletException, IOException {

-and updating my spring-servlet to enable the spring annotations as explained on the page mentioned above.

But when I use jconsole, I do not see in the MBeans section any additional entry for that servlet that I instrumented than for other servlets that do not use any annotation

So my two questions:

  1. Is there anything I am missing so that my web app actually sends metric data via JMX?

  2. If I want the code with spring annotations to start reporting to a CSV file or to graphite, what do I need to add?

Surprisingly I found no complete examples on the web or in the doc from codahale on this.


回答1:


Unfortunately metrics only is based on AOP so that it could be used only for public method



来源:https://stackoverflow.com/questions/14739159/unable-to-see-metrics-captured-with-spring-metrics-annotations

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!