Not getting any data when using metrics annotations

4,553 views
Skip to first unread message

Laurent

unread,
Feb 12, 2013, 12:52:59 PM2/12/13
to metric...@googlegroups.com

Hello,

I can use the Metrics timers and meters successfully (e.g. Metrics.newTimer(...) ).

However, I have no luck when using the metric annotations: no data gets reported to graphite and my console and jmx data remain equal to zero.

My spring context file has simply:

    <metrics:annotation-driven />

The relevant part of my class is:

import com.yammer.metrics.annotation.ExceptionMetered;
import com.yammer.metrics.annotation.Metered;
import com.yammer.metrics.annotation.Timed;

...

@Component
public class GetSessionServlet extends HttpServlet {

  private final static Logger log = LoggerFactory.getLogger(GetSessionServlet.class);


  @Override
  public void init(final ServletConfig config) throws ServletException {
    super.init(config);
    SpringBeanAutowiringSupport.processInjectionBasedOnServletContext(
            this, config.getServletContext());
ConsoleReporter.enable(1, TimeUnit.MINUTES);
GraphiteReporter.enable(1, TimeUnit.MINUTES, "<my host here>", 2003);
 } @Override
@Metered @Timed(name = "get-session", rateUnit = TimeUnit.MILLISECONDS) @ExceptionMetered(name = "get-session-failures", rateUnit = TimeUnit.MILLISECONDS) public void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { final String sessionId = req.getParameter("sessionId"); final String fields = req.getParameter("fields"); final String format = req.getParameter("format"); if (StringUtils.isEmpty(sessionId)) { resp.getWriter().write("sessionId parameter missing!\n"); return; }

... }

(I also tried @Timed instead of @Timed(name = "get-session", rateUnit = TimeUnit.MILLISECONDS) with no more luck.)

I run my app locally with mvn clean tomcat7:run.

My console output keeps showing:

my.package.name.GetSessionServlet:
  doGet:
             count = 0
         mean rate = 0.00 calls/s
     1-minute rate = 0.00 calls/s
     5-minute rate = 0.00 calls/s
    15-minute rate = 0.00 calls/s
               min = 0.00ms
               max = 0.00ms
              mean = 0.00ms
            stddev = 0.00ms
            median = 0.00ms
              75% <= 0.00ms
              95% <= 0.00ms
              98% <= 0.00ms
              99% <= 0.00ms
            99.9% <= 0.00ms

When using jconsole, in the MBeans tab, I can see an entry with the package name of my GetSessionServlet class with three subfolders doGet (for the @Metered numbers), get-session, and get-session-failures.

However, no matter how many times I call my servlet, all the values in the subfolders above remain at zero.

1. What am I missing?
2. Also, any documentation on these metered metrics that goes into more details than the official documentation will be greatly appreciated.

Matt Brown

unread,
Feb 12, 2013, 3:17:09 PM2/12/13
to metric...@googlegroups.com
See the note at the bottom of https://github.com/ryantenney/metrics-spring - Spring cannot intercept an annotated method when that method is called from within the class itself. 

I believe that with a HttpServlet, the servlet container is calling GenericServlet.service(), which in turn calls HttpServlet.service(), which inspects the HTTP method and delegates to the appropriate doXXX() method.

Spring AOP can only intercept method calls where the annotated (public) method is invoked by another object, since the way it works is that Spring gives the other object a proxy to the instance containing the annotation. 

Laurent

unread,
Feb 13, 2013, 9:43:20 AM2/13/13
to metric...@googlegroups.com
Thanks a lot Matt. I did see that comment but had not realized this would apply to my situation. Is there an elegant way to get around that limitation when one needs to time get and post methods short of creating an annotated method in another class that my get servlet method would invoke?

Laurent

Laurent

unread,
Feb 18, 2013, 12:49:05 PM2/18/13
to metric...@googlegroups.com
I created another class with a time() method that I call from my servlet and I still see all my numbers remaining at zero, whether I use the annotation @Timed or @Metered. (Somehow using both in this class generates an exception at deploy time: "Initialization of bean failed; nested exception is java.lang.ClassCastException: com.yammer.metrics.core.Meter cannot be cast to com.yammer.metrics.core.Timer").

Why am I still getting numbers that remain at zero now that clearly I am using an annotated method that isn't called from anywhere else in the class?



import org.springframework.stereotype.Component;

import com.yammer.metrics.annotation.Metered;

@Component
public class Delay {

  @Metered
  public void time() {
    System.out.println("Timing...");
    try {
      Thread.sleep(1000);
    } catch (final InterruptedException e) {
      e.printStackTrace();

    }
  }


}

On Tuesday, February 12, 2013 3:17:09 PM UTC-5, Matt Brown wrote:

Rahul Agarwal

unread,
Oct 24, 2014, 6:48:03 PM10/24/14
to metric...@googlegroups.com
Did you find any solution for this?

Thanks

vinit.sr...@globallogic.com

unread,
Apr 3, 2017, 5:35:07 AM4/3/17
to metrics-user

vinit.sr...@globallogic.com

unread,
Apr 3, 2017, 5:36:11 AM4/3/17
to metrics-user
i am also facing same type of issue please suggest any solution.  

vinit.sr...@globallogic.com

unread,
Apr 3, 2017, 8:21:25 AM4/3/17
to metrics-user

singh....@gmail.com

unread,
Mar 25, 2018, 10:55:25 PM3/25/18
to metrics-user
Hi,

Any update on this ?

Thanks,
Priyanka
Reply all
Reply to author
Forward
0 new messages