You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openmeetings.apache.org by GitBox <gi...@apache.org> on 2021/02/21 20:43:03 UTC

[GitHub] [openmeetings] sebawagner opened a new pull request #130: OPENMEETINGS-2577 performance metrics disabled state

sebawagner opened a new pull request #130:
URL: https://github.com/apache/openmeetings/pull/130


   Enables metrics - but in disabled state by default.
   
   By default all gathering of metrics as well as exposing metrics is disabled!
   
   In order to enable it there needs to be configuration in the web.xml and applicationContext.xml updated.
   
   See documentation on how to enable it:
   https://cwiki.apache.org/confluence/display/OPENMEETINGS/Prometheus+Logging+and+Metrics#PrometheusLoggingandMetrics-EnableMetrics
   
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [openmeetings] sebawagner commented on a change in pull request #130: OPENMEETINGS-2577 performance metrics disabled state

Posted by GitBox <gi...@apache.org>.
sebawagner commented on a change in pull request #130:
URL: https://github.com/apache/openmeetings/pull/130#discussion_r580616790



##########
File path: openmeetings-util/src/main/java/org/apache/openmeetings/util/logging/PrometheusUtil.java
##########
@@ -0,0 +1,35 @@
+/*
+
+ * 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 io.prometheus.client.Histogram;
+
+public class PrometheusUtil {
+
+	private static Histogram histogram = Histogram.build() //

Review comment:
       Those are quotes to prevent outformatting. You usually put them at the end, so that if you highlight all the lines and press CTRL-SHIFT-F Eclipse (or other editors) will reformat. And in order to force a line break you add those // at the end.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [openmeetings] sebawagner commented on a change in pull request #130: OPENMEETINGS-2577 performance metrics disabled state

Posted by GitBox <gi...@apache.org>.
sebawagner commented on a change in pull request #130:
URL: https://github.com/apache/openmeetings/pull/130#discussion_r580619380



##########
File path: 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();

Review comment:
       Done




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [openmeetings] sebawagner commented on a change in pull request #130: OPENMEETINGS-2577 performance metrics disabled state

Posted by GitBox <gi...@apache.org>.
sebawagner commented on a change in pull request #130:
URL: https://github.com/apache/openmeetings/pull/130#discussion_r579863381



##########
File path: 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>

Review comment:
       Prometheus Java Client and all new dependencies are Apache Licence 2.0: 
   https://github.com/prometheus/client_java/blob/master/LICENSE




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [openmeetings] sebawagner commented on a change in pull request #130: OPENMEETINGS-2577 performance metrics disabled state

Posted by GitBox <gi...@apache.org>.
sebawagner commented on a change in pull request #130:
URL: https://github.com/apache/openmeetings/pull/130#discussion_r579862873



##########
File path: openmeetings-core/src/main/java/org/apache/openmeetings/core/remote/StreamProcessorActions.java
##########
@@ -0,0 +1,127 @@
+/*
+
+ * 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.core.remote;
+
+import static org.apache.openmeetings.core.remote.KurentoHandler.PARAM_CANDIDATE;
+import static org.apache.openmeetings.core.remote.KurentoHandler.sendError;
+
+import org.apache.openmeetings.core.util.WebSocketHelper;
+import org.apache.openmeetings.db.entity.basic.Client;
+import org.apache.openmeetings.db.entity.basic.Client.Activity;
+import org.apache.openmeetings.db.entity.basic.Client.StreamDesc;
+import org.apache.openmeetings.db.entity.basic.Client.StreamType;
+import org.apache.openmeetings.db.manager.IClientManager;
+import org.apache.openmeetings.util.logging.TimedApplication;
+import org.apache.wicket.util.string.Strings;
+import org.kurento.client.IceCandidate;
+import org.kurento.client.internal.server.KurentoServerException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import com.github.openjson.JSONObject;
+
+@Component
+public class StreamProcessorActions {

Review comment:
       This is to be able to have below methods being called via Spring Beans and being able to annotate the classes.
   
   However it might be also useful in order to write tests to have below methods in a separated bean.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [openmeetings] sebawagner commented on a change in pull request #130: OPENMEETINGS-2577 performance metrics disabled state

Posted by GitBox <gi...@apache.org>.
sebawagner commented on a change in pull request #130:
URL: https://github.com/apache/openmeetings/pull/130#discussion_r580621159



##########
File path: openmeetings-web/src/main/java/org/apache/openmeetings/web/util/logging/TomcatGenericExports.java
##########
@@ -0,0 +1,305 @@
+/*
+ * 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.web.util.logging;
+
+import io.prometheus.client.Collector;
+import io.prometheus.client.CounterMetricFamily;
+import io.prometheus.client.GaugeMetricFamily;
+import org.apache.catalina.util.ServerInfo;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.management.*;

Review comment:
       Done




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [openmeetings] sebawagner commented on a change in pull request #130: OPENMEETINGS-2577 performance metrics disabled state

Posted by GitBox <gi...@apache.org>.
sebawagner commented on a change in pull request #130:
URL: https://github.com/apache/openmeetings/pull/130#discussion_r580616790



##########
File path: openmeetings-util/src/main/java/org/apache/openmeetings/util/logging/PrometheusUtil.java
##########
@@ -0,0 +1,35 @@
+/*
+
+ * 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 io.prometheus.client.Histogram;
+
+public class PrometheusUtil {
+
+	private static Histogram histogram = Histogram.build() //

Review comment:
       Those are slashes to prevent auto-formatting and line-breaks. You usually put them at the end, so that if you highlight all the lines and press CTRL-SHIFT-F Eclipse (or other editors) will reformat. And in order to force a line break you add those // at the end.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [openmeetings] solomax commented on a change in pull request #130: OPENMEETINGS-2577 performance metrics disabled state

Posted by GitBox <gi...@apache.org>.
solomax commented on a change in pull request #130:
URL: https://github.com/apache/openmeetings/pull/130#discussion_r580735709



##########
File path: 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() //

Review comment:
       I believe the best option will be to make your auto-formatter less agressive/turned off
   these empty comments are useless :((




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [openmeetings] solomax commented on pull request #130: OPENMEETINGS-2577 performance metrics disabled state

Posted by GitBox <gi...@apache.org>.
solomax commented on pull request #130:
URL: https://github.com/apache/openmeetings/pull/130#issuecomment-783839790


   Thanks for the new feature :)


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [openmeetings] sebawagner merged pull request #130: OPENMEETINGS-2577 performance metrics disabled state

Posted by GitBox <gi...@apache.org>.
sebawagner merged pull request #130:
URL: https://github.com/apache/openmeetings/pull/130


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [openmeetings] solomax commented on a change in pull request #130: OPENMEETINGS-2577 performance metrics disabled state

Posted by GitBox <gi...@apache.org>.
solomax commented on a change in pull request #130:
URL: https://github.com/apache/openmeetings/pull/130#discussion_r580063954



##########
File path: 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();

Review comment:
       this code here looks like 99% duplicate of above, can be generalized

##########
File path: 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>

Review comment:
       I would prefer to have this in `dependency manager` section with `version` as a property for easier maintainance

##########
File path: 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() //

Review comment:
       this `//` seems to be useless

##########
File path: openmeetings-web/src/main/java/org/apache/openmeetings/web/util/logging/OpenMeetingsMetricsServlet.java
##########
@@ -0,0 +1,32 @@
+/*
+ * 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.web.util.logging;
+
+import io.prometheus.client.exporter.MetricsServlet;
+
+public class OpenMeetingsMetricsServlet extends MetricsServlet {
+
+	private static final long serialVersionUID = -2488393857088858502L;
+
+	public OpenMeetingsMetricsServlet() {
+		super();
+		new TomcatGenericExports(false).register();

Review comment:
       class calling consctructor and has no more code ....
   Maybe it worth to merge `TomcatGenericExports` into this servlet?

##########
File path: openmeetings-web/pom.xml
##########
@@ -627,6 +627,14 @@
 			<groupId>org.apache.commons</groupId>
 			<artifactId>commons-lang3</artifactId>
 		</dependency>
+		<dependency>
+			<groupId>io.prometheus</groupId>
+			<artifactId>simpleclient_servlet</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.tomcat</groupId>
+			<artifactId>tomcat-catalina</artifactId>

Review comment:
       Will this introduce any conflicts if started with Jetty?

##########
File path: openmeetings-web/src/main/java/org/apache/openmeetings/web/util/logging/TomcatGenericExports.java
##########
@@ -0,0 +1,305 @@
+/*
+ * 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.web.util.logging;
+
+import io.prometheus.client.Collector;
+import io.prometheus.client.CounterMetricFamily;
+import io.prometheus.client.GaugeMetricFamily;
+import org.apache.catalina.util.ServerInfo;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.management.*;
+import java.lang.management.ManagementFactory;
+import java.util.*;
+
+/**
+ * Exports Tomcat metrics applicable to most most applications:
+ *
+ * - http session metrics - request processor metrics - thread pool metrics
+ *
+ * <p>
+ * Example usage:
+ *
+ * <pre>
+ * {@code
+ *   new TomcatGenericExports(false).register();
+ * }
+ * </pre>
+ *
+ * Example metrics being exported:
+ *
+ * <pre>
+ * tomcat_info{version="7.0.61.0",build="Apr 29 2015 14:58:03 UTC",} 1.0
+ * tomcat_session_active_total{context="/foo",host="default",} 877.0
+ * tomcat_session_rejected_total{context="/foo",host="default",} 0.0
+ * tomcat_session_created_total{context="/foo",host="default",} 24428.0
+ * tomcat_session_expired_total{context="/foo",host="default",} 23832.0
+ * tomcat_session_alivetime_seconds_avg{context="/foo",host="default",} 633.0
+ * tomcat_session_alivetime_seconds_max{context="/foo",host="default",} 9883.0
+ * tomcat_requestprocessor_received_bytes{name="http-bio-0.0.0.0-8080",} 0.0
+ * tomcat_requestprocessor_sent_bytes{name="http-bio-0.0.0.0-8080",} 5056098.0
+ * tomcat_requestprocessor_time_seconds{name="http-bio-0.0.0.0-8080",} 127386.0
+ * tomcat_requestprocessor_error_count{name="http-bio-0.0.0.0-8080",} 0.0
+ * tomcat_requestprocessor_request_count{name="http-bio-0.0.0.0-8080",} 33709.0
+ * tomcat_threads_total{pool="http-bio-0.0.0.0-8080",} 10.0
+ * tomcat_threads_active_total{pool="http-bio-0.0.0.0-8080",} 2.0
+ * tomcat_threads_active_max{pool="http-bio-0.0.0.0-8080",} 200.0
+ * </pre>
+ */
+
+public class TomcatGenericExports extends Collector {
+
+	private static final Logger log = LoggerFactory.getLogger(TomcatGenericExports.class);
+	private String jmxDomain = "Catalina";
+
+	public TomcatGenericExports(boolean embedded) {
+		if (embedded) {
+			jmxDomain = "Tomcat";
+		}
+	}
+
+	private void addRequestProcessorMetrics(List<MetricFamilySamples> mfs) {
+		try {
+			final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
+			ObjectName filterName = new ObjectName(jmxDomain + ":type=GlobalRequestProcessor,name=*");
+			Set<ObjectInstance> mBeans = server.queryMBeans(filterName, null);
+
+			if (mBeans.size() > 0) {
+				List<String> labelNameList = Collections.singletonList("name");

Review comment:
       `List.of("name")` ?

##########
File path: openmeetings-web/src/main/java/org/apache/openmeetings/web/util/logging/TomcatGenericExports.java
##########
@@ -0,0 +1,305 @@
+/*
+ * 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.web.util.logging;
+
+import io.prometheus.client.Collector;
+import io.prometheus.client.CounterMetricFamily;
+import io.prometheus.client.GaugeMetricFamily;
+import org.apache.catalina.util.ServerInfo;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.management.*;
+import java.lang.management.ManagementFactory;
+import java.util.*;
+
+/**
+ * Exports Tomcat metrics applicable to most most applications:
+ *
+ * - http session metrics - request processor metrics - thread pool metrics
+ *
+ * <p>

Review comment:
       it seems this `<p>` tag has no close tag
   I would remove it
   not sure if below `<pre>` tags are required ...

##########
File path: openmeetings-web/src/main/java/org/apache/openmeetings/web/util/logging/OpenMeetingsMetricsServlet.java
##########
@@ -0,0 +1,32 @@
+/*
+ * 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.web.util.logging;
+
+import io.prometheus.client.exporter.MetricsServlet;
+
+public class OpenMeetingsMetricsServlet extends MetricsServlet {
+
+	private static final long serialVersionUID = -2488393857088858502L;

Review comment:
       `serialVersionUID` everywhere in the code is `1`
   I see no benefit of generated value

##########
File path: openmeetings-web/src/main/java/org/apache/openmeetings/web/util/logging/TomcatGenericExports.java
##########
@@ -0,0 +1,305 @@
+/*
+ * 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.web.util.logging;
+
+import io.prometheus.client.Collector;
+import io.prometheus.client.CounterMetricFamily;
+import io.prometheus.client.GaugeMetricFamily;
+import org.apache.catalina.util.ServerInfo;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.management.*;
+import java.lang.management.ManagementFactory;
+import java.util.*;
+
+/**
+ * Exports Tomcat metrics applicable to most most applications:
+ *
+ * - http session metrics - request processor metrics - thread pool metrics
+ *
+ * <p>
+ * Example usage:
+ *
+ * <pre>
+ * {@code
+ *   new TomcatGenericExports(false).register();
+ * }
+ * </pre>
+ *
+ * Example metrics being exported:
+ *
+ * <pre>
+ * tomcat_info{version="7.0.61.0",build="Apr 29 2015 14:58:03 UTC",} 1.0
+ * tomcat_session_active_total{context="/foo",host="default",} 877.0
+ * tomcat_session_rejected_total{context="/foo",host="default",} 0.0
+ * tomcat_session_created_total{context="/foo",host="default",} 24428.0
+ * tomcat_session_expired_total{context="/foo",host="default",} 23832.0
+ * tomcat_session_alivetime_seconds_avg{context="/foo",host="default",} 633.0
+ * tomcat_session_alivetime_seconds_max{context="/foo",host="default",} 9883.0
+ * tomcat_requestprocessor_received_bytes{name="http-bio-0.0.0.0-8080",} 0.0
+ * tomcat_requestprocessor_sent_bytes{name="http-bio-0.0.0.0-8080",} 5056098.0
+ * tomcat_requestprocessor_time_seconds{name="http-bio-0.0.0.0-8080",} 127386.0
+ * tomcat_requestprocessor_error_count{name="http-bio-0.0.0.0-8080",} 0.0
+ * tomcat_requestprocessor_request_count{name="http-bio-0.0.0.0-8080",} 33709.0
+ * tomcat_threads_total{pool="http-bio-0.0.0.0-8080",} 10.0
+ * tomcat_threads_active_total{pool="http-bio-0.0.0.0-8080",} 2.0
+ * tomcat_threads_active_max{pool="http-bio-0.0.0.0-8080",} 200.0
+ * </pre>
+ */
+
+public class TomcatGenericExports extends Collector {
+
+	private static final Logger log = LoggerFactory.getLogger(TomcatGenericExports.class);
+	private String jmxDomain = "Catalina";
+
+	public TomcatGenericExports(boolean embedded) {
+		if (embedded) {
+			jmxDomain = "Tomcat";
+		}
+	}
+
+	private void addRequestProcessorMetrics(List<MetricFamilySamples> mfs) {
+		try {
+			final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
+			ObjectName filterName = new ObjectName(jmxDomain + ":type=GlobalRequestProcessor,name=*");
+			Set<ObjectInstance> mBeans = server.queryMBeans(filterName, null);
+
+			if (mBeans.size() > 0) {
+				List<String> labelNameList = Collections.singletonList("name");

Review comment:
       I guess Sonar will be unhappy :(
   Please create constants instead of `"..."` used more than 3 times

##########
File path: openmeetings-util/src/main/java/org/apache/openmeetings/util/logging/PrometheusUtil.java
##########
@@ -0,0 +1,35 @@
+/*
+
+ * 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 io.prometheus.client.Histogram;
+
+public class PrometheusUtil {
+
+	private static Histogram histogram = Histogram.build() //

Review comment:
       these `//` seems to be useless

##########
File path: openmeetings-web/src/main/java/org/apache/openmeetings/web/util/logging/TomcatGenericExports.java
##########
@@ -0,0 +1,305 @@
+/*
+ * 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.web.util.logging;
+
+import io.prometheus.client.Collector;
+import io.prometheus.client.CounterMetricFamily;
+import io.prometheus.client.GaugeMetricFamily;
+import org.apache.catalina.util.ServerInfo;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.management.*;
+import java.lang.management.ManagementFactory;
+import java.util.*;
+
+/**
+ * Exports Tomcat metrics applicable to most most applications:
+ *
+ * - http session metrics - request processor metrics - thread pool metrics
+ *
+ * <p>
+ * Example usage:
+ *
+ * <pre>
+ * {@code
+ *   new TomcatGenericExports(false).register();
+ * }
+ * </pre>
+ *
+ * Example metrics being exported:
+ *
+ * <pre>
+ * tomcat_info{version="7.0.61.0",build="Apr 29 2015 14:58:03 UTC",} 1.0
+ * tomcat_session_active_total{context="/foo",host="default",} 877.0
+ * tomcat_session_rejected_total{context="/foo",host="default",} 0.0
+ * tomcat_session_created_total{context="/foo",host="default",} 24428.0
+ * tomcat_session_expired_total{context="/foo",host="default",} 23832.0
+ * tomcat_session_alivetime_seconds_avg{context="/foo",host="default",} 633.0
+ * tomcat_session_alivetime_seconds_max{context="/foo",host="default",} 9883.0
+ * tomcat_requestprocessor_received_bytes{name="http-bio-0.0.0.0-8080",} 0.0
+ * tomcat_requestprocessor_sent_bytes{name="http-bio-0.0.0.0-8080",} 5056098.0
+ * tomcat_requestprocessor_time_seconds{name="http-bio-0.0.0.0-8080",} 127386.0
+ * tomcat_requestprocessor_error_count{name="http-bio-0.0.0.0-8080",} 0.0
+ * tomcat_requestprocessor_request_count{name="http-bio-0.0.0.0-8080",} 33709.0
+ * tomcat_threads_total{pool="http-bio-0.0.0.0-8080",} 10.0
+ * tomcat_threads_active_total{pool="http-bio-0.0.0.0-8080",} 2.0
+ * tomcat_threads_active_max{pool="http-bio-0.0.0.0-8080",} 200.0
+ * </pre>
+ */
+
+public class TomcatGenericExports extends Collector {
+
+	private static final Logger log = LoggerFactory.getLogger(TomcatGenericExports.class);
+	private String jmxDomain = "Catalina";
+
+	public TomcatGenericExports(boolean embedded) {
+		if (embedded) {
+			jmxDomain = "Tomcat";
+		}
+	}
+
+	private void addRequestProcessorMetrics(List<MetricFamilySamples> mfs) {
+		try {
+			final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
+			ObjectName filterName = new ObjectName(jmxDomain + ":type=GlobalRequestProcessor,name=*");
+			Set<ObjectInstance> mBeans = server.queryMBeans(filterName, null);
+
+			if (mBeans.size() > 0) {
+				List<String> labelNameList = Collections.singletonList("name");
+
+				GaugeMetricFamily requestProcessorBytesReceivedGauge = new GaugeMetricFamily(
+						"tomcat_requestprocessor_received_bytes", "Number of bytes received by this request processor",
+						labelNameList);
+
+				GaugeMetricFamily requestProcessorBytesSentGauge = new GaugeMetricFamily(
+						"tomcat_requestprocessor_sent_bytes", "Number of bytes sent by this request processor",
+						labelNameList);
+
+				GaugeMetricFamily requestProcessorProcessingTimeGauge = new GaugeMetricFamily(
+						"tomcat_requestprocessor_time_seconds", "The total time spend by this request processor",
+						labelNameList);
+
+				CounterMetricFamily requestProcessorErrorCounter = new CounterMetricFamily(
+						"tomcat_requestprocessor_error_count",
+						"The number of error request served by this request processor", labelNameList);
+
+				CounterMetricFamily requestProcessorRequestCounter = new CounterMetricFamily(
+						"tomcat_requestprocessor_request_count",
+						"The number of request served by this request processor", labelNameList);
+
+				for (final ObjectInstance mBean : mBeans) {
+					List<String> labelValueList = Collections
+							.singletonList(mBean.getObjectName().getKeyProperty("name").replaceAll("[\"\\\\]", ""));
+
+					requestProcessorBytesReceivedGauge.addMetric(labelValueList,
+							((Long) server.getAttribute(mBean.getObjectName(), "bytesReceived")).doubleValue());
+
+					requestProcessorBytesSentGauge.addMetric(labelValueList,
+							((Long) server.getAttribute(mBean.getObjectName(), "bytesSent")).doubleValue());
+
+					requestProcessorProcessingTimeGauge.addMetric(labelValueList,
+							((Long) server.getAttribute(mBean.getObjectName(), "processingTime")).doubleValue()
+									/ 1000.0);
+
+					requestProcessorErrorCounter.addMetric(labelValueList,
+							((Integer) server.getAttribute(mBean.getObjectName(), "errorCount")).doubleValue());
+
+					requestProcessorRequestCounter.addMetric(labelValueList,
+							((Integer) server.getAttribute(mBean.getObjectName(), "requestCount")).doubleValue());
+				}
+
+				mfs.add(requestProcessorBytesReceivedGauge);
+				mfs.add(requestProcessorBytesSentGauge);
+				mfs.add(requestProcessorProcessingTimeGauge);
+				mfs.add(requestProcessorRequestCounter);
+				mfs.add(requestProcessorErrorCounter);
+			}
+		} catch (Exception e) {
+			log.error("Error retrieving metric.", e);
+		}
+	}
+
+	private void addSessionMetrics(List<MetricFamilySamples> mfs) {
+		try {
+			final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
+			ObjectName filterName = new ObjectName(jmxDomain + ":type=Manager,context=*,host=*");
+			Set<ObjectInstance> mBeans = server.queryMBeans(filterName, null);
+
+			if (mBeans.size() > 0) {
+				List<String> labelNameList = Arrays.asList("host", "context");

Review comment:
       `List.of("host", "context")` ?

##########
File path: openmeetings-web/src/main/java/org/apache/openmeetings/web/util/logging/TomcatGenericExports.java
##########
@@ -0,0 +1,305 @@
+/*
+ * 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.web.util.logging;
+
+import io.prometheus.client.Collector;
+import io.prometheus.client.CounterMetricFamily;
+import io.prometheus.client.GaugeMetricFamily;
+import org.apache.catalina.util.ServerInfo;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.management.*;

Review comment:
       please avoid wildcard imports

##########
File path: openmeetings-web/src/main/java/org/apache/openmeetings/web/util/logging/TomcatGenericExports.java
##########
@@ -0,0 +1,305 @@
+/*
+ * 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.web.util.logging;
+
+import io.prometheus.client.Collector;
+import io.prometheus.client.CounterMetricFamily;
+import io.prometheus.client.GaugeMetricFamily;
+import org.apache.catalina.util.ServerInfo;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.management.*;
+import java.lang.management.ManagementFactory;
+import java.util.*;
+
+/**
+ * Exports Tomcat metrics applicable to most most applications:
+ *
+ * - http session metrics - request processor metrics - thread pool metrics
+ *
+ * <p>
+ * Example usage:
+ *
+ * <pre>
+ * {@code
+ *   new TomcatGenericExports(false).register();
+ * }
+ * </pre>
+ *
+ * Example metrics being exported:
+ *
+ * <pre>
+ * tomcat_info{version="7.0.61.0",build="Apr 29 2015 14:58:03 UTC",} 1.0
+ * tomcat_session_active_total{context="/foo",host="default",} 877.0
+ * tomcat_session_rejected_total{context="/foo",host="default",} 0.0
+ * tomcat_session_created_total{context="/foo",host="default",} 24428.0
+ * tomcat_session_expired_total{context="/foo",host="default",} 23832.0
+ * tomcat_session_alivetime_seconds_avg{context="/foo",host="default",} 633.0
+ * tomcat_session_alivetime_seconds_max{context="/foo",host="default",} 9883.0
+ * tomcat_requestprocessor_received_bytes{name="http-bio-0.0.0.0-8080",} 0.0
+ * tomcat_requestprocessor_sent_bytes{name="http-bio-0.0.0.0-8080",} 5056098.0
+ * tomcat_requestprocessor_time_seconds{name="http-bio-0.0.0.0-8080",} 127386.0
+ * tomcat_requestprocessor_error_count{name="http-bio-0.0.0.0-8080",} 0.0
+ * tomcat_requestprocessor_request_count{name="http-bio-0.0.0.0-8080",} 33709.0
+ * tomcat_threads_total{pool="http-bio-0.0.0.0-8080",} 10.0
+ * tomcat_threads_active_total{pool="http-bio-0.0.0.0-8080",} 2.0
+ * tomcat_threads_active_max{pool="http-bio-0.0.0.0-8080",} 200.0
+ * </pre>
+ */
+
+public class TomcatGenericExports extends Collector {
+
+	private static final Logger log = LoggerFactory.getLogger(TomcatGenericExports.class);
+	private String jmxDomain = "Catalina";
+
+	public TomcatGenericExports(boolean embedded) {
+		if (embedded) {
+			jmxDomain = "Tomcat";
+		}
+	}
+
+	private void addRequestProcessorMetrics(List<MetricFamilySamples> mfs) {
+		try {
+			final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
+			ObjectName filterName = new ObjectName(jmxDomain + ":type=GlobalRequestProcessor,name=*");
+			Set<ObjectInstance> mBeans = server.queryMBeans(filterName, null);
+
+			if (mBeans.size() > 0) {
+				List<String> labelNameList = Collections.singletonList("name");
+
+				GaugeMetricFamily requestProcessorBytesReceivedGauge = new GaugeMetricFamily(
+						"tomcat_requestprocessor_received_bytes", "Number of bytes received by this request processor",
+						labelNameList);
+
+				GaugeMetricFamily requestProcessorBytesSentGauge = new GaugeMetricFamily(
+						"tomcat_requestprocessor_sent_bytes", "Number of bytes sent by this request processor",
+						labelNameList);
+
+				GaugeMetricFamily requestProcessorProcessingTimeGauge = new GaugeMetricFamily(
+						"tomcat_requestprocessor_time_seconds", "The total time spend by this request processor",
+						labelNameList);
+
+				CounterMetricFamily requestProcessorErrorCounter = new CounterMetricFamily(
+						"tomcat_requestprocessor_error_count",
+						"The number of error request served by this request processor", labelNameList);
+
+				CounterMetricFamily requestProcessorRequestCounter = new CounterMetricFamily(
+						"tomcat_requestprocessor_request_count",
+						"The number of request served by this request processor", labelNameList);
+
+				for (final ObjectInstance mBean : mBeans) {
+					List<String> labelValueList = Collections
+							.singletonList(mBean.getObjectName().getKeyProperty("name").replaceAll("[\"\\\\]", ""));
+
+					requestProcessorBytesReceivedGauge.addMetric(labelValueList,
+							((Long) server.getAttribute(mBean.getObjectName(), "bytesReceived")).doubleValue());
+
+					requestProcessorBytesSentGauge.addMetric(labelValueList,
+							((Long) server.getAttribute(mBean.getObjectName(), "bytesSent")).doubleValue());
+
+					requestProcessorProcessingTimeGauge.addMetric(labelValueList,
+							((Long) server.getAttribute(mBean.getObjectName(), "processingTime")).doubleValue()
+									/ 1000.0);
+
+					requestProcessorErrorCounter.addMetric(labelValueList,
+							((Integer) server.getAttribute(mBean.getObjectName(), "errorCount")).doubleValue());
+
+					requestProcessorRequestCounter.addMetric(labelValueList,
+							((Integer) server.getAttribute(mBean.getObjectName(), "requestCount")).doubleValue());
+				}
+
+				mfs.add(requestProcessorBytesReceivedGauge);
+				mfs.add(requestProcessorBytesSentGauge);
+				mfs.add(requestProcessorProcessingTimeGauge);
+				mfs.add(requestProcessorRequestCounter);
+				mfs.add(requestProcessorErrorCounter);
+			}
+		} catch (Exception e) {
+			log.error("Error retrieving metric.", e);
+		}
+	}
+
+	private void addSessionMetrics(List<MetricFamilySamples> mfs) {
+		try {
+			final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
+			ObjectName filterName = new ObjectName(jmxDomain + ":type=Manager,context=*,host=*");
+			Set<ObjectInstance> mBeans = server.queryMBeans(filterName, null);
+
+			if (mBeans.size() > 0) {
+				List<String> labelNameList = Arrays.asList("host", "context");
+
+				GaugeMetricFamily activeSessionCountGauge = new GaugeMetricFamily("tomcat_session_active_total",
+						"Number of active sessions", labelNameList);
+
+				GaugeMetricFamily rejectedSessionCountGauge = new GaugeMetricFamily("tomcat_session_rejected_total",
+						"Number of sessions rejected due to maxActive being reached", labelNameList);
+
+				GaugeMetricFamily createdSessionCountGauge = new GaugeMetricFamily("tomcat_session_created_total",
+						"Number of sessions created", labelNameList);
+
+				GaugeMetricFamily expiredSessionCountGauge = new GaugeMetricFamily("tomcat_session_expired_total",
+						"Number of sessions that expired", labelNameList);
+
+				GaugeMetricFamily sessionAvgAliveTimeGauge = new GaugeMetricFamily(
+						"tomcat_session_alivetime_seconds_avg", "Average time an expired session had been alive",
+						labelNameList);
+
+				GaugeMetricFamily sessionMaxAliveTimeGauge = new GaugeMetricFamily(
+						"tomcat_session_alivetime_seconds_max", "Maximum time an expired session had been alive",
+						labelNameList);
+
+				GaugeMetricFamily contextStateGauge = new GaugeMetricFamily("tomcat_context_state_started",
+						"Indication if the lifecycle state of this context is STARTED", labelNameList);
+
+				for (final ObjectInstance mBean : mBeans) {
+					List<String> labelValueList = Arrays.asList(mBean.getObjectName().getKeyProperty("host"),
+							mBean.getObjectName().getKeyProperty("context"));
+
+					activeSessionCountGauge.addMetric(labelValueList,
+							((Integer) server.getAttribute(mBean.getObjectName(), "activeSessions")).doubleValue());
+
+					rejectedSessionCountGauge.addMetric(labelValueList,
+							((Integer) server.getAttribute(mBean.getObjectName(), "rejectedSessions")).doubleValue());
+
+					createdSessionCountGauge.addMetric(labelValueList,
+							((Long) server.getAttribute(mBean.getObjectName(), "sessionCounter")).doubleValue());
+
+					expiredSessionCountGauge.addMetric(labelValueList,
+							((Long) server.getAttribute(mBean.getObjectName(), "expiredSessions")).doubleValue());
+
+					sessionAvgAliveTimeGauge.addMetric(labelValueList,
+							((Integer) server.getAttribute(mBean.getObjectName(), "sessionAverageAliveTime"))
+									.doubleValue());
+
+					sessionMaxAliveTimeGauge.addMetric(labelValueList,
+							((Integer) server.getAttribute(mBean.getObjectName(), "sessionMaxAliveTime"))
+									.doubleValue());
+
+					if (server.getAttribute(mBean.getObjectName(), "stateName").equals("STARTED")) {
+						contextStateGauge.addMetric(labelValueList, 1.0);
+					} else {
+						contextStateGauge.addMetric(labelValueList, 0.0);
+					}
+				}
+
+				mfs.add(activeSessionCountGauge);
+				mfs.add(rejectedSessionCountGauge);
+				mfs.add(createdSessionCountGauge);
+				mfs.add(expiredSessionCountGauge);
+				mfs.add(sessionAvgAliveTimeGauge);
+				mfs.add(sessionMaxAliveTimeGauge);
+				mfs.add(contextStateGauge);
+			}
+		} catch (Exception e) {
+			log.error("Error retrieving metric.", e);
+		}
+	}
+
+	private void addThreadPoolMetrics(List<MetricFamilySamples> mfs) {
+		try {
+			final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
+			ObjectName filterName = new ObjectName(jmxDomain + ":type=ThreadPool,name=*");
+			Set<ObjectInstance> mBeans = server.queryMBeans(filterName, null);
+
+			if (mBeans.size() > 0) {
+				List<String> labelList = Collections.singletonList("name");

Review comment:
       `List.of`




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [openmeetings] sebawagner commented on a change in pull request #130: OPENMEETINGS-2577 performance metrics disabled state

Posted by GitBox <gi...@apache.org>.
sebawagner commented on a change in pull request #130:
URL: https://github.com/apache/openmeetings/pull/130#discussion_r580676262



##########
File path: 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>

Review comment:
       Done




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [openmeetings] sebawagner commented on a change in pull request #130: OPENMEETINGS-2577 performance metrics disabled state

Posted by GitBox <gi...@apache.org>.
sebawagner commented on a change in pull request #130:
URL: https://github.com/apache/openmeetings/pull/130#discussion_r580616047



##########
File path: openmeetings-web/pom.xml
##########
@@ -627,6 +627,14 @@
 			<groupId>org.apache.commons</groupId>
 			<artifactId>commons-lang3</artifactId>
 		</dependency>
+		<dependency>
+			<groupId>io.prometheus</groupId>
+			<artifactId>simpleclient_servlet</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.tomcat</groupId>
+			<artifactId>tomcat-catalina</artifactId>

Review comment:
       Jetty seems to work fine. I did test starting it up with embedded Jetty via Maven and there wasn't any issue. 
   Neither during startup nor later in the openmeetings.log




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [openmeetings] sebawagner commented on pull request #130: OPENMEETINGS-2577 performance metrics disabled state

Posted by GitBox <gi...@apache.org>.
sebawagner commented on pull request #130:
URL: https://github.com/apache/openmeetings/pull/130#issuecomment-783801829


   Resolved all comments and fixed those.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [openmeetings] sebawagner commented on a change in pull request #130: OPENMEETINGS-2577 performance metrics disabled state

Posted by GitBox <gi...@apache.org>.
sebawagner commented on a change in pull request #130:
URL: https://github.com/apache/openmeetings/pull/130#discussion_r580619067



##########
File path: 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() //

Review comment:
       See my other comment, the // are to force line break when auto-formatting the code. 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [openmeetings] sebawagner commented on a change in pull request #130: OPENMEETINGS-2577 performance metrics disabled state

Posted by GitBox <gi...@apache.org>.
sebawagner commented on a change in pull request #130:
URL: https://github.com/apache/openmeetings/pull/130#discussion_r580678670



##########
File path: openmeetings-web/src/main/java/org/apache/openmeetings/web/util/logging/TomcatGenericExports.java
##########
@@ -0,0 +1,305 @@
+/*
+ * 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.web.util.logging;
+
+import io.prometheus.client.Collector;
+import io.prometheus.client.CounterMetricFamily;
+import io.prometheus.client.GaugeMetricFamily;
+import org.apache.catalina.util.ServerInfo;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.management.*;
+import java.lang.management.ManagementFactory;
+import java.util.*;
+
+/**
+ * Exports Tomcat metrics applicable to most most applications:
+ *
+ * - http session metrics - request processor metrics - thread pool metrics
+ *
+ * <p>
+ * Example usage:
+ *
+ * <pre>
+ * {@code
+ *   new TomcatGenericExports(false).register();
+ * }
+ * </pre>
+ *
+ * Example metrics being exported:
+ *
+ * <pre>
+ * tomcat_info{version="7.0.61.0",build="Apr 29 2015 14:58:03 UTC",} 1.0
+ * tomcat_session_active_total{context="/foo",host="default",} 877.0
+ * tomcat_session_rejected_total{context="/foo",host="default",} 0.0
+ * tomcat_session_created_total{context="/foo",host="default",} 24428.0
+ * tomcat_session_expired_total{context="/foo",host="default",} 23832.0
+ * tomcat_session_alivetime_seconds_avg{context="/foo",host="default",} 633.0
+ * tomcat_session_alivetime_seconds_max{context="/foo",host="default",} 9883.0
+ * tomcat_requestprocessor_received_bytes{name="http-bio-0.0.0.0-8080",} 0.0
+ * tomcat_requestprocessor_sent_bytes{name="http-bio-0.0.0.0-8080",} 5056098.0
+ * tomcat_requestprocessor_time_seconds{name="http-bio-0.0.0.0-8080",} 127386.0
+ * tomcat_requestprocessor_error_count{name="http-bio-0.0.0.0-8080",} 0.0
+ * tomcat_requestprocessor_request_count{name="http-bio-0.0.0.0-8080",} 33709.0
+ * tomcat_threads_total{pool="http-bio-0.0.0.0-8080",} 10.0
+ * tomcat_threads_active_total{pool="http-bio-0.0.0.0-8080",} 2.0
+ * tomcat_threads_active_max{pool="http-bio-0.0.0.0-8080",} 200.0
+ * </pre>
+ */
+
+public class TomcatGenericExports extends Collector {
+
+	private static final Logger log = LoggerFactory.getLogger(TomcatGenericExports.class);
+	private String jmxDomain = "Catalina";
+
+	public TomcatGenericExports(boolean embedded) {
+		if (embedded) {
+			jmxDomain = "Tomcat";
+		}
+	}
+
+	private void addRequestProcessorMetrics(List<MetricFamilySamples> mfs) {
+		try {
+			final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
+			ObjectName filterName = new ObjectName(jmxDomain + ":type=GlobalRequestProcessor,name=*");
+			Set<ObjectInstance> mBeans = server.queryMBeans(filterName, null);
+
+			if (mBeans.size() > 0) {
+				List<String> labelNameList = Collections.singletonList("name");

Review comment:
       Done




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [openmeetings] sebawagner commented on a change in pull request #130: OPENMEETINGS-2577 performance metrics disabled state

Posted by GitBox <gi...@apache.org>.
sebawagner commented on a change in pull request #130:
URL: https://github.com/apache/openmeetings/pull/130#discussion_r580678531



##########
File path: openmeetings-web/src/main/java/org/apache/openmeetings/web/util/logging/TomcatGenericExports.java
##########
@@ -0,0 +1,305 @@
+/*
+ * 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.web.util.logging;
+
+import io.prometheus.client.Collector;
+import io.prometheus.client.CounterMetricFamily;
+import io.prometheus.client.GaugeMetricFamily;
+import org.apache.catalina.util.ServerInfo;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.management.*;
+import java.lang.management.ManagementFactory;
+import java.util.*;
+
+/**
+ * Exports Tomcat metrics applicable to most most applications:
+ *
+ * - http session metrics - request processor metrics - thread pool metrics
+ *
+ * <p>
+ * Example usage:
+ *
+ * <pre>
+ * {@code
+ *   new TomcatGenericExports(false).register();
+ * }
+ * </pre>
+ *
+ * Example metrics being exported:
+ *
+ * <pre>
+ * tomcat_info{version="7.0.61.0",build="Apr 29 2015 14:58:03 UTC",} 1.0
+ * tomcat_session_active_total{context="/foo",host="default",} 877.0
+ * tomcat_session_rejected_total{context="/foo",host="default",} 0.0
+ * tomcat_session_created_total{context="/foo",host="default",} 24428.0
+ * tomcat_session_expired_total{context="/foo",host="default",} 23832.0
+ * tomcat_session_alivetime_seconds_avg{context="/foo",host="default",} 633.0
+ * tomcat_session_alivetime_seconds_max{context="/foo",host="default",} 9883.0
+ * tomcat_requestprocessor_received_bytes{name="http-bio-0.0.0.0-8080",} 0.0
+ * tomcat_requestprocessor_sent_bytes{name="http-bio-0.0.0.0-8080",} 5056098.0
+ * tomcat_requestprocessor_time_seconds{name="http-bio-0.0.0.0-8080",} 127386.0
+ * tomcat_requestprocessor_error_count{name="http-bio-0.0.0.0-8080",} 0.0
+ * tomcat_requestprocessor_request_count{name="http-bio-0.0.0.0-8080",} 33709.0
+ * tomcat_threads_total{pool="http-bio-0.0.0.0-8080",} 10.0
+ * tomcat_threads_active_total{pool="http-bio-0.0.0.0-8080",} 2.0
+ * tomcat_threads_active_max{pool="http-bio-0.0.0.0-8080",} 200.0
+ * </pre>
+ */
+
+public class TomcatGenericExports extends Collector {
+
+	private static final Logger log = LoggerFactory.getLogger(TomcatGenericExports.class);
+	private String jmxDomain = "Catalina";
+
+	public TomcatGenericExports(boolean embedded) {
+		if (embedded) {
+			jmxDomain = "Tomcat";
+		}
+	}
+
+	private void addRequestProcessorMetrics(List<MetricFamilySamples> mfs) {
+		try {
+			final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
+			ObjectName filterName = new ObjectName(jmxDomain + ":type=GlobalRequestProcessor,name=*");
+			Set<ObjectInstance> mBeans = server.queryMBeans(filterName, null);
+
+			if (mBeans.size() > 0) {
+				List<String> labelNameList = Collections.singletonList("name");

Review comment:
       Done




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [openmeetings] sebawagner commented on a change in pull request #130: OPENMEETINGS-2577 performance metrics disabled state

Posted by GitBox <gi...@apache.org>.
sebawagner commented on a change in pull request #130:
URL: https://github.com/apache/openmeetings/pull/130#discussion_r580678599



##########
File path: openmeetings-web/src/main/java/org/apache/openmeetings/web/util/logging/TomcatGenericExports.java
##########
@@ -0,0 +1,305 @@
+/*
+ * 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.web.util.logging;
+
+import io.prometheus.client.Collector;
+import io.prometheus.client.CounterMetricFamily;
+import io.prometheus.client.GaugeMetricFamily;
+import org.apache.catalina.util.ServerInfo;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.management.*;
+import java.lang.management.ManagementFactory;
+import java.util.*;
+
+/**
+ * Exports Tomcat metrics applicable to most most applications:
+ *
+ * - http session metrics - request processor metrics - thread pool metrics
+ *
+ * <p>
+ * Example usage:
+ *
+ * <pre>
+ * {@code
+ *   new TomcatGenericExports(false).register();
+ * }
+ * </pre>
+ *
+ * Example metrics being exported:
+ *
+ * <pre>
+ * tomcat_info{version="7.0.61.0",build="Apr 29 2015 14:58:03 UTC",} 1.0
+ * tomcat_session_active_total{context="/foo",host="default",} 877.0
+ * tomcat_session_rejected_total{context="/foo",host="default",} 0.0
+ * tomcat_session_created_total{context="/foo",host="default",} 24428.0
+ * tomcat_session_expired_total{context="/foo",host="default",} 23832.0
+ * tomcat_session_alivetime_seconds_avg{context="/foo",host="default",} 633.0
+ * tomcat_session_alivetime_seconds_max{context="/foo",host="default",} 9883.0
+ * tomcat_requestprocessor_received_bytes{name="http-bio-0.0.0.0-8080",} 0.0
+ * tomcat_requestprocessor_sent_bytes{name="http-bio-0.0.0.0-8080",} 5056098.0
+ * tomcat_requestprocessor_time_seconds{name="http-bio-0.0.0.0-8080",} 127386.0
+ * tomcat_requestprocessor_error_count{name="http-bio-0.0.0.0-8080",} 0.0
+ * tomcat_requestprocessor_request_count{name="http-bio-0.0.0.0-8080",} 33709.0
+ * tomcat_threads_total{pool="http-bio-0.0.0.0-8080",} 10.0
+ * tomcat_threads_active_total{pool="http-bio-0.0.0.0-8080",} 2.0
+ * tomcat_threads_active_max{pool="http-bio-0.0.0.0-8080",} 200.0
+ * </pre>
+ */
+
+public class TomcatGenericExports extends Collector {
+
+	private static final Logger log = LoggerFactory.getLogger(TomcatGenericExports.class);
+	private String jmxDomain = "Catalina";
+
+	public TomcatGenericExports(boolean embedded) {
+		if (embedded) {
+			jmxDomain = "Tomcat";
+		}
+	}
+
+	private void addRequestProcessorMetrics(List<MetricFamilySamples> mfs) {
+		try {
+			final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
+			ObjectName filterName = new ObjectName(jmxDomain + ":type=GlobalRequestProcessor,name=*");
+			Set<ObjectInstance> mBeans = server.queryMBeans(filterName, null);
+
+			if (mBeans.size() > 0) {
+				List<String> labelNameList = Collections.singletonList("name");
+
+				GaugeMetricFamily requestProcessorBytesReceivedGauge = new GaugeMetricFamily(
+						"tomcat_requestprocessor_received_bytes", "Number of bytes received by this request processor",
+						labelNameList);
+
+				GaugeMetricFamily requestProcessorBytesSentGauge = new GaugeMetricFamily(
+						"tomcat_requestprocessor_sent_bytes", "Number of bytes sent by this request processor",
+						labelNameList);
+
+				GaugeMetricFamily requestProcessorProcessingTimeGauge = new GaugeMetricFamily(
+						"tomcat_requestprocessor_time_seconds", "The total time spend by this request processor",
+						labelNameList);
+
+				CounterMetricFamily requestProcessorErrorCounter = new CounterMetricFamily(
+						"tomcat_requestprocessor_error_count",
+						"The number of error request served by this request processor", labelNameList);
+
+				CounterMetricFamily requestProcessorRequestCounter = new CounterMetricFamily(
+						"tomcat_requestprocessor_request_count",
+						"The number of request served by this request processor", labelNameList);
+
+				for (final ObjectInstance mBean : mBeans) {
+					List<String> labelValueList = Collections
+							.singletonList(mBean.getObjectName().getKeyProperty("name").replaceAll("[\"\\\\]", ""));
+
+					requestProcessorBytesReceivedGauge.addMetric(labelValueList,
+							((Long) server.getAttribute(mBean.getObjectName(), "bytesReceived")).doubleValue());
+
+					requestProcessorBytesSentGauge.addMetric(labelValueList,
+							((Long) server.getAttribute(mBean.getObjectName(), "bytesSent")).doubleValue());
+
+					requestProcessorProcessingTimeGauge.addMetric(labelValueList,
+							((Long) server.getAttribute(mBean.getObjectName(), "processingTime")).doubleValue()
+									/ 1000.0);
+
+					requestProcessorErrorCounter.addMetric(labelValueList,
+							((Integer) server.getAttribute(mBean.getObjectName(), "errorCount")).doubleValue());
+
+					requestProcessorRequestCounter.addMetric(labelValueList,
+							((Integer) server.getAttribute(mBean.getObjectName(), "requestCount")).doubleValue());
+				}
+
+				mfs.add(requestProcessorBytesReceivedGauge);
+				mfs.add(requestProcessorBytesSentGauge);
+				mfs.add(requestProcessorProcessingTimeGauge);
+				mfs.add(requestProcessorRequestCounter);
+				mfs.add(requestProcessorErrorCounter);
+			}
+		} catch (Exception e) {
+			log.error("Error retrieving metric.", e);
+		}
+	}
+
+	private void addSessionMetrics(List<MetricFamilySamples> mfs) {
+		try {
+			final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
+			ObjectName filterName = new ObjectName(jmxDomain + ":type=Manager,context=*,host=*");
+			Set<ObjectInstance> mBeans = server.queryMBeans(filterName, null);
+
+			if (mBeans.size() > 0) {
+				List<String> labelNameList = Arrays.asList("host", "context");
+
+				GaugeMetricFamily activeSessionCountGauge = new GaugeMetricFamily("tomcat_session_active_total",
+						"Number of active sessions", labelNameList);
+
+				GaugeMetricFamily rejectedSessionCountGauge = new GaugeMetricFamily("tomcat_session_rejected_total",
+						"Number of sessions rejected due to maxActive being reached", labelNameList);
+
+				GaugeMetricFamily createdSessionCountGauge = new GaugeMetricFamily("tomcat_session_created_total",
+						"Number of sessions created", labelNameList);
+
+				GaugeMetricFamily expiredSessionCountGauge = new GaugeMetricFamily("tomcat_session_expired_total",
+						"Number of sessions that expired", labelNameList);
+
+				GaugeMetricFamily sessionAvgAliveTimeGauge = new GaugeMetricFamily(
+						"tomcat_session_alivetime_seconds_avg", "Average time an expired session had been alive",
+						labelNameList);
+
+				GaugeMetricFamily sessionMaxAliveTimeGauge = new GaugeMetricFamily(
+						"tomcat_session_alivetime_seconds_max", "Maximum time an expired session had been alive",
+						labelNameList);
+
+				GaugeMetricFamily contextStateGauge = new GaugeMetricFamily("tomcat_context_state_started",
+						"Indication if the lifecycle state of this context is STARTED", labelNameList);
+
+				for (final ObjectInstance mBean : mBeans) {
+					List<String> labelValueList = Arrays.asList(mBean.getObjectName().getKeyProperty("host"),
+							mBean.getObjectName().getKeyProperty("context"));
+
+					activeSessionCountGauge.addMetric(labelValueList,
+							((Integer) server.getAttribute(mBean.getObjectName(), "activeSessions")).doubleValue());
+
+					rejectedSessionCountGauge.addMetric(labelValueList,
+							((Integer) server.getAttribute(mBean.getObjectName(), "rejectedSessions")).doubleValue());
+
+					createdSessionCountGauge.addMetric(labelValueList,
+							((Long) server.getAttribute(mBean.getObjectName(), "sessionCounter")).doubleValue());
+
+					expiredSessionCountGauge.addMetric(labelValueList,
+							((Long) server.getAttribute(mBean.getObjectName(), "expiredSessions")).doubleValue());
+
+					sessionAvgAliveTimeGauge.addMetric(labelValueList,
+							((Integer) server.getAttribute(mBean.getObjectName(), "sessionAverageAliveTime"))
+									.doubleValue());
+
+					sessionMaxAliveTimeGauge.addMetric(labelValueList,
+							((Integer) server.getAttribute(mBean.getObjectName(), "sessionMaxAliveTime"))
+									.doubleValue());
+
+					if (server.getAttribute(mBean.getObjectName(), "stateName").equals("STARTED")) {
+						contextStateGauge.addMetric(labelValueList, 1.0);
+					} else {
+						contextStateGauge.addMetric(labelValueList, 0.0);
+					}
+				}
+
+				mfs.add(activeSessionCountGauge);
+				mfs.add(rejectedSessionCountGauge);
+				mfs.add(createdSessionCountGauge);
+				mfs.add(expiredSessionCountGauge);
+				mfs.add(sessionAvgAliveTimeGauge);
+				mfs.add(sessionMaxAliveTimeGauge);
+				mfs.add(contextStateGauge);
+			}
+		} catch (Exception e) {
+			log.error("Error retrieving metric.", e);
+		}
+	}
+
+	private void addThreadPoolMetrics(List<MetricFamilySamples> mfs) {
+		try {
+			final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
+			ObjectName filterName = new ObjectName(jmxDomain + ":type=ThreadPool,name=*");
+			Set<ObjectInstance> mBeans = server.queryMBeans(filterName, null);
+
+			if (mBeans.size() > 0) {
+				List<String> labelList = Collections.singletonList("name");

Review comment:
       Done

##########
File path: openmeetings-web/src/main/java/org/apache/openmeetings/web/util/logging/TomcatGenericExports.java
##########
@@ -0,0 +1,305 @@
+/*
+ * 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.web.util.logging;
+
+import io.prometheus.client.Collector;
+import io.prometheus.client.CounterMetricFamily;
+import io.prometheus.client.GaugeMetricFamily;
+import org.apache.catalina.util.ServerInfo;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.management.*;
+import java.lang.management.ManagementFactory;
+import java.util.*;
+
+/**
+ * Exports Tomcat metrics applicable to most most applications:
+ *
+ * - http session metrics - request processor metrics - thread pool metrics
+ *
+ * <p>
+ * Example usage:
+ *
+ * <pre>
+ * {@code
+ *   new TomcatGenericExports(false).register();
+ * }
+ * </pre>
+ *
+ * Example metrics being exported:
+ *
+ * <pre>
+ * tomcat_info{version="7.0.61.0",build="Apr 29 2015 14:58:03 UTC",} 1.0
+ * tomcat_session_active_total{context="/foo",host="default",} 877.0
+ * tomcat_session_rejected_total{context="/foo",host="default",} 0.0
+ * tomcat_session_created_total{context="/foo",host="default",} 24428.0
+ * tomcat_session_expired_total{context="/foo",host="default",} 23832.0
+ * tomcat_session_alivetime_seconds_avg{context="/foo",host="default",} 633.0
+ * tomcat_session_alivetime_seconds_max{context="/foo",host="default",} 9883.0
+ * tomcat_requestprocessor_received_bytes{name="http-bio-0.0.0.0-8080",} 0.0
+ * tomcat_requestprocessor_sent_bytes{name="http-bio-0.0.0.0-8080",} 5056098.0
+ * tomcat_requestprocessor_time_seconds{name="http-bio-0.0.0.0-8080",} 127386.0
+ * tomcat_requestprocessor_error_count{name="http-bio-0.0.0.0-8080",} 0.0
+ * tomcat_requestprocessor_request_count{name="http-bio-0.0.0.0-8080",} 33709.0
+ * tomcat_threads_total{pool="http-bio-0.0.0.0-8080",} 10.0
+ * tomcat_threads_active_total{pool="http-bio-0.0.0.0-8080",} 2.0
+ * tomcat_threads_active_max{pool="http-bio-0.0.0.0-8080",} 200.0
+ * </pre>
+ */
+
+public class TomcatGenericExports extends Collector {
+
+	private static final Logger log = LoggerFactory.getLogger(TomcatGenericExports.class);
+	private String jmxDomain = "Catalina";
+
+	public TomcatGenericExports(boolean embedded) {
+		if (embedded) {
+			jmxDomain = "Tomcat";
+		}
+	}
+
+	private void addRequestProcessorMetrics(List<MetricFamilySamples> mfs) {
+		try {
+			final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
+			ObjectName filterName = new ObjectName(jmxDomain + ":type=GlobalRequestProcessor,name=*");
+			Set<ObjectInstance> mBeans = server.queryMBeans(filterName, null);
+
+			if (mBeans.size() > 0) {
+				List<String> labelNameList = Collections.singletonList("name");
+
+				GaugeMetricFamily requestProcessorBytesReceivedGauge = new GaugeMetricFamily(
+						"tomcat_requestprocessor_received_bytes", "Number of bytes received by this request processor",
+						labelNameList);
+
+				GaugeMetricFamily requestProcessorBytesSentGauge = new GaugeMetricFamily(
+						"tomcat_requestprocessor_sent_bytes", "Number of bytes sent by this request processor",
+						labelNameList);
+
+				GaugeMetricFamily requestProcessorProcessingTimeGauge = new GaugeMetricFamily(
+						"tomcat_requestprocessor_time_seconds", "The total time spend by this request processor",
+						labelNameList);
+
+				CounterMetricFamily requestProcessorErrorCounter = new CounterMetricFamily(
+						"tomcat_requestprocessor_error_count",
+						"The number of error request served by this request processor", labelNameList);
+
+				CounterMetricFamily requestProcessorRequestCounter = new CounterMetricFamily(
+						"tomcat_requestprocessor_request_count",
+						"The number of request served by this request processor", labelNameList);
+
+				for (final ObjectInstance mBean : mBeans) {
+					List<String> labelValueList = Collections
+							.singletonList(mBean.getObjectName().getKeyProperty("name").replaceAll("[\"\\\\]", ""));
+
+					requestProcessorBytesReceivedGauge.addMetric(labelValueList,
+							((Long) server.getAttribute(mBean.getObjectName(), "bytesReceived")).doubleValue());
+
+					requestProcessorBytesSentGauge.addMetric(labelValueList,
+							((Long) server.getAttribute(mBean.getObjectName(), "bytesSent")).doubleValue());
+
+					requestProcessorProcessingTimeGauge.addMetric(labelValueList,
+							((Long) server.getAttribute(mBean.getObjectName(), "processingTime")).doubleValue()
+									/ 1000.0);
+
+					requestProcessorErrorCounter.addMetric(labelValueList,
+							((Integer) server.getAttribute(mBean.getObjectName(), "errorCount")).doubleValue());
+
+					requestProcessorRequestCounter.addMetric(labelValueList,
+							((Integer) server.getAttribute(mBean.getObjectName(), "requestCount")).doubleValue());
+				}
+
+				mfs.add(requestProcessorBytesReceivedGauge);
+				mfs.add(requestProcessorBytesSentGauge);
+				mfs.add(requestProcessorProcessingTimeGauge);
+				mfs.add(requestProcessorRequestCounter);
+				mfs.add(requestProcessorErrorCounter);
+			}
+		} catch (Exception e) {
+			log.error("Error retrieving metric.", e);
+		}
+	}
+
+	private void addSessionMetrics(List<MetricFamilySamples> mfs) {
+		try {
+			final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
+			ObjectName filterName = new ObjectName(jmxDomain + ":type=Manager,context=*,host=*");
+			Set<ObjectInstance> mBeans = server.queryMBeans(filterName, null);
+
+			if (mBeans.size() > 0) {
+				List<String> labelNameList = Arrays.asList("host", "context");

Review comment:
       Done




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org