From 755c48f80d45a3fbd5557e8e856f24f496512de6 Mon Sep 17 00:00:00 2001 From: Jesse Morgan Date: Sat, 4 Oct 2014 12:10:19 -0700 Subject: Adding metrics. --- src/com/p4square/grow/GrowProcessComponent.java | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'src/com/p4square/grow/GrowProcessComponent.java') diff --git a/src/com/p4square/grow/GrowProcessComponent.java b/src/com/p4square/grow/GrowProcessComponent.java index 791f177..f63538c 100644 --- a/src/com/p4square/grow/GrowProcessComponent.java +++ b/src/com/p4square/grow/GrowProcessComponent.java @@ -6,6 +6,10 @@ package com.p4square.grow; import java.io.File; import java.io.IOException; +import java.util.concurrent.TimeUnit; + +import com.codahale.metrics.ConsoleReporter; +import com.codahale.metrics.MetricRegistry; import org.apache.log4j.Logger; @@ -21,6 +25,7 @@ import com.p4square.grow.backend.BackendVerifier; import com.p4square.grow.backend.GrowBackend; import com.p4square.grow.config.Config; import com.p4square.grow.frontend.GrowFrontend; +import com.p4square.restlet.metrics.MetricsApplication; /** * @@ -32,6 +37,7 @@ public class GrowProcessComponent extends Component { private static final String BACKEND_REALM = "Grow Backend"; private final Config mConfig; + private final MetricRegistry mMetricRegistry; /** * Create a new Grow Process website component combining a frontend and backend. @@ -50,12 +56,15 @@ public class GrowProcessComponent extends Component { mConfig = config; mConfig.updateConfig(this.getClass().getResourceAsStream("/grow.properties")); + // Prepare Metrics + mMetricRegistry = new MetricRegistry(); + // Frontend - GrowFrontend frontend = new GrowFrontend(mConfig); + GrowFrontend frontend = new GrowFrontend(mConfig, mMetricRegistry); getDefaultHost().attach(frontend); // Backend - GrowBackend backend = new GrowBackend(mConfig); + GrowBackend backend = new GrowBackend(mConfig, mMetricRegistry); getInternalRouter().attach("/backend", backend); // Authenticated access to the backend @@ -64,6 +73,13 @@ public class GrowProcessComponent extends Component { false, ChallengeScheme.HTTP_BASIC, BACKEND_REALM, verifier); auth.setNext(backend); getDefaultHost().attach("/backend", auth); + + // Authenticated access to metrics + ChallengeAuthenticator metricAuth = new ChallengeAuthenticator( + getContext().createChildContext(), false, + ChallengeScheme.HTTP_BASIC, BACKEND_REALM, verifier); + metricAuth.setNext(new MetricsApplication(mMetricRegistry)); + getDefaultHost().attach("/metrics", metricAuth); } -- cgit v1.2.3