Skip to content

Commit a04c1cf

Browse files
Bypass translator for channel metrics
1 parent 7ced8f3 commit a04c1cf

File tree

2 files changed

+113
-75
lines changed

2 files changed

+113
-75
lines changed

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

Lines changed: 88 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import com.ibm.mq.constants.CMQCFC;
2424
import com.ibm.mq.headers.pcf.PCFException;
2525
import com.ibm.mq.headers.pcf.PCFMessage;
26+
import io.opentelemetry.api.common.AttributeKey;
27+
import io.opentelemetry.api.common.Attributes;
2628
import java.util.Arrays;
2729
import java.util.List;
2830
import java.util.Set;
@@ -131,7 +133,7 @@ public void publishMetrics() {
131133
"Active Channels in queueManager {} are {}", context.getQueueManagerName(), activeChannels);
132134
Metric activeChannelsCountMetric =
133135
metricCreator.createMetric(
134-
"ActiveChannelsCount", activeChannels.size(), null, "ActiveChannelsCount");
136+
"mq.active.channels.count", activeChannels.size(), Attributes.empty());
135137
context.transformAndPrintMetric(activeChannelsCountMetric);
136138

137139
long exitTime = System.currentTimeMillis() - entryTime;
@@ -141,21 +143,91 @@ public void publishMetrics() {
141143
private @NotNull List<Metric> getMetrics(
142144
PCFMessage message, String channelName, List<String> activeChannels) throws PCFException {
143145
List<Metric> responseMetrics = Lists.newArrayList();
144-
context.forEachMetric(
145-
(metrickey, wmqOverride) -> {
146-
int metricVal = message.getIntParameterValue(wmqOverride.getConstantValue());
147-
Metric metric =
148-
metricCreator.createMetric(metrickey, metricVal, wmqOverride, channelName, metrickey);
149-
responseMetrics.add(metric);
150-
// We follow the definition of active channel as documented in
151-
// https://www.ibm.com/docs/en/ibm-mq/9.2.x?topic=states-current-active
152-
if ("Status".equals(metrickey)
153-
&& metricVal != CMQCFC.MQCHS_RETRYING
154-
&& metricVal != CMQCFC.MQCHS_STOPPED
155-
&& metricVal != CMQCFC.MQCHS_STARTING) {
156-
activeChannels.add(channelName);
157-
}
158-
});
146+
{
147+
int received = message.getIntParameterValue(CMQCFC.MQIACH_MSGS);
148+
Metric metric =
149+
metricCreator.createMetric(
150+
"mq.message.received.count",
151+
received,
152+
Attributes.of(AttributeKey.stringKey("channel.name"), channelName));
153+
responseMetrics.add(metric);
154+
}
155+
{
156+
int status = message.getIntParameterValue(CMQCFC.MQIACH_CHANNEL_STATUS);
157+
Metric metric =
158+
metricCreator.createMetric(
159+
"mq.status",
160+
status,
161+
Attributes.of(AttributeKey.stringKey("channel.name"), channelName));
162+
responseMetrics.add(metric);
163+
// We follow the definition of active channel as documented in
164+
// https://www.ibm.com/docs/en/ibm-mq/9.2.x?topic=states-current-active
165+
if (status != CMQCFC.MQCHS_RETRYING
166+
&& status != CMQCFC.MQCHS_STOPPED
167+
&& status != CMQCFC.MQCHS_STARTING) {
168+
activeChannels.add(channelName);
169+
}
170+
}
171+
{
172+
int bytesSent = message.getIntParameterValue(CMQCFC.MQIACH_BYTES_SENT);
173+
Metric metric =
174+
metricCreator.createMetric(
175+
"mq.byte.sent",
176+
bytesSent,
177+
Attributes.of(AttributeKey.stringKey("channel.name"), channelName));
178+
responseMetrics.add(metric);
179+
}
180+
{
181+
int bytesReceived = message.getIntParameterValue(CMQCFC.MQIACH_BYTES_RECEIVED);
182+
Metric metric =
183+
metricCreator.createMetric(
184+
"mq.byte.received",
185+
bytesReceived,
186+
Attributes.of(AttributeKey.stringKey("channel.name"), channelName));
187+
responseMetrics.add(metric);
188+
}
189+
{
190+
int buffersSent = message.getIntParameterValue(CMQCFC.MQIACH_BUFFERS_SENT);
191+
Metric metric =
192+
metricCreator.createMetric(
193+
"mq.buffers.sent",
194+
buffersSent,
195+
Attributes.of(AttributeKey.stringKey("channel.name"), channelName));
196+
responseMetrics.add(metric);
197+
}
198+
{
199+
int buffersReceived = message.getIntParameterValue(CMQCFC.MQIACH_BUFFERS_RECEIVED);
200+
Metric metric =
201+
metricCreator.createMetric(
202+
"mq.buffers.received",
203+
buffersReceived,
204+
Attributes.of(AttributeKey.stringKey("channel.name"), channelName));
205+
responseMetrics.add(metric);
206+
}
207+
{
208+
int currentSharingConvs = 0;
209+
if (message.getParameter(CMQCFC.MQIACH_CURRENT_SHARING_CONVS) != null) {
210+
currentSharingConvs = message.getIntParameterValue(CMQCFC.MQIACH_CURRENT_SHARING_CONVS);
211+
}
212+
Metric metric =
213+
metricCreator.createMetric(
214+
"mq.current.sharing.conversations",
215+
currentSharingConvs,
216+
Attributes.of(AttributeKey.stringKey("channel.name"), channelName));
217+
responseMetrics.add(metric);
218+
}
219+
{
220+
int maxSharingConvs = 0;
221+
if (message.getParameter(CMQCFC.MQIACH_MAX_SHARING_CONVS) != null) {
222+
maxSharingConvs = message.getIntParameterValue(CMQCFC.MQIACH_MAX_SHARING_CONVS);
223+
}
224+
Metric metric =
225+
metricCreator.createMetric(
226+
"mq.max.sharing.conversations",
227+
maxSharingConvs,
228+
Attributes.of(AttributeKey.stringKey("channel.name"), channelName));
229+
responseMetrics.add(metric);
230+
}
159231
return responseMetrics;
160232
}
161233
}

