Metrics are disable by default. The gathering of metrics as well as exposing them via HTTP for analysis needs to be enabled first.
Enable HTTP and WebService calls enable the Servlet Filter
Comment in the following block in the openmeetings/WEB-INF/web.xml
Enable Exposing the metrics and enable Tomcat generic metrics
To enable the export of the metrics as well as some generic Tomcat export (for example around active threads) you need to comment in the following block in openmeetings/WEB-INF/web.xml
This will expose the metrics at: http://$HOST:$PORT/openmeetings/services/metrics/ (be aware of the trailing "/" !)
If you plan to use this in production you need to secure that endpoint.
For example by:
- Add an auth security filter in the web.xml so you need credentials to access the endpoint
- Pointing to a private IP and putting the monitoring into a VPC
Enable metrics for streaming and other application relevant metrics
In order to get insights on the application specific logic and streaming relevant components you need to additionally enable certain annotations by commenting in openmeetings/WEB-INF/classes/applicationContext.xml
View your metrics in Prometheus
Above will enable an endpoint to publish the metrics as HTTP endpoint. You can then use Prometheus (or other tools) to read it in and graph it.
Easiest is to point to it via a Prometheus that runs in a docker container. How to startup the docker container:
Example local-prometheus.yml file to reference in above docker command (points to local running OpenMeetings instance)
Change 192.168.1.66:5080 to your local running OpenMeetings instance. Below graphs and queries are done using this docker container.
What kind of metrics are we collecting
Majority of the metrics collected (specially the below ones) are of the Prometheus type "histogram" https://prometheus.io/docs/practices/histograms/
A histogram automatically both:
- Duration (called $metricName_sum)
Initially you may find it's not quite trivial to calculate the duration for individual calls. But it makes sense once you review below. What we are interested is "rate per min" and similar statistics. Not an individual call, but rate/average over a certain period of time.
How and what to measure in metrics in OpenMeetings
There are roughly 4 categories of Metrics enabled in OpenMeetings
Basic Tomcat generics see: /openmeetings-web/src/main/java/org/apache/openmeetings/web/util/logging/TomcatGenericExports.java
HTTP request metrics -including Web Service calls- via ServletFilter
All Servlet calls, including the WebService calls are available automatically in Prometheus. They are collected by a ServletFilter and published as metrics.
Once collected in Prometheus you can filter all statistics and run queries on long running or size.
Example metrics count web service calls
Below query returns the total count of all calls using the query (below uses the wildcard on the path attribute to filter web service calls out, you could filter further if required)
Example metrics web service calls duration over 1 min time window and graphed
In order to get the duration for those calls you would take the sum (by a certain time period) divided by the count (by the same time period) and what you would get is:
Average duration within a 1min time window, for each of the calls => and graph is and you can adjust the time window also
Application metrics based on annotations in Spring Beans
For Spring Beans I've added an annotation that uses spring-aop to inject bytecode/intercept the start and end of the method (see: /openmeetings-util/src/main/java/org/apache/openmeetings/util/logging/PrometheusAspect.java)
So for any Spring Bean, you can just annotate the method with the 2 annotations I created:
I created two, cause that way you can filter them and measure database queries. (There would be a way to use JDBC interceptors, but it's quite complicated with openJPA).
See for example some annotated methods in UserDao: /openmeetings-db/src/main/java/org/apache/openmeetings/db/dao/user/UserDao.java#L626
Example metrics type database duration over 1 min rate
You can select different ones via the legend on the bottom.
Example metrics type application durations 1 min rate
Application metrics based on manual metric
This metric is currently not in use since it can't be disabled
Unfortunate not all places in the code are spring beans. Also sometimes we have inner classes or similar issues.
In that case I've added a Util that you can add at the start and end of the Method invocation, to create another metric.
At the start
At the end