Wicket Metrics - Time measurement / license header Project: http://git-wip-us.apache.org/repos/asf/wicket/repo Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/5f8b9fe0 Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/5f8b9fe0 Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/5f8b9fe0
Branch: refs/heads/master Commit: 5f8b9fe07b6581cebb5f88a2b00e657e292dc31c Parents: fc85c03 Author: Tobias Soloschenko <[email protected]> Authored: Thu Mar 10 14:03:19 2016 +0100 Committer: Tobias Soloschenko <[email protected]> Committed: Wed Mar 16 17:55:09 2016 +0100 ---------------------------------------------------------------------- .../apache/wicket/metrics/WicketMetrics.java | 54 +++++++++++++++++++- .../metrics/aspects/ApplicationAspect.java | 45 ++++++++++++++-- .../wicket/metrics/aspects/PageAspect.java | 16 ++++++ 3 files changed, 108 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/wicket/blob/5f8b9fe0/wicket-metrics/src/main/java/org/apache/wicket/metrics/WicketMetrics.java ---------------------------------------------------------------------- diff --git a/wicket-metrics/src/main/java/org/apache/wicket/metrics/WicketMetrics.java b/wicket-metrics/src/main/java/org/apache/wicket/metrics/WicketMetrics.java index 26314f0..055b07f 100644 --- a/wicket-metrics/src/main/java/org/apache/wicket/metrics/WicketMetrics.java +++ b/wicket-metrics/src/main/java/org/apache/wicket/metrics/WicketMetrics.java @@ -1,7 +1,24 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.apache.wicket.metrics; import com.codahale.metrics.JmxReporter; import com.codahale.metrics.MetricRegistry; +import com.codahale.metrics.Timer.Context; /** * Base aspect provides access to the metric registry @@ -16,7 +33,7 @@ public class WicketMetrics private static boolean enabled = true; - private static final String JMX_PREFIX = "ApacheWicket/"; + private static final String PREFIX = "ApacheWicket/"; /** * Gets the metric registry @@ -43,7 +60,40 @@ public class WicketMetrics { if (WicketMetrics.enabled) { - getMetricRegistry().meter(JMX_PREFIX + name).mark(); + getMetricRegistry().meter(PREFIX + name).mark(); + } + } + + /** + * Gets a timer context + * + * @param name + * the name of the timer context + * @return the timer context + */ + protected Context context(String name) + { + if (WicketMetrics.enabled) + { + return getMetricRegistry().timer(PREFIX + name).time(); + } + else + { + return null; + } + } + + /** + * Stops the contex quietly + * + * @param context + * the context to stop + */ + public void stopQuietly(Context context) + { + if (context != null) + { + context.stop(); } } http://git-wip-us.apache.org/repos/asf/wicket/blob/5f8b9fe0/wicket-metrics/src/main/java/org/apache/wicket/metrics/aspects/ApplicationAspect.java ---------------------------------------------------------------------- diff --git a/wicket-metrics/src/main/java/org/apache/wicket/metrics/aspects/ApplicationAspect.java b/wicket-metrics/src/main/java/org/apache/wicket/metrics/aspects/ApplicationAspect.java index 2f56e50..10d51a8 100644 --- a/wicket-metrics/src/main/java/org/apache/wicket/metrics/aspects/ApplicationAspect.java +++ b/wicket-metrics/src/main/java/org/apache/wicket/metrics/aspects/ApplicationAspect.java @@ -1,8 +1,27 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.apache.wicket.metrics.aspects; import org.apache.wicket.metrics.WicketMetrics; +import org.aspectj.lang.ProceedingJoinPoint; +import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; -import org.aspectj.lang.annotation.Before; + +import com.codahale.metrics.Timer.Context; /** * Aspect to handle basic web application information @@ -14,11 +33,27 @@ public class ApplicationAspect extends WicketMetrics { /** - * Collects data how often a request has been made against the web app + * Collects data how often a request has been made against the webapp and counts the time how + * long the request remains + * + * @param joinPoint + * the joinPoint to be proceed + * @return returns the boolean of the processRequest method + * + * @throws Throwable + * might occure while invoking process request */ - @Before("call(* org.apache.wicket.protocol.http.WicketFilter.processRequest(..))") - public void beforeRequestProcessed() + @Around("execution(* org.apache.wicket.protocol.http.WicketFilter.processRequest(..))") + public Object aroundRequestProcessed(ProceedingJoinPoint joinPoint) throws Throwable { - mark("core/application/request"); + Context context = context("core/application/request"); + try + { + return joinPoint.proceed(); + } + finally + { + stopQuietly(context); + } } } http://git-wip-us.apache.org/repos/asf/wicket/blob/5f8b9fe0/wicket-metrics/src/main/java/org/apache/wicket/metrics/aspects/PageAspect.java ---------------------------------------------------------------------- diff --git a/wicket-metrics/src/main/java/org/apache/wicket/metrics/aspects/PageAspect.java b/wicket-metrics/src/main/java/org/apache/wicket/metrics/aspects/PageAspect.java index 4e85a36..1f03d35 100644 --- a/wicket-metrics/src/main/java/org/apache/wicket/metrics/aspects/PageAspect.java +++ b/wicket-metrics/src/main/java/org/apache/wicket/metrics/aspects/PageAspect.java @@ -1,3 +1,19 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.apache.wicket.metrics.aspects; import org.apache.wicket.metrics.WicketMetrics;
