23
23
import com .ibm .mq .constants .CMQCFC ;
24
24
import com .ibm .mq .headers .pcf .PCFException ;
25
25
import com .ibm .mq .headers .pcf .PCFMessage ;
26
+ import io .opentelemetry .api .common .AttributeKey ;
27
+ import io .opentelemetry .api .common .Attributes ;
26
28
import java .util .Arrays ;
27
29
import java .util .List ;
28
30
import java .util .Set ;
@@ -131,7 +133,7 @@ public void publishMetrics() {
131
133
"Active Channels in queueManager {} are {}" , context .getQueueManagerName (), activeChannels );
132
134
Metric activeChannelsCountMetric =
133
135
metricCreator .createMetric (
134
- "ActiveChannelsCount " , activeChannels .size (), null , "ActiveChannelsCount" );
136
+ "mq.active.channels.count " , activeChannels .size (), Attributes . empty () );
135
137
context .transformAndPrintMetric (activeChannelsCountMetric );
136
138
137
139
long exitTime = System .currentTimeMillis () - entryTime ;
@@ -141,21 +143,91 @@ public void publishMetrics() {
141
143
private @ NotNull List <Metric > getMetrics (
142
144
PCFMessage message , String channelName , List <String > activeChannels ) throws PCFException {
143
145
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
+ }
159
231
return responseMetrics ;
160
232
}
161
233
}
0 commit comments