Skip to content

Commit 397ee85

Browse files
committed
add client db pool metrics
1 parent c5f4e0e commit 397ee85

File tree

2 files changed

+63
-24
lines changed
  • instrumentation/jmx-metrics/library/src

2 files changed

+63
-24
lines changed

instrumentation/jmx-metrics/library/src/main/resources/jmx/rules/wildfly.yaml

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ rules:
4545
metric: request.duration.sum
4646
sourceUnit: ns
4747
unit: s
48-
desc: The total amount of time spent processing requests.
48+
desc: The total amount of time spent processing requests
4949
# wildfly.error.count
5050
errorCount:
5151
metric: error.count
5252
unit: "{request}"
53-
desc: The number of requests that have resulted in a 5xx response.
53+
desc: The number of requests that have resulted in a 5xx response
5454

5555
# wildly.network.io
5656
- bean: jboss.as:subsystem=undertow,server=*,http-listener=*
@@ -71,24 +71,33 @@ rules:
7171
metricAttribute:
7272
network.io.direction: const(receive)
7373

74-
# - bean: jboss.as:subsystem=datasources,data-source=*,statistics=pool
75-
# unit: "1"
76-
# metricAttribute:
77-
# data_source: param(data-source)
78-
# mapping:
79-
# ActiveCount:
80-
# metric: wildfly.db.client.connections.usage
81-
# metricAttribute:
82-
# state: const(used)
83-
# desc: The number of open jdbc connections
84-
# IdleCount:
85-
# metric: wildfly.db.client.connections.usage
86-
# metricAttribute:
87-
# state: const(idle)
88-
# desc: The number of open jdbc connections
89-
# WaitCount:
90-
# metric: wildfly.db.client.connections.WaitCount
91-
# type: counter
74+
- bean: jboss.as:subsystem=datasources,data-source=*,statistics=pool
75+
prefix: wildfly.db.client.connection.
76+
metricAttribute:
77+
db.client.connection.pool.name: param(data-source)
78+
mapping:
79+
# wildfly.db.client.connection.count
80+
ActiveCount:
81+
metric: &metric count
82+
type: updowncounter
83+
unit: "{connection}"
84+
desc: &desc The number of open physical database connections
85+
metricAttribute:
86+
db.client.connection.state: const(used)
87+
IdleCount:
88+
metric: *metric
89+
type: updowncounter
90+
unit: "{connection}"
91+
desc: *desc
92+
metricAttribute:
93+
db.client.connection.state: const(idle)
94+
# wildfly.db.client.connection.wait.count
95+
WaitCount:
96+
metric: wait.count
97+
type: counter
98+
# In this context, 'request' means 'connection request'
99+
unit: "{request}"
100+
desc: The number of connection requests that had to wait to obtain it
92101

93102
# - bean: jboss.as:subsystem=transactions
94103
# type: counter

instrumentation/jmx-metrics/library/src/test/java/io/opentelemetry/instrumentation/jmx/rules/WildflyTest.java

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,14 @@
2121

2222
public class WildflyTest extends TargetSystemTest {
2323

24-
private static final int WILDFLY_SERVICE_PORT = 8080;
25-
2624
@ParameterizedTest
27-
@ValueSource(strings = {"quay.io/wildfly/wildfly:32.0.1.Final-jdk11"})
25+
@ValueSource(
26+
strings = {
27+
// keep testing on old and deprecated version for compatibility
28+
"jboss/wildfly:8.2.1.Final",
29+
// recent/latest to be maintained as newer versions are released
30+
"quay.io/wildfly/wildfly:36.0.1.Final-jdk21"
31+
})
2832
public void testWildflyMetrics(String dockerImage) {
2933
List<String> yamlFiles = Collections.singletonList("wildfly.yaml");
3034

@@ -50,13 +54,17 @@ public void testWildflyMetrics(String dockerImage) {
5054
verifyMetrics(createMetricsVerifier());
5155
}
5256

57+
private static final int WILDFLY_SERVICE_PORT = 8080;
58+
5359
private static MetricsVerifier createMetricsVerifier() {
5460
AttributeMatcher deploymentAttribute = attribute("wildfly.deployment", "testapp.war");
5561
AttributeMatcher serverAttribute = attribute("wildfly.server", "default-server");
5662
AttributeMatcher listenerAttribute = attribute("wildfly.listener", "default");
5763
AttributeMatcherGroup serverListenerAttributes =
5864
attributeGroup(serverAttribute, listenerAttribute);
5965

66+
AttributeMatcher dataSourceAttribute = attribute("db.client.connection.pool.name", "ExampleDS");
67+
6068
return MetricsVerifier.create()
6169
// session metrics
6270
.add(
@@ -132,6 +140,28 @@ private static MetricsVerifier createMetricsVerifier() {
132140
attributeGroup(
133141
attribute("network.io.direction", "transmit"),
134142
serverAttribute,
135-
listenerAttribute)));
143+
listenerAttribute)))
144+
// database connection pool metrics
145+
.add(
146+
"wildfly.db.client.connection.count",
147+
metric ->
148+
metric
149+
.isUpDownCounter()
150+
.hasDescription("The number of open physical database connections")
151+
.hasUnit("{connection}")
152+
.hasDataPointsWithAttributes(
153+
attributeGroup(
154+
dataSourceAttribute, attribute("db.client.connection.state", "used")),
155+
attributeGroup(
156+
dataSourceAttribute, attribute("db.client.connection.state", "idle"))))
157+
.add(
158+
"wildfly.db.client.connection.wait.count",
159+
metric ->
160+
metric
161+
.isCounter()
162+
.hasDescription(
163+
"The number of connection requests that had to wait to obtain it")
164+
.hasUnit("{request}")
165+
.hasDataPointsWithOneAttribute(dataSourceAttribute));
136166
}
137167
}

0 commit comments

Comments
 (0)