Skip to content

Commit eb4b5bd

Browse files
use native gauges
1 parent e9a8cd0 commit eb4b5bd

File tree

10 files changed

+220
-176
lines changed

10 files changed

+220
-176
lines changed

golden/data/expected.yaml

Lines changed: 63 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -2,54 +2,6 @@ resourceMetrics:
22
- resource: {}
33
scopeMetrics:
44
- metrics:
5-
- gauge:
6-
dataPoints:
7-
- asInt: "0"
8-
attributes:
9-
- key: queue.manager
10-
value:
11-
stringValue: QM1
12-
- key: topic.name
13-
value:
14-
stringValue: dev
15-
startTimeUnixNano: "1000000"
16-
timeUnixNano: "2000000"
17-
- asInt: "0"
18-
attributes:
19-
- key: queue.manager
20-
value:
21-
stringValue: QM1
22-
- key: topic.name
23-
value:
24-
stringValue: dev/
25-
startTimeUnixNano: "1000000"
26-
timeUnixNano: "2000000"
27-
name: mq.publish.count
28-
unit: "1"
29-
- gauge:
30-
dataPoints:
31-
- asInt: "0"
32-
attributes:
33-
- key: queue.manager
34-
value:
35-
stringValue: QM1
36-
- key: topic.name
37-
value:
38-
stringValue: dev
39-
startTimeUnixNano: "1000000"
40-
timeUnixNano: "2000000"
41-
- asInt: "0"
42-
attributes:
43-
- key: queue.manager
44-
value:
45-
stringValue: QM1
46-
- key: topic.name
47-
value:
48-
stringValue: dev/
49-
startTimeUnixNano: "1000000"
50-
timeUnixNano: "2000000"
51-
name: mq.subscription.count
52-
unit: "1"
535
- gauge:
546
dataPoints:
557
- asInt: "0"
@@ -1074,19 +1026,6 @@ resourceMetrics:
10741026
stringValue: QM1
10751027
startTimeUnixNano: "1000000"
10761028
timeUnixNano: "2000000"
1077-
- asInt: "109"
1078-
attributes:
1079-
- key: channel.name
1080-
value:
1081-
stringValue: DEV.ADMIN.SVRCONN
1082-
- key: channel.type
1083-
value:
1084-
stringValue: server-connection
1085-
- key: queue.manager
1086-
value:
1087-
stringValue: QM1
1088-
startTimeUnixNano: "1000000"
1089-
timeUnixNano: "2000000"
10901029
name: mq.message.received.count
10911030
- gauge:
10921031
dataPoints:
@@ -1226,6 +1165,52 @@ resourceMetrics:
12261165
startTimeUnixNano: "1000000"
12271166
timeUnixNano: "2000000"
12281167
name: mq.archive.log.size
1168+
- gauge:
1169+
dataPoints:
1170+
- asInt: "0"
1171+
attributes:
1172+
- key: queue.manager
1173+
value:
1174+
stringValue: QM1
1175+
- key: topic.name
1176+
value:
1177+
stringValue: dev
1178+
startTimeUnixNano: "1000000"
1179+
timeUnixNano: "2000000"
1180+
- asInt: "0"
1181+
attributes:
1182+
- key: queue.manager
1183+
value:
1184+
stringValue: QM1
1185+
- key: topic.name
1186+
value:
1187+
stringValue: dev/
1188+
startTimeUnixNano: "1000000"
1189+
timeUnixNano: "2000000"
1190+
name: mq.publish.count
1191+
- gauge:
1192+
dataPoints:
1193+
- asInt: "0"
1194+
attributes:
1195+
- key: queue.manager
1196+
value:
1197+
stringValue: QM1
1198+
- key: topic.name
1199+
value:
1200+
stringValue: dev
1201+
startTimeUnixNano: "1000000"
1202+
timeUnixNano: "2000000"
1203+
- asInt: "0"
1204+
attributes:
1205+
- key: queue.manager
1206+
value:
1207+
stringValue: QM1
1208+
- key: topic.name
1209+
value:
1210+
stringValue: dev/
1211+
startTimeUnixNano: "1000000"
1212+
timeUnixNano: "2000000"
1213+
name: mq.subscription.count
12291214
- gauge:
12301215
dataPoints:
12311216
- asInt: "114"
@@ -1293,6 +1278,23 @@ resourceMetrics:
12931278
startTimeUnixNano: "1000000"
12941279
timeUnixNano: "2000000"
12951280
name: mq.max.instances
1281+
- gauge:
1282+
dataPoints:
1283+
- asInt: "109"
1284+
attributes:
1285+
- key: channel.name
1286+
value:
1287+
stringValue: DEV.ADMIN.SVRCONN
1288+
- key: channel.type
1289+
value:
1290+
stringValue: server-connection
1291+
- key: queue.manager
1292+
value:
1293+
stringValue: QM1
1294+
startTimeUnixNano: "1000000"
1295+
timeUnixNano: "2000000"
1296+
name: mq.message.count
1297+
unit: "1"
12961298
- gauge:
12971299
dataPoints:
12981300
- asInt: "4200"

