diff options
Diffstat (limited to 'src/com/p4square/grow')
-rw-r--r-- | src/com/p4square/grow/GrowProcessComponent.java | 20 | ||||
-rw-r--r-- | src/com/p4square/grow/backend/GrowBackend.java | 18 | ||||
-rw-r--r-- | src/com/p4square/grow/frontend/GrowFrontend.java | 21 |
3 files changed, 49 insertions, 10 deletions
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); } diff --git a/src/com/p4square/grow/backend/GrowBackend.java b/src/com/p4square/grow/backend/GrowBackend.java index e73ad38..4091138 100644 --- a/src/com/p4square/grow/backend/GrowBackend.java +++ b/src/com/p4square/grow/backend/GrowBackend.java @@ -6,6 +6,8 @@ package com.p4square.grow.backend; import java.io.IOException; +import com.codahale.metrics.MetricRegistry; + import org.apache.log4j.Logger; import org.restlet.Application; @@ -42,6 +44,8 @@ import com.p4square.grow.backend.feed.FeedDataProvider; import com.p4square.grow.backend.feed.ThreadResource; import com.p4square.grow.backend.feed.TopicResource; +import com.p4square.restlet.metrics.MetricRouter; + /** * Main class for the backend application. * @@ -51,22 +55,30 @@ public class GrowBackend extends Application implements GrowData { private final static Logger LOG = Logger.getLogger(GrowBackend.class); + private final MetricRegistry mMetricRegistry; + private final Config mConfig; private final GrowData mGrowData; public GrowBackend() { - this(new Config()); + this(new Config(), new MetricRegistry()); } - public GrowBackend(Config config) { + public GrowBackend(Config config, MetricRegistry metricRegistry) { mConfig = config; + mMetricRegistry = metricRegistry; + mGrowData = new DynamoGrowData(config); } + public MetricRegistry getMetrics() { + return mMetricRegistry; + } + @Override public Restlet createInboundRoot() { - Router router = new Router(getContext()); + Router router = new MetricRouter(getContext(), mMetricRegistry); // Account API router.attach("/accounts/{userId}", AccountResource.class); diff --git a/src/com/p4square/grow/frontend/GrowFrontend.java b/src/com/p4square/grow/frontend/GrowFrontend.java index 926670b..37d4984 100644 --- a/src/com/p4square/grow/frontend/GrowFrontend.java +++ b/src/com/p4square/grow/frontend/GrowFrontend.java @@ -23,6 +23,8 @@ import org.restlet.routing.Redirector; import org.restlet.routing.Router; import org.restlet.security.Authenticator; +import com.codahale.metrics.MetricRegistry; + import org.apache.log4j.Logger; import com.p4square.fmfacade.FMFacade; @@ -33,6 +35,8 @@ import com.p4square.grow.config.Config; import com.p4square.f1oauth.F1Access; import com.p4square.f1oauth.SecondPartyVerifier; +import com.p4square.restlet.metrics.MetricRouter; + import com.p4square.session.SessionCheckingAuthenticator; import com.p4square.session.SessionCreatingAuthenticator; @@ -47,22 +51,28 @@ import com.p4square.session.SessionCreatingAuthenticator; public class GrowFrontend extends FMFacade { private static Logger LOG = Logger.getLogger(GrowFrontend.class); - private Config mConfig; + private final Config mConfig; + private final MetricRegistry mMetricRegistry; private F1Access mHelper; public GrowFrontend() { - this(new Config()); + this(new Config(), new MetricRegistry()); } - public GrowFrontend(Config config) { + public GrowFrontend(Config config, MetricRegistry metricRegistry) { mConfig = config; + mMetricRegistry = metricRegistry; } public Config getConfig() { return mConfig; } + public MetricRegistry getMetrics() { + return mMetricRegistry; + } + @Override public synchronized void start() throws Exception { Template errorTemplate = getTemplate("templates/error.ftl"); @@ -80,6 +90,7 @@ public class GrowFrontend extends FMFacade { mConfig.getString("f1BaseUrl", "staging.fellowshiponeapi.com"), mConfig.getString("f1ChurchCode", "pfseawa"), F1Access.UserType.WEBLINK); + mHelper.setMetricRegistry(mMetricRegistry); } return mHelper; @@ -87,7 +98,7 @@ public class GrowFrontend extends FMFacade { @Override protected Router createRouter() { - Router router = new Router(getContext()); + Router router = new MetricRouter(getContext(), mMetricRegistry); final Authenticator defaultGuard = new SessionCheckingAuthenticator(getContext(), true); defaultGuard.setNext(FreeMarkerPageResource.class); @@ -97,7 +108,7 @@ public class GrowFrontend extends FMFacade { router.attach("/newaccount.html", NewAccountResource.class); router.attach("/newbeliever", NewBelieverResource.class); - final Router accountRouter = new Router(getContext()); + final Router accountRouter = new MetricRouter(getContext(), mMetricRegistry); accountRouter.attach("/authenticate", AuthenticatedResource.class); accountRouter.attach("/logout", LogoutResource.class); |