package io.haptava.examples.heroku.servlets;

import com.codahale.metrics.MetricRegistry;
import com.google.common.net.HttpHeaders;
import com.sudothought.http.HttpConstants;
import com.sudothought.util.IoUtils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;

public class HtmlPage
    extends ServletWithMetrics {

  private final String filename;

  public HtmlPage(final MetricRegistry metricRegistry, final String metricName, final String filename) {
    super(metricRegistry, metricName);
    this.filename = filename;
  }

  @Override
  protected void doGet(final HttpServletRequest request, final HttpServletResponse response) {

    response.setContentType(HttpConstants.HTML_CONTENT);
    response.setHeader(HttpHeaders.CACHE_CONTROL, HttpConstants.NO_CACHE);
    response.setStatus(HttpServletResponse.SC_OK);

    try {
      PrintWriter writer = response.getWriter();
      final String file = IoUtils.readFile(this.filename);
      writer.print(file);
      writer.close();
    }
    catch (final Exception e) {
      e.printStackTrace();
    }
  }
}

@@ -83,16 +83,57 @@
 gistry;%0A
+import com.google.common.base.Stopwatch;%0A
 import c
@@ -746,16 +746,69 @@
 nse) %7B%0A%0A
+    final Stopwatch sw = Stopwatch.createStarted();%0A%0A
     resp
@@ -1219,15 +1219,42 @@
 );%0A    %7D
+%0A%0A    this.markMetrics(sw);
 %0A  %7D%0A%7D%0A

Add metrics to HtmlPage