src/main/java/com/splunk/ibm/mq/WMQMonitorTask.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import com.splunk.ibm.mq.metricscollector.InquireQueueManagerCmdCollector;
2727
import com.splunk.ibm.mq.metricscollector.JobSubmitterContext;
2828
import com.splunk.ibm.mq.metricscollector.ListenerMetricsCollector;
29-
import com.splunk.ibm.mq.metricscollector.MetricCreator;
3029
import com.splunk.ibm.mq.metricscollector.MetricsCollectorContext;
3130
import com.splunk.ibm.mq.metricscollector.MetricsPublisherJob;
3231
import com.splunk.ibm.mq.metricscollector.PerformanceEventQueueCollector;
@@ -46,7 +45,6 @@
4645
import java.util.List;
4746
import java.util.concurrent.CountDownLatch;
4847
import java.util.concurrent.ExecutorService;
49-
import java.util.function.BiFunction;
5048
import java.util.function.Function;
5149
import org.slf4j.Logger;
5250
import org.slf4j.LoggerFactory;
@@ -239,13 +237,11 @@ private void inquireQueueMetrics(QueueCollectorSharedState sharedState, PCFMessa
239237

240238
// Inquire for listener metrics
241239
private void inquireListenerMetrics(
242-
BiFunction<MetricsCollectorContext, MetricCreator, Runnable> collectorConstructor,
243-
PCFMessageAgent agent) {
240+
Function<MetricsCollectorContext, Runnable> collectorConstructor, PCFMessageAgent agent) {
244241

245242
MetricsCollectorContext context =
246243
new MetricsCollectorContext(queueManager, agent, metricWriteHelper);
247-
MetricCreator metricCreator = new MetricCreator(queueManager.getName());
248-
Runnable metricsCollector = collectorConstructor.apply(context, metricCreator);
244+
Runnable metricsCollector = collectorConstructor.apply(context);
249245
pendingJobs.add(metricsCollector);
250246
}
251247

@@ -263,10 +259,9 @@ private void inquireTopicMetrics(
263259
// Inquire configuration-specific metrics
264260
private void inquireConfigurationMetrics(MQQueueManager mqQueueManager, PCFMessageAgent agent) {
265261

266-
MetricCreator metricCreator = new MetricCreator(queueManager.getName());
267262
ReadConfigurationEventQueueCollector collector =
268263
new ReadConfigurationEventQueueCollector(
269-
agent, mqQueueManager, queueManager, metricWriteHelper, metricCreator);
264+
agent, mqQueueManager, queueManager, metricWriteHelper);
270265
pendingJobs.add(collector);
271266
}
272267

src/main/java/com/splunk/ibm/mq/metricscollector/ChannelMetricsCollector.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public final class ChannelMetricsCollector implements Runnable {
4040
private final MetricsCollectorContext context;
4141
private final LongGauge activeChannelsGauge;
4242
private final LongGauge channelStatusGauge;
43-
private final LongGauge receivedCountGauge;
43+
private final LongGauge messageCountGauge;
4444
private final LongGauge byteSentGauge;
4545
private final LongGauge byteReceivedGauge;
4646
private final LongGauge buffersSentGauge;
@@ -69,11 +69,11 @@ public ChannelMetricsCollector(MetricsCollectorContext context) {
6969
.ofLongs()
7070
.setUnit("1")
7171
.build();
72-
this.receivedCountGauge =
72+
this.messageCountGauge =
7373
context
7474
.getMetricWriteHelper()
7575
.getMeter()
76-
.gaugeBuilder("mq.message.received.count")
76+
.gaugeBuilder("mq.message.count")
7777
.ofLongs()
7878
.setUnit("1")
7979
.build();
@@ -228,7 +228,7 @@ private void updateMetrics(
228228
throws PCFException {
229229
{
230230
int received = message.getIntParameterValue(CMQCFC.MQIACH_MSGS);
231-
receivedCountGauge.set(
231+
messageCountGauge.set(
232232
received,
233233
Attributes.of(
234234
AttributeKey.stringKey("channel.name"),

src/main/java/com/splunk/ibm/mq/metricscollector/InquireTStatusCmdCollector.java

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515
*/
1616
package com.splunk.ibm.mq.metricscollector;
1717

18-
import com.google.common.collect.Lists;
1918
import com.ibm.mq.constants.CMQC;
2019
import com.ibm.mq.constants.CMQCFC;
2120
import com.ibm.mq.headers.MQDataException;
2221
import com.ibm.mq.headers.pcf.PCFException;
2322
import com.ibm.mq.headers.pcf.PCFMessage;
2423
import io.opentelemetry.api.common.AttributeKey;
2524
import io.opentelemetry.api.common.Attributes;
25+
import io.opentelemetry.api.metrics.LongGauge;
2626
import java.io.IOException;
2727
import java.util.List;
2828
import java.util.Set;
@@ -32,14 +32,28 @@
3232
final class InquireTStatusCmdCollector implements Runnable {
3333

3434
private static final Logger logger = LoggerFactory.getLogger(InquireTStatusCmdCollector.class);
35-
private final MetricCreator metricCreator;
3635

3736
static final String COMMAND = "MQCMD_INQUIRE_TOPIC_STATUS";
3837
private final MetricsCollectorContext context;
38+
private final LongGauge publishCountGauge;
39+
private final LongGauge subscriptionCountGauge;
3940

40-
public InquireTStatusCmdCollector(MetricsCollectorContext context, MetricCreator metricCreator) {
41+
public InquireTStatusCmdCollector(MetricsCollectorContext context) {
4142
this.context = context;
42-
this.metricCreator = metricCreator;
43+
this.publishCountGauge =
44+
context
45+
.getMetricWriteHelper()
46+
.getMeter()
47+
.gaugeBuilder("mq.publish.count")
48+
.ofLongs()
49+
.build();
50+
this.subscriptionCountGauge =
51+
context
52+
.getMetricWriteHelper()
53+
.getMeter()
54+
.gaugeBuilder("mq.subscription.count")
55+
.ofLongs()
56+
.build();
4357
}
4458

4559
@Override
@@ -114,38 +128,36 @@ private void processPCFRequestAndPublishQMetrics(
114128
for (PCFMessage message : messages) {
115129
String topicName = MessageBuddy.topicName(message);
116130
logger.debug("Pulling out metrics for topic name {} for command {}", topicName, command);
117-
List<Metric> responseMetrics = extractMetrics(command, message, topicName);
118-
context.transformAndPrintMetrics(responseMetrics);
131+
extractMetrics(message, topicName);
119132
}
120133
}
121134

122-
private List<Metric> extractMetrics(String command, PCFMessage pcfMessage, String topicString)
123-
throws PCFException {
124-
List<Metric> responseMetrics = Lists.newArrayList();
135+
private void extractMetrics(PCFMessage pcfMessage, String topicString) throws PCFException {
125136
{
126137
int count = 0;
127138
if (pcfMessage.getParameter(CMQC.MQIA_PUB_COUNT) != null) {
128139
count = pcfMessage.getIntParameterValue(CMQC.MQIA_PUB_COUNT);
129140
}
130-
Metric metric =
131-
metricCreator.createMetric(
132-
"mq.publish.count",
133-
count,
134-
Attributes.of(AttributeKey.stringKey("topic.name"), topicString));
135-
responseMetrics.add(metric);
141+
publishCountGauge.set(
142+
count,
143+
Attributes.of(
144+
AttributeKey.stringKey("topic.name"),
145+
topicString,
146+
AttributeKey.stringKey("queue.manager"),
147+
context.getQueueManagerName()));
136148
}
137149
{
138150
int count = 0;
139151
if (pcfMessage.getParameter(CMQC.MQIA_SUB_COUNT) != null) {
140152
count = pcfMessage.getIntParameterValue(CMQC.MQIA_SUB_COUNT);
141153
}
142-
Metric metric =
143-
metricCreator.createMetric(
144-
"mq.subscription.count",
145-
count,
146-
Attributes.of(AttributeKey.stringKey("topic.name"), topicString));
147-
responseMetrics.add(metric);
154+
subscriptionCountGauge.set(
155+
count,
156+
Attributes.of(
157+
AttributeKey.stringKey("topic.name"),
158+
topicString,
159+
AttributeKey.stringKey("queue.manager"),
160+
context.getQueueManagerName()));
148161
}
149-
return responseMetrics;
150162
}
151163
}

0 commit comments

Comments
 (0)