Skip to content

Commit 0967118

Browse files
improve and align activemq classic JMX metrics with semconv (#14996)
Co-authored-by: otelbot <[email protected]>
1 parent 4671882 commit 0967118

File tree

9 files changed

+401
-91
lines changed

9 files changed

+401
-91
lines changed

instrumentation/jmx-metrics/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ $ java -javaagent:path/to/opentelemetry-javaagent.jar \
2525

2626
No targets are enabled by default. The supported target environments are listed below.
2727

28-
- [activemq](javaagent/activemq.md)
28+
- [activemq](library/activemq.md)
2929
- [camel](javaagent/camel.md)
3030
- [jetty](library/jetty.md)
3131
- [kafka-broker](javaagent/kafka-broker.md)

instrumentation/jmx-metrics/javaagent/activemq.md

Lines changed: 0 additions & 17 deletions
This file was deleted.

instrumentation/jmx-metrics/javaagent/src/main/resources/jmx/rules/activemq.yaml

Lines changed: 0 additions & 67 deletions
This file was deleted.

instrumentation/jmx-metrics/javaagent/src/test/java/io/opentelemetry/instrumentation/javaagent/jmx/JmxMetricInsightInstallerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
class JmxMetricInsightInstallerTest {
2727
private static final String PATH_TO_ALL_EXISTING_RULES = "src/main/resources/jmx/rules";
2828
private static final Set<String> FILES_TO_BE_TESTED =
29-
new HashSet<>(Arrays.asList("activemq.yaml", "camel.yaml", "kafka-broker.yaml"));
29+
new HashSet<>(Arrays.asList("camel.yaml", "kafka-broker.yaml"));
3030

3131
@Test
3232
void testToVerifyExistingRulesAreValid() throws Exception {
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# ActiveMQ Metrics
2+
3+
Here is the list of metrics based on MBeans exposed by ActiveMQ.
4+
5+
For now, only ActiveMQ classic is supported.
6+
7+
| Metric Name | Type | Unit | Attributes | Description |
8+
|-------------------------------------------|---------------|--------------|-----------------------------------------------------------------------------|-----------------------------------------------------------------------|
9+
| activemq.producer.count | UpDownCounter | {producer} | messaging.destination.name, activemq.broker.name, activemq.destination.type | The number of producers attached to this destination |
10+
| activemq.consumer.count | UpDownCounter | {consumer} | messaging.destination.name, activemq.broker.name, activemq.destination.type | The number of consumers subscribed to this destination |
11+
| activemq.destination.memory.usage | UpDownCounter | By | messaging.destination.name, activemq.broker.name, activemq.destination.type | The amount of used memory by this destination |
12+
| activemq.destination.memory.limit | UpDownCounter | By | messaging.destination.name, activemq.broker.name, activemq.destination.type | The amount of configured memory limit for this destination |
13+
| activemq.destination.temp.utilization | Gauge | 1 | messaging.destination.name, activemq.broker.name, activemq.destination.type | The fraction of non-persistent storage used by this destination |
14+
| activemq.destination.temp.limit | UpDownCounter | By | messaging.destination.name, activemq.broker.name, activemq.destination.type | The amount of configured non-persistent storage limit |
15+
| activemq.message.queue.size | UpDownCounter | {message} | messaging.destination.name, activemq.broker.name, activemq.destination.type | The current number of messages waiting to be consumed |
16+
| activemq.message.expired | Counter | {message} | messaging.destination.name, activemq.broker.name, activemq.destination.type | The number of messages not delivered because they expired |
17+
| activemq.message.enqueued | Counter | {message} | messaging.destination.name, activemq.broker.name, activemq.destination.type | The number of messages sent to this destination |
18+
| activemq.message.dequeued | Counter | {message} | messaging.destination.name, activemq.broker.name, activemq.destination.type | The number of messages acknowledged and removed from this destination |
19+
| activemq.message.enqueue.average_duration | Gauge | s | messaging.destination.name, activemq.broker.name, activemq.destination.type | The average time a message was held on this destination |
20+
| activemq.connection.count | UpDownCounter | {connection} | activemq.broker.name | The number of active connections |
21+
| activemq.memory.utilization | Gauge | 1 | activemq.broker.name | The fraction of broker memory used |
22+
| activemq.memory.limit | UpDownCounter | By | activemq.broker.name | The amount of configured broker memory limit |
23+
| activemq.store.utilization | Gauge | 1 | activemq.broker.name | The fraction of broker persistent storage used |
24+
| activemq.store.limit | UpDownCounter | By | activemq.broker.name | The amount of configured broker persistent storage limit |
25+
| activemq.temp.utilization | Gauge | 1 | activemq.broker.name | The fraction of broker non-persistent storage used |
26+
| activemq.temp.limit | UpDownCounter | By | activemq.broker.name | The amount of configured broker non-persistent storage limit |
27+
28+
## Attributes
29+
30+
- `messaging.destination.name` contains the destination.name ([semconv](https://opentelemetry.io/docs/specs/semconv/registry/attributes/messaging/#messaging-destination-name))
31+
- `activemq.broker.name` contains the name of the broker
32+
- `activemq.destination.type` is set to `queue` for queues (point-to-point), `topic` for topics (multicast).

instrumentation/jmx-metrics/library/src/main/java/io/opentelemetry/instrumentation/jmx/engine/UnitConverter.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class UnitConverter {
2222
registerConversion("ms", "s", value -> value.doubleValue() / TimeUnit.SECONDS.toMillis(1));
2323
registerConversion("us", "s", value -> value.doubleValue() / TimeUnit.SECONDS.toMicros(1));
2424
registerConversion("ns", "s", value -> value.doubleValue() / TimeUnit.SECONDS.toNanos(1));
25+
registerConversion("%", "1", value -> value.doubleValue() / 100d);
2526
}
2627

2728
private final Function<Number, Number> convertingFunction;
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
---
2+
rules:
3+
4+
# Topic and Queues level metrics
5+
- bean: org.apache.activemq:type=Broker,brokerName=*,destinationType=*,destinationName=*
6+
metricAttribute:
7+
messaging.destination.name: param(destinationName)
8+
# 'topic' or 'queue'
9+
activemq.destination.type: lowercase(param(destinationType))
10+
activemq.broker.name: param(brokerName)
11+
prefix: activemq.
12+
mapping:
13+
# activemq.producer.count
14+
ProducerCount:
15+
metric: producer.count
16+
unit: "{producer}"
17+
type: updowncounter
18+
desc: The number of producers attached to this destination
19+
# activemq.consumer.count
20+
ConsumerCount:
21+
metric: consumer.count
22+
unit: "{consumer}"
23+
type: updowncounter
24+
desc: The number of consumers subscribed to this destination
25+
# activemq.destination.memory.usage
26+
MemoryUsageByteCount:
27+
metric: destination.memory.usage
28+
unit: By
29+
type: updowncounter
30+
desc: The amount of used memory by this destination
31+
# activemq.destination.memory.limit
32+
MemoryLimit:
33+
metric: destination.memory.limit
34+
unit: By
35+
type: updowncounter
36+
desc: The amount of configured memory limit for this destination
37+
# activemq.destination.temp.utilization
38+
TempUsagePercentUsage:
39+
metric: destination.temp.utilization
40+
unit: "1"
41+
type: gauge
42+
desc: The percentage of non-persistent storage used by this destination
43+
# activemq.destination.temp.limit
44+
TempUsageLimit:
45+
metric: destination.temp.limit
46+
unit: By
47+
type: updowncounter
48+
desc: The amount of configured non-persistent storage limit for this destination
49+
# activemq.message.queue.size
50+
QueueSize:
51+
metric: message.queue.size
52+
unit: "{message}"
53+
type: updowncounter
54+
desc: The current number of messages waiting to be consumed
55+
# activemq.message.expired
56+
ExpiredCount:
57+
metric: message.expired
58+
unit: "{message}"
59+
type: counter
60+
desc: The number of messages not delivered because they expired
61+
# activemq.message.enqueued
62+
EnqueueCount:
63+
metric: message.enqueued
64+
unit: "{message}"
65+
type: counter
66+
desc: The number of messages sent to this destination
67+
# activemq.message.dequeued
68+
DequeueCount:
69+
metric: message.dequeued
70+
unit: "{message}"
71+
type: counter
72+
desc: The number of messages acknowledged and removed from this destination
73+
# activemq.message.enqueue.average_duration
74+
AverageEnqueueTime:
75+
metric: message.enqueue.average_duration
76+
sourceUnit: ms
77+
unit: s
78+
type: gauge
79+
desc: The average time a message was held on this destination
80+
81+
# Broker-level metrics
82+
- bean: org.apache.activemq:type=Broker,brokerName=*
83+
metricAttribute:
84+
activemq.broker.name: param(brokerName)
85+
prefix: activemq.
86+
mapping:
87+
# activemq.connection.count
88+
CurrentConnectionsCount:
89+
metric: connection.count
90+
type: updowncounter
91+
unit: "{connection}"
92+
desc: The number of active connections
93+
# activemq.memory.utilization
94+
MemoryPercentUsage:
95+
metric: memory.utilization
96+
type: gauge
97+
sourceUnit: "%"
98+
unit: "1"
99+
desc: The percentage of broker memory used
100+
# activemq.memory.limit
101+
MemoryLimit:
102+
metric: memory.limit
103+
type: updowncounter
104+
unit: By
105+
desc: The amount of configured broker memory limit
106+
# activemq.store.utilization
107+
StorePercentUsage:
108+
metric: store.utilization
109+
type: gauge
110+
sourceUnit: "%"
111+
unit: "1"
112+
desc: The percentage of broker persistent storage used
113+
# activemq.store.limit
114+
StoreLimit:
115+
metric: store.limit
116+
type: updowncounter
117+
unit: By
118+
desc: The amount of configured broker persistent storage limit
119+
# activemq.temp.utilization
120+
TempPercentUsage:
121+
metric: temp.utilization
122+
type: gauge
123+
sourceUnit: "%"
124+
unit: "1"
125+
desc: The percentage of broker non-persistent storage used
126+
# activemq.temp.limit
127+
TempLimit:
128+
metric: temp.limit
129+
type: updowncounter
130+
unit: By
131+
desc: The amount of configured broker non-persistent storage limit

instrumentation/jmx-metrics/library/src/test/java/io/opentelemetry/instrumentation/jmx/engine/UnitConverterTest.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,26 @@ class UnitConverterTest {
3232
})
3333
void shouldSupportPredefined_to_s_Conversions(
3434
Long originalValue, String originalUnit, Double expectedConvertedValue) {
35-
// Given
36-
String targetUnit = "s";
35+
testConversion(originalValue, originalUnit, expectedConvertedValue, "s");
36+
}
3737

38-
// When
38+
@ParameterizedTest
39+
@CsvSource({
40+
"100,1.0", "99,0.99", "1,0.01", "0,0",
41+
})
42+
void shouldSupportPredefined_percent_Conversions(
43+
Long originalValue, Double expectedConvertedValue) {
44+
testConversion(originalValue, "%", expectedConvertedValue, "1");
45+
}
46+
47+
private static void testConversion(
48+
Long originalValue, String originalUnit, Double expectedConvertedValue, String targetUnit) {
3949
UnitConverter converter = UnitConverter.getInstance(originalUnit, targetUnit);
50+
51+
assertThat(converter).isNotNull();
4052
Number actualValue = converter.convert(originalValue);
4153

42-
// Then
43-
assertEquals(expectedConvertedValue, actualValue);
54+
assertThat(expectedConvertedValue).isEqualTo(actualValue);
4455
}
4556

4657
@ParameterizedTest

0 commit comments

Comments
 (0)