Skip to content

Commit 35f3bf1

Browse files
committed
Discover shared queues
1 parent 9712a6b commit 35f3bf1

File tree

4 files changed

+40
-8
lines changed

4 files changed

+40
-8
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Changelog
22
Newest updates are at the top of this file.
33

4+
## January 09 2020 - v4.1.3
5+
* mqmetric - Discovery of shared queues (ibm-messaging/mq-metric-samples#26)
6+
* mqmetric - Add DESCR attribute from queues and channels to permit labelling in metrics (ibm-messaging/mq-metric-samples#16)
7+
48
## December 05 2019 - v4.1.2
59
* Update for MQ 9.1.4 - No new base API function introduced
610
* Add amqsgbr sample for browse option

mqmetric/channel.go

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ const (
6464
SQUASH_CHL_STATUS_STOPPED = 0
6565
SQUASH_CHL_STATUS_TRANSITION = 1
6666
SQUASH_CHL_STATUS_RUNNING = 2
67+
68+
DUMMY_STRING = "-" // To provide a non-empty value for certain fields
6769
)
6870

6971
var ChannelStatus StatusSet
@@ -317,9 +319,14 @@ func parseChlData(instanceType int32, cfh *ibmmq.MQCFH, buf []byte) string {
317319
}
318320

319321
// Prometheus was ignoring a blank string which then got translated into "0.00" in Grafana
320-
// So if there is no remote qmgr, force a non-empty string value in there
322+
// So if there is no remote qmgr, force a non-empty string value in there. Similarly, the jobname for
323+
// inactive channels often arrives looking like "00000" but not filling the entire length
324+
// allowed. So reset that one too.
321325
if rqmName == "" {
322-
rqmName = "-"
326+
rqmName = DUMMY_STRING
327+
}
328+
if jobName == "" || allZero(jobName) {
329+
jobName = DUMMY_STRING
323330
}
324331

325332
// Create a unique key for this channel instance
@@ -329,7 +336,7 @@ func parseChlData(instanceType int32, cfh *ibmmq.MQCFH, buf []byte) string {
329336
// the channel start timestamp. That may still be wrong if lots of channel
330337
// instances start at the same time, but it's a lot better than combining the
331338
// instances badly.
332-
if jobName == "" && platform == ibmmq.MQPL_ZOS {
339+
if jobName == DUMMY_STRING && platform == ibmmq.MQPL_ZOS {
333340
jobName = startDate + ":" + startTime
334341
}
335342
key = chlName + "/" + connName + "/" + rqmName + "/" + jobName
@@ -583,3 +590,13 @@ func parseChannelAttrData(cfh *ibmmq.MQCFH, buf []byte, infoMap map[string]*ObjI
583590

584591
return
585592
}
593+
594+
func allZero(s string) bool {
595+
rc := true
596+
for i := 0; i < len(s); i++ {
597+
if s[i] != '0' {
598+
return false
599+
}
600+
}
601+
return rc
602+
}

mqmetric/discover.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,17 @@ func inquireObjects(objectPatternsList string, objectType int32) ([]string, erro
730730
pcfparm.Int64Value = []int64{int64(ibmmq.MQQT_LOCAL)}
731731
cfh.ParameterCount++
732732
buf = append(buf, pcfparm.Bytes()...)
733+
734+
// We don't see shared queues in the returned set unless explicitly asked for.
735+
// MQQSGD_ALL returns all locals, and (if qmgr in a QSG) also shared queues.
736+
if platform == ibmmq.MQPL_ZOS {
737+
pcfparm = new(ibmmq.PCFParameter)
738+
pcfparm.Type = ibmmq.MQCFT_INTEGER
739+
pcfparm.Parameter = ibmmq.MQIA_QSG_DISP
740+
pcfparm.Int64Value = []int64{int64(ibmmq.MQQSGD_ALL)}
741+
cfh.ParameterCount++
742+
buf = append(buf, pcfparm.Bytes()...)
743+
}
733744
}
734745
// Once we know the total number of parameters, put the
735746
// CFH header on the front of the buffer.
@@ -1361,9 +1372,10 @@ func GetObjectDescription(key string, objectType int32) string {
13611372
o, ok = chlInfoMap[key]
13621373
}
13631374

1364-
if ok {
1365-
return o.Description
1375+
if !ok || strings.TrimSpace(o.Description) == "" {
1376+
// return something so Prometheus doesn't turn it into "0.0"
1377+
return "-"
13661378
} else {
1367-
return ""
1379+
return o.Description
13681380
}
13691381
}

mqmetric/queue.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@ func CollectQueueStatus(patterns string) error {
161161
if len(qName) == 0 || !qi.exists {
162162
continue
163163
}
164-
//fmt.Printf("Collecting qStatus for %s\n",qName)
165164
err = collectQueueStatus(qName, ibmmq.MQOT_Q)
166165
if err == nil && useResetQStats {
167166
err = collectResetQStats(qName)
@@ -173,6 +172,7 @@ func CollectQueueStatus(patterns string) error {
173172
if len(pattern) == 0 {
174173
continue
175174
}
175+
176176
err = collectQueueStatus(pattern, ibmmq.MQOT_Q)
177177
if err == nil && useResetQStats {
178178
err = collectResetQStats(pattern)
@@ -367,7 +367,6 @@ func parseQData(instanceType int32, cfh *ibmmq.MQCFH, buf []byte) string {
367367

368368
// Create a unique key for this instance
369369
key = qName
370-
371370
QueueStatus.Attributes[ATTR_Q_NAME].Values[key] = newStatusValueString(qName)
372371

373372
// And then re-parse the message so we can store the metrics now knowing the map key

0 commit comments

Comments
 (0)