You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openmeetings.apache.org by se...@apache.org on 2021/02/17 05:27:16 UTC
[openmeetings] branch
feature/OPENMEETINGS-2577-performance--metrics-disabled-state created (now
3e8b3b8)
This is an automated email from the ASF dual-hosted git repository.
sebawagner pushed a change to branch feature/OPENMEETINGS-2577-performance--metrics-disabled-state
in repository https://gitbox.apache.org/repos/asf/openmeetings.git.
at 3e8b3b8 OPENMEETINGS-2577 Fix adding Tomcat metrics as part of Metrics Servlet.
This branch includes the following new commits:
new 0a12b0f OPENMEETINGS-2577 Add aop-style Annotations and Aspect to register in Prometheus.
new ceea0dd OPENMEETINGS-2577 Add and annotate core streaming classes. Add metrics servlet. Add TomcatMetrics.
new 3e8b3b8 OPENMEETINGS-2577 Fix adding Tomcat metrics as part of Metrics Servlet.
The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
[openmeetings] 02/03: OPENMEETINGS-2577 Add and annotate core
streaming classes. Add metrics servlet. Add TomcatMetrics.
Posted by se...@apache.org.
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 ceea0ddb7f42801b1608d815392247d1a1f9b55f
Author: Sebastian Wagner <se...@gmail.com>
AuthorDate: Wed Feb 17 18:15:37 2021 +1300
OPENMEETINGS-2577 Add and annotate core streaming classes. Add metrics servlet. Add TomcatMetrics.
---
.../openmeetings/core/remote/StreamProcessor.java | 67 +++--
openmeetings-web/pom.xml | 8 +
.../web/util/logging/TomcatGenericExports.java | 306 +++++++++++++++++++++
.../webapp/WEB-INF/classes/applicationContext.xml | 3 +
openmeetings-web/src/main/webapp/WEB-INF/web.xml | 38 +++
pom.xml | 5 +
6 files changed, 402 insertions(+), 25 deletions(-)
diff --git a/openmeetings-core/src/main/java/org/apache/openmeetings/core/remote/StreamProcessor.java b/openmeetings-core/src/main/java/org/apache/openmeetings/core/remote/StreamProcessor.java
index 58eab69..0f7750d 100644
--- a/openmeetings-core/src/main/java/org/apache/openmeetings/core/remote/StreamProcessor.java
+++ b/openmeetings-core/src/main/java/org/apache/openmeetings/core/remote/StreamProcessor.java
@@ -51,6 +51,7 @@ import org.apache.openmeetings.db.entity.room.Room.RoomElement;
import org.apache.openmeetings.db.manager.IClientManager;
import org.apache.openmeetings.db.util.ws.RoomMessage;
import org.apache.openmeetings.db.util.ws.TextRoomMessage;
+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;
@@ -84,9 +85,9 @@ public class StreamProcessor implements IStreamProcessor {
@Autowired
private InterviewConverter interviewConverter;
+ @TimedApplication
void onMessage(Client c, final String cmdId, JSONObject msg) {
final String uid = msg.optString("uid");
- KStream sender;
StreamDesc sd;
Optional<StreamDesc> osd;
log.debug("Incoming message from user with ID '{}': {}", c.getUserId(), msg);
@@ -114,32 +115,10 @@ public class StreamProcessor implements IStreamProcessor {
handleBroadcastRestarted(c, uid);
break;
case "onIceCandidate":
- sender = getByUid(uid);
- if (sender != null) {
- JSONObject candidate = msg.getJSONObject(PARAM_CANDIDATE);
- String candStr = candidate.getString(PARAM_CANDIDATE);
- if (!Strings.isEmpty(candStr)) {
- IceCandidate cand = new IceCandidate(
- candStr
- , candidate.getString("sdpMid")
- , candidate.getInt("sdpMLineIndex"));
- sender.addCandidate(cand, msg.getString("luid"));
- }
- }
+ addIceCandidate(msg);
break;
case "addListener":
- sender = getByUid(msg.getString("sender"));
- if (sender != null) {
- Client sendClient = cm.getBySid(sender.getSid());
- sd = sendClient.getStream(sender.getUid());
- if (sd == null) {
- break;
- }
- if (StreamType.SCREEN == sd.getType() && sd.hasActivity(Activity.RECORD) && !sd.hasActivity(Activity.SCREEN)) {
- break;
- }
- sender.addListener(c.getSid(), c.getUid(), msg.getString("sdpOffer"));
- }
+ addListener(c, msg);
break;
case "wannaShare":
osd = c.getScreenStream();
@@ -177,6 +156,41 @@ public class StreamProcessor implements IStreamProcessor {
}
}
+ @TimedApplication
+ private void addIceCandidate(JSONObject msg) {
+ final String uid = msg.optString("uid");
+ KStream sender;
+ sender = getByUid(uid);
+ if (sender != null) {
+ JSONObject candidate = msg.getJSONObject(PARAM_CANDIDATE);
+ String candStr = candidate.getString(PARAM_CANDIDATE);
+ if (!Strings.isEmpty(candStr)) {
+ IceCandidate cand = new IceCandidate(
+ candStr
+ , candidate.getString("sdpMid")
+ , candidate.getInt("sdpMLineIndex"));
+ sender.addCandidate(cand, msg.getString("luid"));
+ }
+ }
+ }
+
+ @TimedApplication
+ private void addListener(Client c, JSONObject msg) {
+ KStream sender = getByUid(msg.getString("sender"));
+ if (sender != null) {
+ Client sendClient = cm.getBySid(sender.getSid());
+ StreamDesc sd = sendClient.getStream(sender.getUid());
+ if (sd == null) {
+ return;
+ }
+ if (StreamType.SCREEN == sd.getType() && sd.hasActivity(Activity.RECORD) && !sd.hasActivity(Activity.SCREEN)) {
+ return;
+ }
+ sender.addListener(c.getSid(), c.getUid(), msg.getString("sdpOffer"));
+ }
+ }
+
+ @TimedApplication
private void handleBroadcastRestarted(Client c, final String uid) {
if (!kHandler.isConnected()) {
return;
@@ -187,6 +201,7 @@ public class StreamProcessor implements IStreamProcessor {
}
}
+ @TimedApplication
private void handleBroadcastStarted(Client c, final String uid, JSONObject msg) {
if (!kHandler.isConnected()) {
return;
@@ -225,6 +240,7 @@ public class StreamProcessor implements IStreamProcessor {
* @param then steps need to be done after broadcast is started
* @return the current KStream
*/
+ @TimedApplication
void startBroadcast(KStream stream, StreamDesc sd, String sdpOffer, Runnable then) {
stream.startBroadcast(sd, sdpOffer, then);
}
@@ -248,6 +264,7 @@ public class StreamProcessor implements IStreamProcessor {
return closed;
}
+ @TimedApplication
public void toggleActivity(Client c, Activity a) {
log.info("PARTICIPANT {}: trying to toggle activity {}", c, a);
if (!kHandler.isConnected()) {
diff --git a/openmeetings-web/pom.xml b/openmeetings-web/pom.xml
index 39d7ee3..36c0e8f 100644
--- a/openmeetings-web/pom.xml
+++ b/openmeetings-web/pom.xml
@@ -628,6 +628,14 @@
<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>
+ </dependency>
+ <dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery-ui-touch-punch</artifactId>
<version>0.2.3-2</version>
diff --git a/openmeetings-web/src/main/java/org/apache/openmeetings/web/util/logging/TomcatGenericExports.java b/openmeetings-web/src/main/java/org/apache/openmeetings/web/util/logging/TomcatGenericExports.java
new file mode 100644
index 0000000..daf0d25
--- /dev/null
+++ b/openmeetings-web/src/main/java/org/apache/openmeetings/web/util/logging/TomcatGenericExports.java
@@ -0,0 +1,306 @@
+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.*;
+
+/*
+
+ * 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.
+ */
+/**
+ * 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");
+
+ GaugeMetricFamily threadPoolCurrentCountGauge = new GaugeMetricFamily("tomcat_threads_total",
+ "Number threads in this pool.", labelList);
+
+ GaugeMetricFamily threadPoolActiveCountGauge = new GaugeMetricFamily("tomcat_threads_active_total",
+ "Number of active threads in this pool.", labelList);
+
+ GaugeMetricFamily threadPoolMaxThreadsGauge = new GaugeMetricFamily("tomcat_threads_max",
+ "Maximum number of threads allowed in this pool.", labelList);
+
+ GaugeMetricFamily threadPoolConnectionCountGauge = new GaugeMetricFamily(
+ "tomcat_connections_active_total", "Number of connections served by this pool.", labelList);
+
+ GaugeMetricFamily threadPoolMaxConnectionGauge = new GaugeMetricFamily("tomcat_connections_active_max",
+ "Maximum number of concurrent connections served by this pool.", labelList);
+
+ String[] genericAttributes = new String[] { "currentThreadCount", "currentThreadsBusy", "maxThreads",
+ "connectionCount", "maxConnections" };
+
+ for (final ObjectInstance mBean : mBeans) {
+ List<String> labelValueList = Collections
+ .singletonList(mBean.getObjectName().getKeyProperty("name").replaceAll("[\"\\\\]", ""));
+ AttributeList attributeList = server.getAttributes(mBean.getObjectName(), genericAttributes);
+ for (Attribute attribute : attributeList.asList()) {
+ switch (attribute.getName()) {
+ case "currentThreadCount":
+ threadPoolCurrentCountGauge.addMetric(labelValueList,
+ ((Integer) attribute.getValue()).doubleValue());
+ break;
+ case "currentThreadsBusy":
+ threadPoolActiveCountGauge.addMetric(labelValueList,
+ ((Integer) attribute.getValue()).doubleValue());
+ break;
+ case "maxThreads":
+ threadPoolMaxThreadsGauge.addMetric(labelValueList,
+ ((Integer) attribute.getValue()).doubleValue());
+ break;
+ case "connectionCount":
+ threadPoolConnectionCountGauge.addMetric(labelValueList,
+ ((Long) attribute.getValue()).doubleValue());
+ break;
+ case "maxConnections":
+ threadPoolMaxConnectionGauge.addMetric(labelValueList,
+ ((Integer) attribute.getValue()).doubleValue());
+
+ }
+ }
+ }
+
+ addNonEmptyMetricFamily(mfs, threadPoolCurrentCountGauge);
+ addNonEmptyMetricFamily(mfs, threadPoolActiveCountGauge);
+ addNonEmptyMetricFamily(mfs, threadPoolMaxThreadsGauge);
+ addNonEmptyMetricFamily(mfs, threadPoolConnectionCountGauge);
+ addNonEmptyMetricFamily(mfs, threadPoolMaxConnectionGauge);
+ }
+ } catch (Exception e) {
+ log.error("Error retrieving metric:" + e.getMessage());
+ }
+ }
+
+ private void addVersionInfo(List<MetricFamilySamples> mfs) {
+ GaugeMetricFamily tomcatInfo = new GaugeMetricFamily("tomcat_info", "tomcat version info",
+ Arrays.asList("version", "build"));
+ tomcatInfo.addMetric(Arrays.asList(ServerInfo.getServerNumber(), ServerInfo.getServerBuilt()), 1);
+ mfs.add(tomcatInfo);
+ }
+
+ private void addNonEmptyMetricFamily(List<MetricFamilySamples> mfs, GaugeMetricFamily metricFamily) {
+ if (metricFamily.samples.size() > 0) {
+ mfs.add(metricFamily);
+ }
+ }
+
+ public List<MetricFamilySamples> collect() {
+ List<MetricFamilySamples> mfs = new ArrayList<MetricFamilySamples>();
+ addSessionMetrics(mfs);
+ addThreadPoolMetrics(mfs);
+ addRequestProcessorMetrics(mfs);
+ addVersionInfo(mfs);
+ return mfs;
+
+ }
+}
diff --git a/openmeetings-web/src/main/webapp/WEB-INF/classes/applicationContext.xml b/openmeetings-web/src/main/webapp/WEB-INF/classes/applicationContext.xml
index 211f0e1..64acb8d 100644
--- a/openmeetings-web/src/main/webapp/WEB-INF/classes/applicationContext.xml
+++ b/openmeetings-web/src/main/webapp/WEB-INF/classes/applicationContext.xml
@@ -22,10 +22,12 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
+ xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
+ http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"
>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
@@ -38,6 +40,7 @@
<tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true" />
<context:annotation-config />
+ <aop:aspectj-autoproxy/>
<context:component-scan base-package="org.apache.openmeetings" />
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
diff --git a/openmeetings-web/src/main/webapp/WEB-INF/web.xml b/openmeetings-web/src/main/webapp/WEB-INF/web.xml
index 62e5e2a..375c4c0 100644
--- a/openmeetings-web/src/main/webapp/WEB-INF/web.xml
+++ b/openmeetings-web/src/main/webapp/WEB-INF/web.xml
@@ -54,6 +54,35 @@
<param-value>css,docs,images,js,persistence,public,screenshare,data,services</param-value>
</init-param>
</filter>
+
+ <filter>
+ <filter-name>prometheusFilter</filter-name>
+ <filter-class>io.prometheus.client.filter.MetricsFilter</filter-class>
+ <init-param>
+ <param-name>metric-name</param-name>
+ <param-value>webapp_metrics_filter</param-value>
+ </init-param>
+ <init-param>
+ <param-name>help</param-name>
+ <param-value>This is the help for your metrics filter</param-value>
+ </init-param>
+ <init-param>
+ <param-name>buckets</param-name>
+ <param-value>0.005,0.01,0.025,0.05,0.075,0.1,0.25,0.5,0.75,1,2.5,5,7.5,10</param-value>
+ </init-param>
+ <!-- Optionally override path components; anything less than 1 (1 is the
+ default) means full granularity -->
+ <init-param>
+ <param-name>path-components</param-name>
+ <param-value>0</param-value>
+ </init-param>
+ </filter>
+
+ <filter-mapping>
+ <filter-name>prometheusFilter</filter-name>
+ <url-pattern>/*</url-pattern>
+ </filter-mapping>
+
<filter-mapping>
<filter-name>OpenmeetingsApplication</filter-name>
<url-pattern>/*</url-pattern>
@@ -78,6 +107,15 @@
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
+ <servlet>
+ <servlet-name>metrics</servlet-name>
+ <servlet-class>io.prometheus.client.exporter.MetricsServlet</servlet-class>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>metrics</servlet-name>
+ <url-pattern>/services/metrics/</url-pattern>
+ </servlet-mapping>
+
<mime-mapping>
<extension>inc</extension>
<mime-type>text/plain</mime-type>
diff --git a/pom.xml b/pom.xml
index ea2c369..47dc193 100644
--- a/pom.xml
+++ b/pom.xml
@@ -569,6 +569,11 @@
<version>${io.prometheus.version}</version>
</dependency>
<dependency>
+ <groupId>org.apache.tomcat</groupId>
+ <artifactId>tomcat-catalina</artifactId>
+ <version>${tomcat.version}</version>
+ </dependency>
+ <dependency>
<groupId>org.codehaus.jettison</groupId>
<artifactId>jettison</artifactId>
<version>${jettison.version}</version>
[openmeetings] 03/03: OPENMEETINGS-2577 Fix adding Tomcat metrics
as part of Metrics Servlet.
Posted by se...@apache.org.
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 3e8b3b8436cbd7cd50f40f07e59ab0369fd3b869
Author: Sebastian Wagner <se...@gmail.com>
AuthorDate: Wed Feb 17 18:26:56 2021 +1300
OPENMEETINGS-2577 Fix adding Tomcat metrics as part of Metrics Servlet.
---
.../util/logging/OpenMeetingsMetricsServlet.java | 32 ++++++++++++++++++++++
.../web/util/logging/TomcatGenericExports.java | 27 +++++++++---------
openmeetings-web/src/main/webapp/WEB-INF/web.xml | 2 +-
3 files changed, 46 insertions(+), 15 deletions(-)
diff --git a/openmeetings-web/src/main/java/org/apache/openmeetings/web/util/logging/OpenMeetingsMetricsServlet.java b/openmeetings-web/src/main/java/org/apache/openmeetings/web/util/logging/OpenMeetingsMetricsServlet.java
new file mode 100644
index 0000000..05c1555
--- /dev/null
+++ b/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();
+ }
+
+}
diff --git a/openmeetings-web/src/main/java/org/apache/openmeetings/web/util/logging/TomcatGenericExports.java b/openmeetings-web/src/main/java/org/apache/openmeetings/web/util/logging/TomcatGenericExports.java
index daf0d25..9d69847 100644
--- a/openmeetings-web/src/main/java/org/apache/openmeetings/web/util/logging/TomcatGenericExports.java
+++ b/openmeetings-web/src/main/java/org/apache/openmeetings/web/util/logging/TomcatGenericExports.java
@@ -1,18 +1,4 @@
-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.*;
-
/*
-
* 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
@@ -30,6 +16,19 @@ import java.util.*;
* 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:
*
diff --git a/openmeetings-web/src/main/webapp/WEB-INF/web.xml b/openmeetings-web/src/main/webapp/WEB-INF/web.xml
index 375c4c0..7bcee27 100644
--- a/openmeetings-web/src/main/webapp/WEB-INF/web.xml
+++ b/openmeetings-web/src/main/webapp/WEB-INF/web.xml
@@ -109,7 +109,7 @@
<servlet>
<servlet-name>metrics</servlet-name>
- <servlet-class>io.prometheus.client.exporter.MetricsServlet</servlet-class>
+ <servlet-class>org.apache.openmeetings.web.util.logging.OpenMeetingsMetricsServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>metrics</servlet-name>
[openmeetings] 01/03: OPENMEETINGS-2577 Add aop-style Annotations
and Aspect to register in Prometheus.
Posted by se...@apache.org.
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 <se...@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>