3

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.

Lolo
  • 3,935
  • 5
  • 40
  • 50
  • Try searching for a different library. Spring JMX is not always easy to work with – Asaf Mesika Nov 28 '15 at 11:37
  • See follow up question that did find a charitable soul able to help me out: http://stackoverflow.com/questions/14816029 – Lolo Dec 01 '15 at 15:44

1 Answers1

-1

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

GUEST
  • 1