Skip to content

Commit 3868694

Browse files
authored
Merge pull request #155 from signalfx/start_time2
add support for channel start time in channel metrics
2 parents 9107498 + b61f846 commit 3868694

File tree

6 files changed

+86
-43
lines changed

6 files changed

+86
-43
lines changed

golden/data/expected.yaml

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ resourceMetrics:
3838
- key: channel.name
3939
value:
4040
stringValue: DEV.ADMIN.SVRCONN
41+
- key: channel.start.time
42+
value:
43+
intValue: "1748458488"
4144
- key: channel.type
4245
value:
4346
stringValue: server-connection
@@ -626,6 +629,9 @@ resourceMetrics:
626629
- key: channel.name
627630
value:
628631
stringValue: DEV.ADMIN.SVRCONN
632+
- key: channel.start.time
633+
value:
634+
intValue: "1748458488"
629635
- key: channel.type
630636
value:
631637
stringValue: server-connection
@@ -648,11 +654,14 @@ resourceMetrics:
648654
name: mq.connection.count
649655
- gauge:
650656
dataPoints:
651-
- asInt: "17160"
657+
- asInt: "17168"
652658
attributes:
653659
- key: channel.name
654660
value:
655661
stringValue: DEV.ADMIN.SVRCONN
662+
- key: channel.start.time
663+
value:
664+
intValue: "1748458488"
656665
- key: channel.type
657666
value:
658667
stringValue: server-connection
@@ -680,6 +689,9 @@ resourceMetrics:
680689
- key: channel.name
681690
value:
682691
stringValue: DEV.ADMIN.SVRCONN
692+
- key: channel.start.time
693+
value:
694+
intValue: "1748458488"
683695
- key: channel.type
684696
value:
685697
stringValue: server-connection
@@ -997,6 +1009,9 @@ resourceMetrics:
9971009
- key: channel.name
9981010
value:
9991011
stringValue: DEV.ADMIN.SVRCONN
1012+
- key: channel.start.time
1013+
value:
1014+
intValue: "1748458488"
10001015
- key: channel.type
10011016
value:
10021017
stringValue: server-connection
@@ -1014,6 +1029,9 @@ resourceMetrics:
10141029
- key: channel.name
10151030
value:
10161031
stringValue: DEV.ADMIN.SVRCONN
1032+
- key: channel.start.time
1033+
value:
1034+
intValue: "1748458488"
10171035
- key: channel.type
10181036
value:
10191037
stringValue: server-connection
@@ -1193,6 +1211,9 @@ resourceMetrics:
11931211
- key: channel.name
11941212
value:
11951213
stringValue: DEV.ADMIN.SVRCONN
1214+
- key: channel.start.time
1215+
value:
1216+
intValue: "1748458488"
11961217
- key: channel.type
11971218
value:
11981219
stringValue: server-connection
@@ -1275,6 +1296,9 @@ resourceMetrics:
12751296
- key: channel.name
12761297
value:
12771298
stringValue: DEV.ADMIN.SVRCONN
1299+
- key: channel.start.time
1300+
value:
1301+
intValue: "1748458488"
12781302
- key: channel.type
12791303
value:
12801304
stringValue: server-connection

