This is an automated email from the ASF dual-hosted git repository. sebawagner pushed a commit to branch feature/OPENMEETINGS-2577-performance--metrics-disabled-state in repository https://gitbox.apache.org/repos/asf/openmeetings.git
commit 0a12b0fa94a3285b1801bf92b3ec23f847997250 Author: Sebastian Wagner <seba.wag...@gmail.com> AuthorDate: Wed Feb 17 17:06:18 2021 +1300 OPENMEETINGS-2577 Add aop-style Annotations and Aspect to register in Prometheus. --- openmeetings-util/pom.xml | 17 ++++++ .../util/logging/PrometheusAspect.java | 60 ++++++++++++++++++++++ .../openmeetings/util/logging/PrometheusUtil.java | 16 ++++++ .../util/logging/TimedApplication.java | 31 +++++++++++ .../openmeetings/util/logging/TimedDatabase.java | 31 +++++++++++ pom.xml | 33 ++++++++++++ 6 files changed, 188 insertions(+) diff --git a/openmeetings-util/pom.xml b/openmeetings-util/pom.xml index 3df7acc..6ec925a 100644 --- a/openmeetings-util/pom.xml +++ b/openmeetings-util/pom.xml @@ -133,5 +133,22 @@ <groupId>org.apache.tika</groupId> <artifactId>tika-parsers</artifactId> </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-context</artifactId> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-aop</artifactId> + </dependency> + <dependency> + <groupId>org.aspectj</groupId> + <artifactId>aspectjtools</artifactId> + <version>1.9.6</version> + </dependency> + <dependency> + <groupId>io.prometheus</groupId> + <artifactId>simpleclient</artifactId> + </dependency> </dependencies> </project> diff --git a/openmeetings-util/src/main/java/org/apache/openmeetings/util/logging/PrometheusAspect.java b/openmeetings-util/src/main/java/org/apache/openmeetings/util/logging/PrometheusAspect.java new file mode 100644 index 0000000..30da70f --- /dev/null +++ b/openmeetings-util/src/main/java/org/apache/openmeetings/util/logging/PrometheusAspect.java @@ -0,0 +1,60 @@ +/* + + * 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.openmeetings.util.logging; + +import org.aspectj.lang.ProceedingJoinPoint; +import org.aspectj.lang.annotation.Around; +import org.aspectj.lang.annotation.Aspect; +import org.springframework.stereotype.Component; + +import io.prometheus.client.Histogram; + +@Aspect +@Component +public class PrometheusAspect { + + @Around("@annotation(TimedDatabase)") + public Object logExecutionTime(ProceedingJoinPoint joinPoint) throws Throwable { + String className = joinPoint.getSignature().getDeclaringType().getSimpleName(); + String methodName = joinPoint.getSignature().getName(); + Histogram.Timer timer = PrometheusUtil.getHistogram() // + .labels(className, methodName, "database", "default").startTimer(); + try { + return joinPoint.proceed(); + } finally { + timer.observeDuration(); + } + } + + @Around("@annotation(TimedApplication)") + public Object logExecutionTimedApplication(ProceedingJoinPoint joinPoint) throws Throwable { + String className = joinPoint.getSignature().getDeclaringType().getSimpleName(); + String methodName = joinPoint.getSignature().getName(); + Histogram.Timer timer = PrometheusUtil.getHistogram() // + .labels(className, methodName, "application", "default").startTimer(); + try { + return joinPoint.proceed(); + } finally { + timer.observeDuration(); + } + } + + +} diff --git a/openmeetings-util/src/main/java/org/apache/openmeetings/util/logging/PrometheusUtil.java b/openmeetings-util/src/main/java/org/apache/openmeetings/util/logging/PrometheusUtil.java new file mode 100644 index 0000000..8af38ee --- /dev/null +++ b/openmeetings-util/src/main/java/org/apache/openmeetings/util/logging/PrometheusUtil.java @@ -0,0 +1,16 @@ +package org.apache.openmeetings.util.logging; + +import io.prometheus.client.Histogram; + +public class PrometheusUtil { + + private static Histogram histogram = Histogram.build() // + .help("OpenMeetings Application Metrics") // + .name("org_openmeetings_metrics") // + .labelNames("class", "method", "type", "message") // + .register(); + + public static Histogram getHistogram() { + return histogram; + } +} diff --git a/openmeetings-util/src/main/java/org/apache/openmeetings/util/logging/TimedApplication.java b/openmeetings-util/src/main/java/org/apache/openmeetings/util/logging/TimedApplication.java new file mode 100644 index 0000000..09c25ea --- /dev/null +++ b/openmeetings-util/src/main/java/org/apache/openmeetings/util/logging/TimedApplication.java @@ -0,0 +1,31 @@ +/* + + * 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.openmeetings.util.logging; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.METHOD) +public @interface TimedApplication { + +} diff --git a/openmeetings-util/src/main/java/org/apache/openmeetings/util/logging/TimedDatabase.java b/openmeetings-util/src/main/java/org/apache/openmeetings/util/logging/TimedDatabase.java new file mode 100644 index 0000000..0280295 --- /dev/null +++ b/openmeetings-util/src/main/java/org/apache/openmeetings/util/logging/TimedDatabase.java @@ -0,0 +1,31 @@ +/* + + * 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.openmeetings.util.logging; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.METHOD) +public @interface TimedDatabase { + +} diff --git a/pom.xml b/pom.xml index 2ce0b03..ea2c369 100644 --- a/pom.xml +++ b/pom.xml @@ -87,6 +87,7 @@ <tomcat.version>9.0.43</tomcat.version> <ical4j.version>3.0.18</ical4j.version> <cxf.version>3.4.2</cxf.version> + <io.prometheus.version>0.10.0</io.prometheus.version> <simple-xml.version>2.7.1</simple-xml.version> <jettison.version>1.4.1</jettison.version> <site.basedir>${project.basedir}</site.basedir> @@ -456,6 +457,17 @@ </dependency> <dependency> <groupId>org.springframework</groupId> + <artifactId>spring-context</artifactId> + <version>${spring.version}</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.springframework</groupId> <artifactId>spring-context-support</artifactId> <version>${spring.version}</version> <exclusions> @@ -477,6 +489,17 @@ </exclusions> </dependency> <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-aop</artifactId> + <version>${spring.version}</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> <groupId>org.mnode.ical4j</groupId> <artifactId>ical4j</artifactId> <version>${ical4j.version}</version> @@ -536,6 +559,16 @@ <version>${cxf.version}</version> </dependency> <dependency> + <groupId>io.prometheus</groupId> + <artifactId>simpleclient</artifactId> + <version>${io.prometheus.version}</version> + </dependency> + <dependency> + <groupId>io.prometheus</groupId> + <artifactId>simpleclient_servlet</artifactId> + <version>${io.prometheus.version}</version> + </dependency> + <dependency> <groupId>org.codehaus.jettison</groupId> <artifactId>jettison</artifactId> <version>${jettison.version}</version>