Updated Branches: refs/heads/flume-1.4 eb46fe93a -> 33d44248c
FLUME-2076. JMX metrics support for HTTP Source. (Sravya Tirukkovalur via Mike Percy) Project: http://git-wip-us.apache.org/repos/asf/flume/repo Commit: http://git-wip-us.apache.org/repos/asf/flume/commit/33d44248 Tree: http://git-wip-us.apache.org/repos/asf/flume/tree/33d44248 Diff: http://git-wip-us.apache.org/repos/asf/flume/diff/33d44248 Branch: refs/heads/flume-1.4 Commit: 33d44248c9c7fa2fa61a972924721ff6ffe2c75e Parents: eb46fe9 Author: Mike Percy <[email protected]> Authored: Sun Jun 23 13:35:05 2013 -0700 Committer: Mike Percy <[email protected]> Committed: Sun Jun 23 13:36:50 2013 -0700 ---------------------------------------------------------------------- .../java/org/apache/flume/source/http/HTTPSource.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flume/blob/33d44248/flume-ng-core/src/main/java/org/apache/flume/source/http/HTTPSource.java ---------------------------------------------------------------------- diff --git a/flume-ng-core/src/main/java/org/apache/flume/source/http/HTTPSource.java b/flume-ng-core/src/main/java/org/apache/flume/source/http/HTTPSource.java index a4c3eb3..c90f067 100644 --- a/flume-ng-core/src/main/java/org/apache/flume/source/http/HTTPSource.java +++ b/flume-ng-core/src/main/java/org/apache/flume/source/http/HTTPSource.java @@ -24,6 +24,7 @@ import org.apache.flume.Context; import org.apache.flume.Event; import org.apache.flume.EventDrivenSource; import org.apache.flume.conf.Configurable; +import org.apache.flume.instrumentation.SourceCounter; import org.apache.flume.source.AbstractSource; import org.mortbay.jetty.Connector; import org.mortbay.jetty.Server; @@ -52,7 +53,7 @@ import java.util.Map; * the server should bind. Mandatory <p> <tt>handler</tt>: the class that * deserializes a HttpServletRequest into a list of flume events. This class * must implement HTTPSourceHandler. Default: - * {@linkplain JSONDeserializer}. <p> <tt>handler.*</tt> Any configuration + * {@linkplain JSONHandler}. <p> <tt>handler.*</tt> Any configuration * to be passed to the handler. <p> * * All events deserialized from one Http request are committed to the channel in @@ -85,6 +86,7 @@ public class HTTPSource extends AbstractSource implements private volatile Server srv; private volatile String host; private HTTPSourceHandler handler; + private SourceCounter sourceCounter; @Override public void configure(Context context) { @@ -118,6 +120,9 @@ public class HTTPSource extends AbstractSource implements LOG.error("Error configuring HTTPSource!", ex); Throwables.propagate(ex); } + if (sourceCounter == null) { + sourceCounter = new SourceCounter(getName()); + } } private void checkHostAndPort() { @@ -150,6 +155,7 @@ public class HTTPSource extends AbstractSource implements Throwables.propagate(ex); } Preconditions.checkArgument(srv.isRunning()); + sourceCounter.start(); super.start(); } @@ -162,6 +168,8 @@ public class HTTPSource extends AbstractSource implements } catch (Exception ex) { LOG.error("Error while stopping HTTPSource. Exception follows.", ex); } + sourceCounter.stop(); + LOG.info("Http source {} stopped. Metrics: {}", getName(), sourceCounter); } private class FlumeHTTPServlet extends HttpServlet { @@ -187,6 +195,8 @@ public class HTTPSource extends AbstractSource implements + ex.getMessage()); return; } + sourceCounter.incrementAppendBatchReceivedCount(); + sourceCounter.addToEventReceivedCount(events.size()); try { getChannelProcessor().processEventBatch(events); } catch (ChannelException ex) { @@ -207,6 +217,8 @@ public class HTTPSource extends AbstractSource implements response.setCharacterEncoding(request.getCharacterEncoding()); response.setStatus(HttpServletResponse.SC_OK); response.flushBuffer(); + sourceCounter.incrementAppendBatchAcceptedCount(); + sourceCounter.addToEventAcceptedCount(events.size()); } @Override
