-
Notifications
You must be signed in to change notification settings - Fork 969
Jmx unit semconv alignment - Tomcat #13650
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
trask
merged 31 commits into
open-telemetry:main
from
robsunday:jmx-unit-semconv-alignment
May 29, 2025
Merged
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
d081c29
add test code to test yaml jmx metrics
SylvainJuge e1f60cd
Merge branch 'main' of github.com:open-telemetry/opentelemetry-java-i…
SylvainJuge 02e8a41
Merge branch 'main' into jmx-unit-semconv-alignment
robsunday dfae1ac
Tomcat metrics updated
robsunday e272d84
Tomcat test added
robsunday 2d2c264
tomcat.active_session.count support added in test
robsunday 15ad839
Comment added to test
robsunday 297fb6b
Checkstyle error fix
robsunday e8fdc29
Attr name fixed
robsunday 185e60d
Merge branch 'main' into jmx-unit-semconv-alignment
robsunday 8a9bb0f
Test fixed.
robsunday 1cc4080
Test fixed.
robsunday 747ec32
Merge branch 'main' into jmx-unit-semconv-alignment
robsunday 816b9ed
Merge branch 'main' into jmx-unit-semconv-alignment
robsunday 910e837
Thread count related metrics fixed after code review
robsunday 0dc6775
Merge branch 'main' into jmx-unit-semconv-alignment
robsunday 1dcd568
Readme updates
robsunday 38fb785
Merge branch 'main' into jmx-unit-semconv-alignment
robsunday 99104ee
Update instrumentation/jmx-metrics/library/src/main/resources/jmx/rul…
robsunday f8cc647
Update instrumentation/jmx-metrics/library/src/main/resources/jmx/rul…
robsunday 299b35c
Code review changes
robsunday ee7faec
Fixed tomcat.md
robsunday 5bdbabd
Merge branch 'main' into jmx-unit-semconv-alignment
robsunday b5fdd29
tomcat.request.duration.total -> tomcat.request.duration.sum
robsunday 6f69f76
Merge branch 'main' into jmx-unit-semconv-alignment
robsunday c3248f1
Update instrumentation/jmx-metrics/library/tomcat.md
robsunday 7c4afcb
tomcat.request_processor.name -> tomcat.request.processor.name
robsunday aee5f06
Merge branch 'main' into jmx-unit-semconv-alignment
robsunday 616014e
Update instrumentation/jmx-metrics/library/tomcat.md
robsunday 8ad8974
Indentation fixed
robsunday 9f07105
Unit descriptions tuning
robsunday File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 0 additions & 79 deletions
79
instrumentation/jmx-metrics/javaagent/src/main/resources/jmx/rules/tomcat.yaml
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
86 changes: 86 additions & 0 deletions
86
instrumentation/jmx-metrics/library/src/main/resources/jmx/rules/tomcat.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
--- | ||
# For Tomcat, the default JMX domain is "Catalina:", however with some deployments like embedded in spring-boot | ||
# we can have the "Tomcat:" domain used, thus we use both MBean names for the metrics. | ||
|
||
rules: | ||
- beans: | ||
- Catalina:type=GlobalRequestProcessor,name=* | ||
- Tomcat:type=GlobalRequestProcessor,name=* | ||
prefix: tomcat. | ||
metricAttribute: | ||
tomcat.request.processor.name: param(name) | ||
mapping: | ||
errorCount: | ||
metric: error.count | ||
type: counter | ||
unit: "{error}" | ||
desc: The number of errors. | ||
requestCount: | ||
metric: request.count | ||
type: counter | ||
unit: "{request}" | ||
desc: The number of requests processed. | ||
maxTime: | ||
metric: request.duration.max | ||
type: gauge | ||
robsunday marked this conversation as resolved.
Show resolved
Hide resolved
|
||
sourceUnit: ms | ||
unit: s | ||
desc: The longest request processing time. | ||
processingTime: | ||
robsunday marked this conversation as resolved.
Show resolved
Hide resolved
|
||
metric: request.duration.sum | ||
type: counter | ||
sourceUnit: ms | ||
unit: s | ||
desc: Total time of processing all requests. | ||
bytesReceived: | ||
metric: &metric network.io | ||
type: &type counter | ||
unit: &unit By | ||
desc: &desc The number of bytes transmitted. | ||
metricAttribute: | ||
network.io.direction: const(receive) | ||
bytesSent: | ||
metric: *metric | ||
type: *type | ||
unit: *unit | ||
desc: *desc | ||
metricAttribute: | ||
network.io.direction: const(transmit) | ||
|
||
- beans: | ||
- Catalina:type=Manager,host=localhost,context=* | ||
- Tomcat:type=Manager,host=localhost,context=* | ||
prefix: tomcat. | ||
metricAttribute: | ||
tomcat.context: param(context) | ||
mapping: | ||
activeSessions: | ||
metric: session.active.count | ||
type: updowncounter | ||
unit: "{session}" | ||
desc: The number of currently active sessions. | ||
maxActiveSessions: | ||
metric: session.active.limit | ||
type: updowncounter | ||
unit: "{session}" | ||
desc: Maximum possible number of active sessions. | ||
|
||
- beans: | ||
- Catalina:type=ThreadPool,name=* | ||
- Tomcat:type=ThreadPool,name=* | ||
unit: "{thread}" | ||
prefix: tomcat.thread. | ||
type: updowncounter | ||
metricAttribute: | ||
tomcat.thread.pool.name: param(name) | ||
mapping: | ||
robsunday marked this conversation as resolved.
Show resolved
Hide resolved
|
||
currentThreadCount: | ||
metric: count | ||
desc: Total thread count of the thread pool. | ||
maxThreads: | ||
metric: limit | ||
desc: Maximum possible number of threads in the thread pool. | ||
currentThreadsBusy: | ||
metric: busy.count | ||
desc: Number of busy threads in the thread pool. | ||
|
||
SylvainJuge marked this conversation as resolved.
Show resolved
Hide resolved
|
154 changes: 154 additions & 0 deletions
154
...brary/src/test/java/io/opentelemetry/instrumentation/jmx/rules/TomcatIntegrationTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.jmx.rules; | ||
|
||
import static io.opentelemetry.instrumentation.jmx.rules.assertions.DataPointAttributes.attribute; | ||
import static io.opentelemetry.instrumentation.jmx.rules.assertions.DataPointAttributes.attributeGroup; | ||
import static io.opentelemetry.instrumentation.jmx.rules.assertions.DataPointAttributes.attributeWithAnyValue; | ||
|
||
import io.opentelemetry.instrumentation.jmx.rules.assertions.AttributeMatcher; | ||
import java.time.Duration; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.CsvSource; | ||
import org.testcontainers.containers.GenericContainer; | ||
import org.testcontainers.containers.wait.strategy.Wait; | ||
|
||
public class TomcatIntegrationTest extends TargetSystemTest { | ||
|
||
@ParameterizedTest | ||
@CsvSource({ | ||
"tomcat:10.0, https://tomcat.apache.org/tomcat-10.0-doc/appdev/sample/sample.war", | ||
"tomcat:9.0, https://tomcat.apache.org/tomcat-9.0-doc/appdev/sample/sample.war" | ||
}) | ||
void testCollectedMetrics(String dockerImageName, String sampleWebApplicationUrl) | ||
throws Exception { | ||
List<String> yamlFiles = Collections.singletonList("tomcat.yaml"); | ||
|
||
yamlFiles.forEach(this::validateYamlSyntax); | ||
|
||
List<String> jvmArgs = new ArrayList<>(); | ||
jvmArgs.add(javaAgentJvmArgument()); | ||
jvmArgs.addAll(javaPropertiesToJvmArgs(otelConfigProperties(yamlFiles))); | ||
|
||
// testing with a basic tomcat image as test application to capture JVM metrics | ||
GenericContainer<?> target = | ||
new GenericContainer<>(dockerImageName) | ||
.withEnv("CATALINA_OPTS", String.join(" ", jvmArgs)) | ||
.withStartupTimeout(Duration.ofMinutes(2)) | ||
.withExposedPorts(8080) | ||
.waitingFor(Wait.forListeningPorts(8080)); | ||
|
||
copyFilesToTarget(target, yamlFiles); | ||
|
||
startTarget(target); | ||
|
||
// Deploy example web application to the tomcat to enable reporting tomcat.session.active.count | ||
// metric | ||
target.execInContainer("rm", "-fr", "/usr/local/tomcat/webapps/ROOT"); | ||
target.execInContainer( | ||
"curl", sampleWebApplicationUrl, "-o", "/usr/local/tomcat/webapps/ROOT.war"); | ||
|
||
verifyMetrics(createMetricsVerifier()); | ||
} | ||
|
||
private static MetricsVerifier createMetricsVerifier() { | ||
AttributeMatcher requestProcessorNameAttribute = | ||
attribute("tomcat.request.processor.name", "\"http-nio-8080\""); | ||
AttributeMatcher threadPoolNameAttribute = | ||
attribute("tomcat.thread.pool.name", "\"http-nio-8080\""); | ||
|
||
return MetricsVerifier.create() | ||
.add( | ||
"tomcat.error.count", | ||
metric -> | ||
metric | ||
.hasDescription("The number of errors.") | ||
.hasUnit("{error}") | ||
.isCounter() | ||
.hasDataPointsWithOneAttribute(requestProcessorNameAttribute)) | ||
.add( | ||
"tomcat.request.count", | ||
metric -> | ||
metric | ||
.hasDescription("The number of requests processed.") | ||
.hasUnit("{request}") | ||
.isCounter() | ||
.hasDataPointsWithOneAttribute(requestProcessorNameAttribute)) | ||
.add( | ||
"tomcat.request.duration.max", | ||
metric -> | ||
metric | ||
.hasDescription("The longest request processing time.") | ||
.hasUnit("s") | ||
.isGauge() | ||
.hasDataPointsWithOneAttribute(requestProcessorNameAttribute)) | ||
.add( | ||
"tomcat.request.duration.sum", | ||
metric -> | ||
metric | ||
.hasDescription("Total time of processing all requests.") | ||
.hasUnit("s") | ||
.isCounter() | ||
.hasDataPointsWithOneAttribute(requestProcessorNameAttribute)) | ||
.add( | ||
"tomcat.network.io", | ||
metric -> | ||
metric | ||
.hasDescription("The number of bytes transmitted.") | ||
.hasUnit("By") | ||
.isCounter() | ||
.hasDataPointsWithAttributes( | ||
attributeGroup( | ||
attribute("network.io.direction", "receive"), | ||
requestProcessorNameAttribute), | ||
attributeGroup( | ||
attribute("network.io.direction", "transmit"), | ||
requestProcessorNameAttribute))) | ||
.add( | ||
"tomcat.session.active.count", | ||
metric -> | ||
metric | ||
.hasDescription("The number of currently active sessions.") | ||
.hasUnit("{session}") | ||
.isUpDownCounter() | ||
.hasDataPointsWithOneAttribute(attributeWithAnyValue("tomcat.context"))) | ||
.add( | ||
"tomcat.session.active.limit", | ||
metric -> | ||
metric | ||
.hasDescription("Maximum possible number of active sessions.") | ||
.hasUnit("{session}") | ||
.isUpDownCounter() | ||
.hasDataPointsWithOneAttribute(attributeWithAnyValue("tomcat.context"))) | ||
.add( | ||
"tomcat.thread.count", | ||
metric -> | ||
metric | ||
.hasDescription("Total thread count of the thread pool.") | ||
.hasUnit("{thread}") | ||
.isUpDownCounter() | ||
.hasDataPointsWithOneAttribute(threadPoolNameAttribute)) | ||
.add( | ||
"tomcat.thread.limit", | ||
metric -> | ||
metric | ||
.hasDescription("Maximum possible number of threads in the thread pool.") | ||
.hasUnit("{thread}") | ||
.isUpDownCounter() | ||
.hasDataPointsWithOneAttribute(threadPoolNameAttribute)) | ||
.add( | ||
"tomcat.thread.busy.count", | ||
metric -> | ||
metric | ||
.hasDescription("Number of busy threads in the thread pool.") | ||
.hasUnit("{thread}") | ||
.isUpDownCounter() | ||
.hasDataPointsWithOneAttribute(threadPoolNameAttribute)); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Tomcat Metrics | ||
|
||
Here is the list of metrics based on MBeans exposed by Tomcat. | ||
|
||
| Metric Name | Type | Attributes | Description | | ||
|-----------------------------|---------------|-----------------------------------------------------|--------------------------------------------------------| | ||
| tomcat.session.active.count | UpDownCounter | tomcat.context | The number of currently active sessions. | | ||
| tomcat.session.active.limit | UpDownCounter | tomcat.context | Maximum possible number of active sessions. | | ||
| tomcat.error.count | Counter | tomcat.request.processor.name | The number of errors. | | ||
| tomcat.request.count | Counter | tomcat.request.processor.name | The number of requests processed. | | ||
| tomcat.request.duration.max | Gauge | tomcat.request.processor.name | The longest request processing time. | | ||
| tomcat.request.duration.sum | Counter | tomcat.request.processor.name | Total time of processing all requests. | | ||
| tomcat.network.io | Counter | tomcat.request.processor.name, network.io.direction | The number of bytes transmitted. | | ||
| tomcat.thread.count | UpDownCounter | tomcat.thread.pool.name | Total thread count of the thread pool. | | ||
| tomcat.thread.limit | UpDownCounter | tomcat.thread.pool.name | Maximum possible number of threads in the thread pool. | | ||
| tomcat.thread.busy.count | UpDownCounter | tomcat.thread.pool.name | Number of busy threads in the thread pool. | |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.