Open sky333999 opened 3 months ago
Looked into the code a bit and I think I figured it out. It's because the MBean for the tomcat manager
and many others are being defined as a single bean
when in reality, the object name includes a wildcard and after performing a query against the MBean server, Catalina:type=Manager,host=localhost,context=*
resolves into multiple MBeans
Catalina:context=/shoppingcart,host=localhost,type=Manager
Catalina:context=/,host=localhost,type=Manager
What ends up happening is that the gatherer will fetch all the MBeans that match the pattern and then because it thinks it's a single MBean, it only keeps the first one.
So, the metrics don't represent an aggregated value of all the beans that match the pattern. It's just the first one, which happens to be 0.
It looks like this is a simple case of misconfiguration. The JVM metrics are defined correctly using otel.mbeans
The Tomcat metrics just need to be updated to use otel.mbeans
instead of otel.mbean
.
Not quite so simple. The gatherer needs to be updated to support aggregating metrics with the same attributes. After changing the metrics to otel.mbeans
, it's calling record
on each of the individual data points, which results in it dropping all but the first.
{"caller":"subprocess/subprocess.go:280","msg":"WARNING: Instrument tomcat.sessions has recorded multiple values for the same attributes: {}","kind":"receiver","name":"jmx","data_type":"metrics"}
Component(s)
jmx-metrics
What happened?
Description
When using tomcat as the target system for jmx-metrics,
tomcat.sessions
is always emitted as 0 despite the MXBeans showing a non-zero value for theactiveSessions
attribute.Steps to Reproduce
Spin up a tomcat server and install any sample web app that leverages sessions on it.
Create sessions and confirm by looking at the Tomcat manager that sessions is non-zero.
In this example, shoppingcart is a sample app and as can be seen, the sessions count is 1.
Use a tool such as jconsole or jmxterm to query MXBeans and confirm
activeSessions
is non-zero.The above is the output from jmxterm to query the MXBeans. As can be seen, the value matches the expectation.
tomcat.sessions
coming from jmx-metrics. For example, setup an OTel collector pipeline with a JMX receiver and debug exporter.Expected Result
I expect the value of
tomcat.sessions
as per the definition here to also be non-zero.Actual Result
The value of
tomcat.sessions
is always 0.Component version
v1.35.0
Log output
No response
Additional context
No response