golden/docker-compose.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ services:
4141
--ignore-timestamp
4242
--ignore-start-timestamp
4343
--timeout 2m
44+
--ignore-metric-attribute-value channel.start.time
4445
--ignore-resource-metrics-order
4546
--ignore-scope-metrics-order
4647
--ignore-metrics-order

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

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,9 @@ public void run() {
144144
CMQCFC.MQIACH_BUFFERS_SENT,
145145
CMQCFC.MQIACH_BUFFERS_RECEIVED,
146146
CMQCFC.MQIACH_CURRENT_SHARING_CONVS,
147-
CMQCFC.MQIACH_MAX_SHARING_CONVS
147+
CMQCFC.MQIACH_MAX_SHARING_CONVS,
148+
CMQCFC.MQCACH_CHANNEL_START_DATE,
149+
CMQCFC.MQCACH_CHANNEL_START_TIME
148150
};
149151
if (logger.isDebugEnabled()) {
150152
logger.debug(
@@ -189,9 +191,10 @@ public void run() {
189191
for (PCFMessage message : messages) {
190192
String channelName = MessageBuddy.channelName(message);
191193
String channelType = MessageBuddy.channelType(message);
194+
long channelStartTime = MessageBuddy.channelStartTime(message);
192195

193196
logger.debug("Pulling out metrics for channel name {}", channelName);
194-
updateMetrics(message, channelName, channelType, activeChannels);
197+
updateMetrics(message, channelName, channelType, channelStartTime, activeChannels);
195198
}
196199
} catch (PCFException pcfe) {
197200
if (pcfe.getReason() == MQRCCF_CHL_STATUS_NOT_FOUND) {
@@ -205,6 +208,8 @@ public void run() {
205208
logger.error(
206209
"Invalid metrics passed while collecting channel metrics, check config.yaml: Reason '2067'",
207210
pcfe);
211+
} else {
212+
logger.error(pcfe.getMessage(), pcfe);
208213
}
209214
} catch (Exception e) {
210215
logger.error(
@@ -224,16 +229,19 @@ public void run() {
224229
}
225230

226231
private void updateMetrics(
227-
PCFMessage message, String channelName, String channelType, List<String> activeChannels)
232+
PCFMessage message,
233+
String channelName,
234+
String channelType,
235+
long channelStartTime,
236+
List<String> activeChannels)
228237
throws PCFException {
229238
Attributes attributes =
230-
Attributes.of(
231-
AttributeKey.stringKey("channel.name"),
232-
channelName,
233-
AttributeKey.stringKey("channel.type"),
234-
channelType,
235-
AttributeKey.stringKey("queue.manager"),
236-
context.getQueueManagerName());
239+
Attributes.builder()
240+
.put("channel.name", channelName)
241+
.put("channel.type", channelType)
242+
.put("queue.manager", context.getQueueManagerName())
243+
.put("channel.start.time", channelStartTime)
244+
.build();
237245
int received = message.getIntParameterValue(CMQCFC.MQIACH_MSGS);
238246
messageCountGauge.set(received, attributes);
239247
int status = message.getIntParameterValue(CMQCFC.MQIACH_CHANNEL_STATUS);

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

Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import com.ibm.mq.headers.pcf.MQCFIL;
2121
import com.ibm.mq.headers.pcf.PCFException;
2222
import com.ibm.mq.headers.pcf.PCFMessage;
23-
import io.opentelemetry.api.common.AttributeKey;
2423
import io.opentelemetry.api.common.Attributes;
2524
import io.opentelemetry.api.metrics.LongGauge;
2625
import java.util.List;
@@ -144,41 +143,33 @@ public void run() {
144143
private void updateMetrics(PCFMessage message, String channelName, String channelType)
145144
throws PCFException {
146145
Attributes attributes =
147-
Attributes.of(
148-
AttributeKey.stringKey("channel.name"),
149-
channelName,
150-
AttributeKey.stringKey("queue.manager"),
151-
context.getQueueManagerName(),
152-
AttributeKey.stringKey("channel.type"),
153-
channelType);
154-
{
155-
int maxInstances = message.getIntParameterValue(CMQCFC.MQIACH_MAX_INSTANCES);
156-
this.maxClientsGauge.set(maxInstances, attributes);
146+
Attributes.builder()
147+
.put("channel.name", channelName)
148+
.put("channel.type", channelType)
149+
.put("queue.manager", context.getQueueManagerName())
150+
.build();
151+
if (message.getParameter(CMQCFC.MQIACH_MAX_INSTANCES) != null) {
152+
this.maxClientsGauge.set(
153+
message.getIntParameterValue(CMQCFC.MQIACH_MAX_INSTANCES), attributes);
157154
}
158-
{
159-
int maxInstancesPerClient = message.getIntParameterValue(CMQCFC.MQIACH_MAX_INSTS_PER_CLIENT);
160-
this.instancesPerClientGauge.set(maxInstancesPerClient, attributes);
155+
if (message.getParameter(CMQCFC.MQIACH_MAX_INSTS_PER_CLIENT) != null) {
156+
this.instancesPerClientGauge.set(
157+
message.getIntParameterValue(CMQCFC.MQIACH_MAX_INSTS_PER_CLIENT), attributes);
161158
}
162-
{
163-
int count = 0;
164-
if (message.getParameter(CMQCFC.MQIACH_MR_COUNT) != null) {
165-
count = message.getIntParameterValue(CMQCFC.MQIACH_MR_COUNT);
166-
}
167-
this.messageRetryCountGauge.set(count, attributes);
159+
int count = 0;
160+
if (message.getParameter(CMQCFC.MQIACH_MR_COUNT) != null) {
161+
count = message.getIntParameterValue(CMQCFC.MQIACH_MR_COUNT);
168162
}
169-
{
170-
int received = 0;
171-
if (message.getParameter(CMQCFC.MQIACH_MSGS_RECEIVED) != null) {
172-
received = message.getIntParameterValue(CMQCFC.MQIACH_MSGS_RECEIVED);
173-
}
174-
this.messageReceivedCountGauge.set(received, attributes);
163+
this.messageRetryCountGauge.set(count, attributes);
164+
int received = 0;
165+
if (message.getParameter(CMQCFC.MQIACH_MSGS_RECEIVED) != null) {
166+
received = message.getIntParameterValue(CMQCFC.MQIACH_MSGS_RECEIVED);
175167
}
176-
{
177-
int count = 0;
178-
if (message.getParameter(CMQCFC.MQIACH_MSGS_SENT) != null) {
179-
count = message.getIntParameterValue(CMQCFC.MQIACH_MSGS_SENT);
180-
}
181-
this.messageSentCountGauge.set(count, attributes);
168+
this.messageReceivedCountGauge.set(received, attributes);
169+
int sent = 0;
170+
if (message.getParameter(CMQCFC.MQIACH_MSGS_SENT) != null) {
171+
sent = message.getIntParameterValue(CMQCFC.MQIACH_MSGS_SENT);
182172
}
173+
this.messageSentCountGauge.set(sent, attributes);
183174
}
184175
}

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.ibm.mq.constants.CMQXC;
2121
import com.ibm.mq.headers.pcf.PCFException;
2222
import com.ibm.mq.headers.pcf.PCFMessage;
23+
import java.time.Instant;
2324

2425
public class MessageBuddy {
2526

@@ -47,6 +48,10 @@ static String channelType(PCFMessage message) throws PCFException {
4748
return "cluster-receiver";
4849
case CMQXC.MQCHT_CLUSSDR:
4950
return "cluster-sender";
51+
case CMQXC.MQCHT_MQTT:
52+
return "mqtt";
53+
case CMQXC.MQCHT_AMQP:
54+
return "amqp";
5055
default:
5156
throw new IllegalArgumentException(
5257
"Unsupported channel type: "
@@ -65,4 +70,12 @@ public static String listenerName(PCFMessage message) throws PCFException {
6570
public static String queueName(PCFMessage message) throws PCFException {
6671
return message.getStringParameterValue(CMQC.MQCA_Q_NAME).trim();
6772
}
73+
74+
public static long channelStartTime(PCFMessage message) throws PCFException {
75+
String date = message.getStringParameterValue(CMQCFC.MQCACH_CHANNEL_START_DATE).trim();
76+
String time = message.getStringParameterValue(CMQCFC.MQCACH_CHANNEL_START_TIME).trim();
77+
78+
Instant parsed = Instant.parse(date + "T" + time.replaceAll("\\.", ":") + "Z");
79+
return parsed.getEpochSecond();
80+
}
6881
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ private PCFMessage[] createPCFResponseForInquireChannelStatusCmd() {
166166
response1.addParameter(CMQCFC.MQIACH_MSGS, 17);
167167
response1.addParameter(CMQCFC.MQIACH_CHANNEL_STATUS, 3);
168168
response1.addParameter(CMQCFC.MQIACH_CHANNEL_SUBSTATE, 300);
169+
response1.addParameter(CMQCFC.MQCACH_CHANNEL_START_DATE, "2012-01-03");
170+
response1.addParameter(CMQCFC.MQCACH_CHANNEL_START_TIME, "22.33.44");
169171

170172
PCFMessage response2 = new PCFMessage(2, CMQCFC.MQCMD_INQUIRE_CHANNEL_STATUS, 2, true);
171173
response2.addParameter(CMQCFC.MQCACH_CHANNEL_NAME, "DEV.APP.SVRCONN");
@@ -179,6 +181,8 @@ private PCFMessage[] createPCFResponseForInquireChannelStatusCmd() {
179181
response2.addParameter(CMQCFC.MQIACH_MSGS, 17);
180182
response2.addParameter(CMQCFC.MQIACH_CHANNEL_STATUS, 3);
181183
response2.addParameter(CMQCFC.MQIACH_CHANNEL_SUBSTATE, 300);
184+
response2.addParameter(CMQCFC.MQCACH_CHANNEL_START_DATE, "2012-01-04");
185+
response2.addParameter(CMQCFC.MQCACH_CHANNEL_START_TIME, "22.33.45");
182186

183187
PCFMessage response3 = new PCFMessage(2, CMQCFC.MQCMD_INQUIRE_CHANNEL_STATUS, 2, true);
184188
response3.addParameter(CMQCFC.MQCACH_CHANNEL_NAME, "TEST.APP.SVRCONN");
@@ -192,6 +196,8 @@ private PCFMessage[] createPCFResponseForInquireChannelStatusCmd() {
192196
response3.addParameter(CMQCFC.MQIACH_MSGS, 17);
193197
response3.addParameter(CMQCFC.MQIACH_CHANNEL_STATUS, 3);
194198
response3.addParameter(CMQCFC.MQIACH_CHANNEL_SUBSTATE, 300);
199+
response3.addParameter(CMQCFC.MQCACH_CHANNEL_START_DATE, "2012-01-05");
200+
response3.addParameter(CMQCFC.MQCACH_CHANNEL_START_TIME, "22.33.46");
195201

196202
return new PCFMessage[] {response1, response2, response3};
197203
}

0 commit comments

Comments
 (0)