@@ -6,7 +6,7 @@ storage mechanisms including Prometheus and InfluxDB.
66package mqmetric
77
88/*
9- Copyright (c) IBM Corporation 2016, 2019
9+ Copyright (c) IBM Corporation 2016, 2020
1010
1111 Licensed under the Apache License, Version 2.0 (the "License");
1212 you may not use this file except in compliance with the License.
@@ -43,6 +43,10 @@ const (
4343 ATTR_CHL_RQMNAME = "rqmname"
4444
4545 ATTR_CHL_MESSAGES = "messages"
46+ ATTR_CHL_BYTES_SENT = "bytes_sent"
47+ ATTR_CHL_BYTES_RCVD = "bytes_rcvd"
48+ ATTR_CHL_BUFFERS_SENT = "buffers_sent"
49+ ATTR_CHL_BUFFERS_RCVD = "buffers_rcvd"
4650 ATTR_CHL_BATCHES = "batches"
4751 ATTR_CHL_STATUS = "status"
4852 ATTR_CHL_STATUS_SQUASH = ATTR_CHL_STATUS + "_squash"
@@ -81,7 +85,9 @@ text. The elements can be expanded later; just trying to give a starting point
8185for now.
8286*/
8387func ChannelInitAttributes () {
88+ traceEntry ("ChannelInitAttributes" )
8489 if chlAttrsInit {
90+ traceExit ("ChannelInitAttributes" , 1 )
8591 return
8692 }
8793 ChannelStatus .Attributes = make (map [string ]* StatusAttribute )
@@ -101,6 +107,18 @@ func ChannelInitAttributes() {
101107 attr = ATTR_CHL_MESSAGES
102108 ChannelStatus .Attributes [attr ] = newStatusAttribute (attr , "Messages (API Calls for SVRCONN)" , ibmmq .MQIACH_MSGS )
103109 ChannelStatus .Attributes [attr ].delta = true // We have to manage the differences as MQ reports cumulative values
110+ attr = ATTR_CHL_BYTES_SENT
111+ ChannelStatus .Attributes [attr ] = newStatusAttribute (attr , "Bytes sent" , ibmmq .MQIACH_BYTES_SENT )
112+ ChannelStatus .Attributes [attr ].delta = true // We have to manage the differences as MQ reports cumulative values
113+ attr = ATTR_CHL_BYTES_RCVD
114+ ChannelStatus .Attributes [attr ] = newStatusAttribute (attr , "Bytes rcvd" , ibmmq .MQIACH_BYTES_RCVD )
115+ ChannelStatus .Attributes [attr ].delta = true // We have to manage the differences as MQ reports cumulative values
116+ attr = ATTR_CHL_BUFFERS_SENT
117+ ChannelStatus .Attributes [attr ] = newStatusAttribute (attr , "Buffers sent" , ibmmq .MQIACH_BUFFERS_SENT )
118+ ChannelStatus .Attributes [attr ].delta = true // We have to manage the differences as MQ reports cumulative values
119+ attr = ATTR_CHL_BUFFERS_RCVD
120+ ChannelStatus .Attributes [attr ] = newStatusAttribute (attr , "Buffers rcvd" , ibmmq .MQIACH_BUFFERS_RCVD )
121+ ChannelStatus .Attributes [attr ].delta = true // We have to manage the differences as MQ reports cumulative values
104122 attr = ATTR_CHL_BATCHES
105123 ChannelStatus .Attributes [attr ] = newStatusAttribute (attr , "Completed Batches" , ibmmq .MQIACH_BATCHES )
106124 ChannelStatus .Attributes [attr ].delta = true // We have to manage the differences as MQ reports cumulative values
@@ -156,18 +174,26 @@ func ChannelInitAttributes() {
156174 attr = ATTR_CHL_MAX_INSTC
157175 ChannelStatus .Attributes [attr ] = newStatusAttribute (attr , "MaxInstC" , - 1 )
158176
177+ traceExit ("ChannelInitAttributes" , 0 )
159178}
160179
161180// If we need to list the channels that match a pattern. Not needed for
162181// the status queries as they (unlike the pub/sub resource stats) accept
163182// patterns in the PCF command
164183func InquireChannels (patterns string ) ([]string , error ) {
184+ traceEntry ("InquireChannels" )
165185 ChannelInitAttributes ()
166- return inquireObjects (patterns , ibmmq .MQOT_CHANNEL )
186+ rc , err := inquireObjects (patterns , ibmmq .MQOT_CHANNEL )
187+
188+ traceExitErr ("InquireChannels" , 0 , err )
189+ return rc , err
167190}
168191
169192func CollectChannelStatus (patterns string ) error {
170193 var err error
194+
195+ traceEntry ("CollectChannelStatus" )
196+
171197 channelsSeen = make (map [string ]bool ) // Record which channels have been seen in this period
172198 ChannelInitAttributes ()
173199
@@ -178,6 +204,7 @@ func CollectChannelStatus(patterns string) error {
178204
179205 channelPatterns := strings .Split (patterns , "," )
180206 if len (channelPatterns ) == 0 {
207+ traceExit ("CollectChannelStatus" , 1 )
181208 return nil
182209 }
183210
@@ -245,6 +272,7 @@ func CollectChannelStatus(patterns string) error {
245272 }
246273 }
247274 }
275+ traceExitErr ("CollectChannelStatus" , 0 , err )
248276 return err
249277
250278}
@@ -253,6 +281,9 @@ func CollectChannelStatus(patterns string) error {
253281// Collect the responses and build up the statistics
254282func collectChannelStatus (pattern string , instanceType int32 ) error {
255283 var err error
284+
285+ traceEntryF ("collectChannelStatus" , "Pattern: %s" , pattern )
286+
256287 statusClearReplyQ ()
257288
258289 putmqmd , pmo , cfh , buf := statusSetCommandHeaders ()
@@ -283,6 +314,7 @@ func collectChannelStatus(pattern string, instanceType int32) error {
283314 // And now put the command to the queue
284315 err = cmdQObj .Put (putmqmd , pmo , buf )
285316 if err != nil {
317+ traceExitErr ("collectChannelStatus" , 1 , err )
286318 return err
287319 }
288320
@@ -298,13 +330,16 @@ func collectChannelStatus(pattern string, instanceType int32) error {
298330 }
299331 }
300332
333+ traceExitErr ("collectChannelStatus" , 0 , err )
301334 return err
302335}
303336
304337// Given a PCF response message, parse it to extract the desired statistics
305338func parseChlData (instanceType int32 , cfh * ibmmq.MQCFH , buf []byte ) string {
306339 var elem * ibmmq.PCFParameter
307340
341+ traceEntry ("parseChlData" )
342+
308343 chlName := ""
309344 connName := ""
310345 jobName := ""
@@ -321,6 +356,7 @@ func parseChlData(instanceType int32, cfh *ibmmq.MQCFH, buf []byte) string {
321356 offset := 0
322357 datalen := len (buf )
323358 if cfh == nil || cfh .ParameterCount == 0 {
359+ traceExit ("parseChlData" , 1 )
324360 return ""
325361 }
326362
@@ -379,6 +415,7 @@ func parseChlData(instanceType int32, cfh *ibmmq.MQCFH, buf []byte) string {
379415 for k , _ := range channelsSeen {
380416 re := regexp .MustCompile (subKey )
381417 if re .MatchString (k ) {
418+ traceExit ("parseChlData" , 2 )
382419 return ""
383420 }
384421 }
@@ -421,6 +458,7 @@ func parseChlData(instanceType int32, cfh *ibmmq.MQCFH, buf []byte) string {
421458 ChannelStatus .Attributes [ATTR_CHL_MAX_INST ].Values [key ] = newStatusValueInt64 (maxInst )
422459 }
423460
461+ traceExitF ("parseChlData" , 0 , "Key: %s" , key )
424462 return key
425463}
426464
@@ -430,6 +468,7 @@ func parseChlData(instanceType int32, cfh *ibmmq.MQCFH, buf []byte) string {
430468func ChannelNormalise (attr * StatusAttribute , v int64 ) float64 {
431469 var f float64
432470
471+ traceEntry ("ChannelNormalise" )
433472 if attr .squash {
434473 switch attr .pcfAttr {
435474
@@ -467,6 +506,9 @@ func ChannelNormalise(attr *StatusAttribute, v int64) float64 {
467506 f = 0
468507 }
469508 }
509+
510+ traceExit ("ChannelNormalise" , 0 )
511+
470512 return f
471513}
472514
@@ -476,9 +518,12 @@ func ChannelNormalise(attr *StatusAttribute, v int64) float64 {
476518func inquireChannelAttributes (objectPatternsList string , infoMap map [string ]* ObjInfo ) error {
477519 var err error
478520
521+ traceEntry ("inquireChannelAttributes" )
522+
479523 statusClearReplyQ ()
480524
481525 if objectPatternsList == "" {
526+ traceExitErr ("inquireChannelAttributes" , 1 , err )
482527 return err
483528 }
484529
@@ -528,6 +573,7 @@ func inquireChannelAttributes(objectPatternsList string, infoMap map[string]*Obj
528573 // And now put the command to the queue
529574 err = cmdQObj .Put (putmqmd , pmo , buf )
530575 if err != nil {
576+ traceExitErr ("inquireChannelAttributes" , 2 , err )
531577 return err
532578 }
533579
@@ -538,6 +584,8 @@ func inquireChannelAttributes(objectPatternsList string, infoMap map[string]*Obj
538584 }
539585 }
540586 }
587+ traceExit ("inquireChannelAttributes" , 0 )
588+
541589 return nil
542590}
543591
@@ -546,13 +594,16 @@ func parseChannelAttrData(cfh *ibmmq.MQCFH, buf []byte, infoMap map[string]*ObjI
546594 var ci * ObjInfo
547595 var ok bool
548596
597+ traceEntry ("parseChannelAttrData" )
598+
549599 chlName := ""
550600
551601 parmAvail := true
552602 bytesRead := 0
553603 offset := 0
554604 datalen := len (buf )
555605 if cfh .ParameterCount == 0 {
606+ traceExit ("parseChannelAttrData" , 1 )
556607 return
557608 }
558609 // Parse it once to extract the fields that are needed for the map key
@@ -631,6 +682,7 @@ func parseChannelAttrData(cfh *ibmmq.MQCFH, buf []byte, infoMap map[string]*ObjI
631682 }
632683 }
633684
685+ traceExit ("parseChannelAttrData" , 0 )
634686 return
635687}
636688
0 commit comments