src/test/java/com/splunk/ibm/mq/metricscollector/ChannelMetricsCollectorTest.java

Lines changed: 25 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import static org.mockito.Mockito.when;
2929

3030
import com.fasterxml.jackson.databind.ObjectMapper;
31-
import com.google.common.collect.Lists;
3231
import com.ibm.mq.constants.CMQCFC;
3332
import com.ibm.mq.headers.pcf.PCFException;
3433
import com.ibm.mq.headers.pcf.PCFMessage;
@@ -100,14 +99,6 @@ void setup() throws Exception {
10099

101100
@Test
102101
void testPublishMetrics() throws Exception {
103-
List<String> metricPathsList = Lists.newArrayList();
104-
metricPathsList.add(
105-
"Server|Component:mq|Custom Metrics|WebsphereMQ|QM1|Channels|DEV.ADMIN.SVRCONN|Status");
106-
metricPathsList.add(
107-
"Server|Component:mq|Custom Metrics|WebsphereMQ|QM1|Channels|DEV.APP.SVRCONN|Status");
108-
metricPathsList.add(
109-
"Server|Component:mq|Custom Metrics|WebsphereMQ|QM1|Channels|ActiveChannelsCount");
110-
111102
when(pcfMessageAgent.send(any(PCFMessage.class)))
112103
.thenReturn(createPCFResponseForInquireChannelStatusCmd());
113104
classUnderTest = new ChannelMetricsCollector(context, metricCreator);
@@ -118,74 +109,49 @@ void testPublishMetrics() throws Exception {
118109

119110
List<List<Metric>> allValues = pathCaptor.getAllValues();
120111
assertThat(allValues).hasSize(3);
121-
assertThat(allValues.get(0)).hasSize(6);
122-
assertThat(allValues.get(1)).hasSize(6);
112+
assertThat(allValues.get(0)).hasSize(8);
113+
assertThat(allValues.get(1)).hasSize(8);
123114
assertThat(allValues.get(2)).hasSize(1);
124115

125-
assertRowWithList(allValues.get(0), "ADMIN");
126-
assertRowWithList(allValues.get(1), "APP");
116+
assertRowWithList(allValues.get(0));
117+
assertRowWithList(allValues.get(1));
127118

128119
assertThatMetric(allValues.get(2).get(0))
129-
.hasName("ActiveChannelsCount")
130-
.hasPath("Server|Component:mq|Custom Metrics|WebsphereMQ|QM1|Channels|ActiveChannelsCount")
120+
.hasName("mq.active.channels.count")
131121
.hasValue("2")
132-
.withPropertiesMatching(standardPropsForAlias("ActiveChannelsCount"));
122+
.withPropertiesMatching(standardPropsForAlias("mq.active.channels.count"));
133123
}
134124

135-
void assertRowWithList(List<Metric> metrics, String component) {
125+
void assertRowWithList(List<Metric> metrics) {
136126
assertThatMetric(metrics.get(0))
137-
.hasName("Status")
138-
.hasPath(
139-
"Server|Component:mq|Custom Metrics|WebsphereMQ|QM1|Channels|DEV."
140-
+ component
141-
+ ".SVRCONN|Status")
142-
.hasValue("3")
143-
.withPropertiesMatching(standardPropsForAlias("Status"));
127+
.hasName("mq.message.received.count")
128+
.hasValue("17")
129+
.withPropertiesMatching(standardPropsForAlias("mq.message.received.count"));
144130

145131
assertThatMetric(metrics.get(1))
146-
.hasName("Messages")
147-
.hasPath(
148-
"Server|Component:mq|Custom Metrics|WebsphereMQ|QM1|Channels|DEV."
149-
+ component
150-
+ ".SVRCONN|Messages")
151-
.hasValue("17")
152-
.withPropertiesMatching(standardPropsForAlias("Messages"));
132+
.hasName("mq.status")
133+
.hasValue("3")
134+
.withPropertiesMatching(standardPropsForAlias("mq.status"));
153135

154136
assertThatMetric(metrics.get(2))
155-
.hasName("BuffersSent")
156-
.hasPath(
157-
"Server|Component:mq|Custom Metrics|WebsphereMQ|QM1|Channels|DEV."
158-
+ component
159-
+ ".SVRCONN|BuffersSent")
160-
.hasValue("19")
161-
.withPropertiesMatching(standardPropsForAlias("Buffers Sent"));
137+
.hasName("mq.byte.sent")
138+
.hasValue("6984")
139+
.withPropertiesMatching(standardPropsForAlias("mq.byte.sent"));
162140

163141
assertThatMetric(metrics.get(3))
164-
.hasName("ByteSent")
165-
.hasPath(
166-
"Server|Component:mq|Custom Metrics|WebsphereMQ|QM1|Channels|DEV."
167-
+ component
168-
+ ".SVRCONN|ByteSent")
169-
.hasValue("6984")
170-
.withPropertiesMatching(standardPropsForAlias("Byte Sent"));
142+
.hasName("mq.byte.received")
143+
.hasValue("5772")
144+
.withPropertiesMatching(standardPropsForAlias("mq.byte.received"));
171145

172146
assertThatMetric(metrics.get(4))
173-
.hasName("BuffersReceived")
174-
.hasPath(
175-
"Server|Component:mq|Custom Metrics|WebsphereMQ|QM1|Channels|DEV."
176-
+ component
177-
+ ".SVRCONN|BuffersReceived")
178-
.hasValue("20")
179-
.withPropertiesMatching(standardPropsForAlias("Buffers Received"));
147+
.hasName("mq.buffers.sent")
148+
.hasValue("19")
149+
.withPropertiesMatching(standardPropsForAlias("mq.buffers.sent"));
180150

181151
assertThatMetric(metrics.get(5))
182-
.hasName("ByteReceived")
183-
.hasPath(
184-
"Server|Component:mq|Custom Metrics|WebsphereMQ|QM1|Channels|DEV."
185-
+ component
186-
+ ".SVRCONN|ByteReceived")
187-
.hasValue("5772")
188-
.withPropertiesMatching(standardPropsForAlias("Byte Received"));
152+
.hasName("mq.buffers.received")
153+
.hasValue("20")
154+
.withPropertiesMatching(standardPropsForAlias("mq.buffers.received"));
189155
}
190156

191157
/*

0 commit comments

Comments
 (0)