Skip to content

Commit 7fae626

Browse files
committed
feat: Add showCustomAttribute filter config setting to include the CUSTOM attribute as tag/label
Adds new `filters.showCustomAttribute` config setting to add the CUSTOM attribute data from a queue manager or queue as metrics tag/label.
1 parent e70e256 commit 7fae626

File tree

16 files changed

+180
-3
lines changed

16 files changed

+180
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Newest updates are at the top of this file.
44
### Unreleased
55
* Fix boolean logic for `isFirstCollection` in `mq_prometheus (#385)`
66
* Ensure proper collection on the first poll and at regular intervals thereafter
7+
* Add showCustomAttribute filter config setting to include the CUSTOM attribute as metric tag/label
78

89
### Feb 28 2025 (v5.6.2)
910
* Update to MQ 9.4.2

cmd/mq_aws/exporter.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,9 @@ func Collect() error {
251251
if hostname != mqmetric.DUMMY_STRING {
252252
tags["hostname"] = hostname
253253
}
254+
if showAndSupportsCustomLabel() {
255+
tags["custom"] = mqmetric.GetObjectCustom("", ibmmq.MQOT_Q_MGR)
256+
}
254257
} else if strings.HasPrefix(key, mqmetric.NativeHAKeyPrefix) {
255258
series = "nha"
256259
tags["nha"] = strings.Replace(key, mqmetric.NativeHAKeyPrefix, "", -1)
@@ -270,6 +273,9 @@ func Collect() error {
270273
tags["usage"] = usage
271274
tags["description"] = mqmetric.GetObjectDescription(key, ibmmq.MQOT_Q)
272275
tags["cluster"] = mqmetric.GetQueueAttribute(key, ibmmq.MQCA_CLUSTER_NAME)
276+
if showAndSupportsCustomLabel() {
277+
tags["custom"] = mqmetric.GetObjectCustom(key, ibmmq.MQOT_Q)
278+
}
273279
}
274280
addMetaLabels(tags)
275281

@@ -351,6 +357,9 @@ func Collect() error {
351357
tags["usage"] = usage
352358
tags["description"] = mqmetric.GetObjectDescription(key, ibmmq.MQOT_Q)
353359
tags["cluster"] = mqmetric.GetQueueAttribute(key, ibmmq.MQCA_CLUSTER_NAME)
360+
if showAndSupportsCustomLabel() {
361+
tags["custom"] = mqmetric.GetObjectCustom(key, ibmmq.MQOT_Q)
362+
}
354363
addMetaLabels(tags)
355364

356365
f := mqmetric.QueueNormalise(attr, value.ValueInt64)
@@ -476,6 +485,9 @@ func Collect() error {
476485
if hostname != mqmetric.DUMMY_STRING {
477486
tags["hostname"] = hostname
478487
}
488+
if showAndSupportsCustomLabel() {
489+
tags["custom"] = mqmetric.GetObjectCustom("", ibmmq.MQOT_Q_MGR)
490+
}
479491
addMetaLabels(tags)
480492

481493
f := mqmetric.QueueManagerNormalise(attr, value.ValueInt64)
@@ -640,3 +652,7 @@ func addMetaLabels(tags map[string]string) {
640652
}
641653
}
642654
}
655+
656+
func showAndSupportsCustomLabel() bool {
657+
return config.cf.CC.ShowCustomAttribute
658+
}

cmd/mq_coll/exporter.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,9 @@ func Collect() error {
205205
if hostname != mqmetric.DUMMY_STRING {
206206
tags["hostname"] = hostname
207207
}
208+
if showAndSupportsCustomLabel() {
209+
tags["custom"] = mqmetric.GetObjectCustom("", ibmmq.MQOT_Q_MGR)
210+
}
208211
} else if strings.HasPrefix(key, mqmetric.NativeHAKeyPrefix) {
209212
series = "nha"
210213
tags["nha"] = strings.Replace(key, mqmetric.NativeHAKeyPrefix, "", -1)
@@ -223,6 +226,9 @@ func Collect() error {
223226
tags["usage"] = usage
224227
tags["description"] = mqmetric.GetObjectDescription(key, ibmmq.MQOT_Q)
225228
tags["cluster"] = mqmetric.GetQueueAttribute(key, ibmmq.MQCA_CLUSTER_NAME)
229+
if showAndSupportsCustomLabel() {
230+
tags["custom"] = mqmetric.GetObjectCustom(key, ibmmq.MQOT_Q)
231+
}
226232
}
227233
addMetaLabels(tags)
228234

@@ -290,6 +296,9 @@ func Collect() error {
290296
tags["usage"] = usage
291297
tags["description"] = mqmetric.GetObjectDescription(key, ibmmq.MQOT_Q)
292298
tags["cluster"] = mqmetric.GetQueueAttribute(key, ibmmq.MQCA_CLUSTER_NAME)
299+
if showAndSupportsCustomLabel() {
300+
tags["custom"] = mqmetric.GetObjectCustom(key, ibmmq.MQOT_Q)
301+
}
293302
addMetaLabels(tags)
294303

295304
f := mqmetric.QueueNormalise(attr, value.ValueInt64)
@@ -389,6 +398,9 @@ func Collect() error {
389398
if hostname != mqmetric.DUMMY_STRING {
390399
tags["hostname"] = hostname
391400
}
401+
if showAndSupportsCustomLabel() {
402+
tags["custom"] = mqmetric.GetObjectCustom("", ibmmq.MQOT_Q_MGR)
403+
}
392404
addMetaLabels(tags)
393405

394406
f := mqmetric.QueueManagerNormalise(attr, value.ValueInt64)
@@ -530,3 +542,7 @@ func addMetaLabels(tags map[string]string) {
530542
}
531543
}
532544
}
545+
546+
func showAndSupportsCustomLabel() bool {
547+
return config.cf.CC.ShowCustomAttribute
548+
}

cmd/mq_influx/exporter.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,9 @@ func Collect(c client.Client) error {
236236
if hostname != mqmetric.DUMMY_STRING {
237237
tags["hostname"] = hostname
238238
}
239+
if showAndSupportsCustomLabel() {
240+
tags["custom"] = mqmetric.GetObjectCustom("", ibmmq.MQOT_Q_MGR)
241+
}
239242
} else if strings.HasPrefix(key, mqmetric.NativeHAKeyPrefix) {
240243
series = "nha"
241244
tags["nha"] = strings.Replace(key, mqmetric.NativeHAKeyPrefix, "", -1)
@@ -255,6 +258,9 @@ func Collect(c client.Client) error {
255258
tags["usage"] = usage
256259
tags["description"] = mqmetric.GetObjectDescription(key, ibmmq.MQOT_Q)
257260
tags["cluster"] = mqmetric.GetQueueAttribute(key, ibmmq.MQCA_CLUSTER_NAME)
261+
if showAndSupportsCustomLabel() {
262+
tags["custom"] = mqmetric.GetObjectCustom(key, ibmmq.MQOT_Q)
263+
}
258264
addMetaLabels(tags)
259265

260266
}
@@ -329,6 +335,9 @@ func Collect(c client.Client) error {
329335
tags["usage"] = usage
330336
tags["description"] = mqmetric.GetObjectDescription(key, ibmmq.MQOT_Q)
331337
tags["cluster"] = mqmetric.GetQueueAttribute(key, ibmmq.MQCA_CLUSTER_NAME)
338+
if showAndSupportsCustomLabel() {
339+
tags["custom"] = mqmetric.GetObjectCustom(key, ibmmq.MQOT_Q)
340+
}
332341
addMetaLabels(tags)
333342

334343
f := mqmetric.QueueNormalise(attr, value.ValueInt64)
@@ -447,6 +456,9 @@ func Collect(c client.Client) error {
447456
if hostname != mqmetric.DUMMY_STRING {
448457
tags["hostname"] = hostname
449458
}
459+
if showAndSupportsCustomLabel() {
460+
tags["custom"] = mqmetric.GetObjectCustom("", ibmmq.MQOT_Q_MGR)
461+
}
450462
addMetaLabels(tags)
451463

452464
f := mqmetric.QueueManagerNormalise(attr, value.ValueInt64)
@@ -574,3 +586,7 @@ func addMetaLabels(tags map[string]string) {
574586
}
575587
}
576588
}
589+
590+
func showAndSupportsCustomLabel() bool {
591+
return config.cf.CC.ShowCustomAttribute
592+
}

cmd/mq_json/exporter.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,9 @@ func Collect() error {
233233
if hostname != mqmetric.DUMMY_STRING {
234234
pt.Tags["hostname"] = hostname
235235
}
236+
if showAndSupportsCustomLabel() {
237+
pt.Tags["custom"] = mqmetric.GetObjectCustom("", ibmmq.MQOT_Q_MGR)
238+
}
236239
} else if strings.HasPrefix(key, mqmetric.NativeHAKeyPrefix) {
237240
pt.Tags["nha"] = strings.Replace(key, mqmetric.NativeHAKeyPrefix, "", -1)
238241
pt.ObjectType = "nha"
@@ -244,7 +247,9 @@ func Collect() error {
244247
pt.ObjectType = "queue"
245248
pt.Tags["description"] = mqmetric.GetObjectDescription(key, ibmmq.MQOT_Q)
246249
pt.Tags["cluster"] = mqmetric.GetQueueAttribute(key, ibmmq.MQCA_CLUSTER_NAME)
247-
250+
if showAndSupportsCustomLabel() {
251+
pt.Tags["custom"] = mqmetric.GetObjectCustom(key, ibmmq.MQOT_Q)
252+
}
248253
}
249254
addMetaLabels(pt.Tags)
250255
}
@@ -327,6 +332,9 @@ func Collect() error {
327332
pt.Tags["queue"] = qName
328333
pt.Tags["usage"] = usageString
329334
pt.Tags["description"] = mqmetric.GetObjectDescription(qName, ibmmq.MQOT_Q)
335+
if showAndSupportsCustomLabel() {
336+
pt.Tags["custom"] = mqmetric.GetObjectCustom(qName, ibmmq.MQOT_Q)
337+
}
330338
pt.Tags["cluster"] = mqmetric.GetQueueAttribute(key, ibmmq.MQCA_CLUSTER_NAME)
331339
pt.Tags["platform"] = platformString
332340
addMetaLabels(pt.Tags)
@@ -382,6 +390,9 @@ func Collect() error {
382390
pt.Tags["qmgr"] = strings.TrimSpace(qMgrName)
383391
pt.Tags["platform"] = platformString
384392
pt.Tags["description"] = mqmetric.GetObjectDescription("", ibmmq.MQOT_Q_MGR)
393+
if showAndSupportsCustomLabel() {
394+
pt.Tags["custom"] = mqmetric.GetObjectCustom("", ibmmq.MQOT_Q_MGR)
395+
}
385396
hostname := mqmetric.GetQueueManagerAttribute(config.cf.QMgrName, ibmmq.MQCACF_HOST_NAME)
386397
if hostname != mqmetric.DUMMY_STRING {
387398
pt.Tags["hostname"] = hostname
@@ -650,3 +661,7 @@ func addMetaLabels(tags map[string]string) {
650661
}
651662
}
652663
}
664+
665+
func showAndSupportsCustomLabel() bool {
666+
return config.cf.CC.ShowCustomAttribute
667+
}

cmd/mq_opentsdb/exporter.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,9 @@ func Collect() error {
236236
if hostname != mqmetric.DUMMY_STRING {
237237
tags["hostname"] = hostname
238238
}
239+
if showAndSupportsCustomLabel() {
240+
tags["custom"] = mqmetric.GetObjectCustom("", ibmmq.MQOT_Q_MGR)
241+
}
239242
} else if strings.HasPrefix(key, mqmetric.NativeHAKeyPrefix) {
240243
series = "nha"
241244
tags["nha"] = strings.Replace(key, mqmetric.NativeHAKeyPrefix, "", -1)
@@ -254,7 +257,9 @@ func Collect() error {
254257
tags["usage"] = usage
255258
tags["description"] = mqmetric.GetObjectDescription(key, ibmmq.MQOT_Q)
256259
tags["cluster"] = mqmetric.GetQueueAttribute(key, ibmmq.MQCA_CLUSTER_NAME)
257-
260+
if showAndSupportsCustomLabel() {
261+
tags["custom"] = mqmetric.GetObjectCustom(key, ibmmq.MQOT_Q)
262+
}
258263
}
259264
addMetaLabels(tags)
260265

@@ -335,6 +340,9 @@ func Collect() error {
335340
tags["usage"] = usage
336341
tags["description"] = mqmetric.GetObjectDescription(key, ibmmq.MQOT_Q)
337342
tags["cluster"] = mqmetric.GetQueueAttribute(key, ibmmq.MQCA_CLUSTER_NAME)
343+
if showAndSupportsCustomLabel() {
344+
tags["custom"] = mqmetric.GetObjectCustom(key, ibmmq.MQOT_Q)
345+
}
338346
addMetaLabels(tags)
339347

340348
f := mqmetric.QueueNormalise(attr, value.ValueInt64)
@@ -457,6 +465,9 @@ func Collect() error {
457465
if hostname != mqmetric.DUMMY_STRING {
458466
tags["hostname"] = hostname
459467
}
468+
if showAndSupportsCustomLabel() {
469+
tags["custom"] = mqmetric.GetObjectCustom("", ibmmq.MQOT_Q_MGR)
470+
}
460471
addMetaLabels(tags)
461472

462473
f := mqmetric.QueueManagerNormalise(attr, value.ValueInt64)
@@ -662,3 +673,7 @@ func addMetaLabels(tags map[string]string) {
662673
}
663674
}
664675
}
676+
677+
func showAndSupportsCustomLabel() bool {
678+
return config.cf.CC.ShowCustomAttribute
679+
}

cmd/mq_otel/reader.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,9 @@ func GetMetrics(ctx context.Context, meter metric.Meter) error {
361361
if hostname != mqmetric.DUMMY_STRING {
362362
tags["hostname"] = hostname
363363
}
364+
if showAndSupportsCustomLabel() {
365+
tags["custom"] = mqmetric.GetObjectCustom("", ibmmq.MQOT_Q_MGR)
366+
}
364367
} else if strings.HasPrefix(key, mqmetric.NativeHAKeyPrefix) {
365368
series = "nha"
366369
tags["nha"] = strings.Replace(key, mqmetric.NativeHAKeyPrefix, "", -1)
@@ -379,6 +382,9 @@ func GetMetrics(ctx context.Context, meter metric.Meter) error {
379382
tags["usage"] = usage
380383
tags["description"] = mqmetric.GetObjectDescription(key, ibmmq.MQOT_Q)
381384
tags["cluster"] = mqmetric.GetQueueAttribute(key, ibmmq.MQCA_CLUSTER_NAME)
385+
if showAndSupportsCustomLabel() {
386+
tags["custom"] = mqmetric.GetObjectCustom(key, ibmmq.MQOT_Q)
387+
}
382388
}
383389

384390
addMetaLabels(tags)
@@ -413,6 +419,9 @@ func GetMetrics(ctx context.Context, meter metric.Meter) error {
413419
tags["usage"] = usage
414420
tags["description"] = mqmetric.GetObjectDescription(key, ibmmq.MQOT_Q)
415421
tags["cluster"] = mqmetric.GetQueueAttribute(key, ibmmq.MQCA_CLUSTER_NAME)
422+
if showAndSupportsCustomLabel() {
423+
tags["custom"] = mqmetric.GetObjectCustom(key, ibmmq.MQOT_Q)
424+
}
416425
addMetaLabels(tags)
417426

418427
f := mqmetric.QueueNormalise(attr, value.ValueInt64)
@@ -549,6 +558,9 @@ func GetMetrics(ctx context.Context, meter metric.Meter) error {
549558
if hostname != mqmetric.DUMMY_STRING {
550559
tags["hostname"] = hostname
551560
}
561+
if showAndSupportsCustomLabel() {
562+
tags["custom"] = mqmetric.GetObjectCustom("", ibmmq.MQOT_Q_MGR)
563+
}
552564
addMetaLabels(tags)
553565

554566
f := mqmetric.QueueManagerNormalise(attr, value.ValueInt64)
@@ -657,3 +669,7 @@ func addMetaLabels(tags map[string]string) {
657669
}
658670
}
659671
}
672+
673+
func showAndSupportsCustomLabel() bool {
674+
return config.cf.CC.ShowCustomAttribute
675+
}

cmd/mq_prometheus/exporter.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,9 @@ func (e *exporter) Collect(ch chan<- prometheus.Metric) {
234234
if supportsHostnameLabel() {
235235
labels["hostname"] = mqmetric.DUMMY_STRING
236236
}
237+
if showAndSupportsCustomLabel() {
238+
labels["custom"] = mqmetric.GetObjectCustom("", ibmmq.MQOT_Q_MGR)
239+
}
237240
addMetaLabels(labels)
238241
m.addMetric(labels, 0.0)
239242
m.Collect(ch)
@@ -477,6 +480,9 @@ func (e *exporter) Collect(ch chan<- prometheus.Metric) {
477480
if supportsHostnameLabel() {
478481
labels["hostname"] = mqmetric.GetQueueManagerAttribute(config.cf.QMgrName, ibmmq.MQCACF_HOST_NAME)
479482
}
483+
if showAndSupportsCustomLabel() {
484+
labels["custom"] = mqmetric.GetObjectCustom("", ibmmq.MQOT_Q_MGR)
485+
}
480486
addMetaLabels(labels)
481487
m.addMetric(labels, f)
482488
} else if strings.HasPrefix(key, mqmetric.NativeHAKeyPrefix) {
@@ -506,6 +512,9 @@ func (e *exporter) Collect(ch chan<- prometheus.Metric) {
506512
"description": mqmetric.GetObjectDescription(key, ibmmq.MQOT_Q),
507513
"cluster": mqmetric.GetQueueAttribute(key, ibmmq.MQCA_CLUSTER_NAME),
508514
"platform": platformString}
515+
if showAndSupportsCustomLabel() {
516+
labels["custom"] = mqmetric.GetObjectCustom(key, ibmmq.MQOT_Q)
517+
}
509518
addMetaLabels(labels)
510519
m.addMetric(labels, f)
511520
}
@@ -603,6 +612,9 @@ func (e *exporter) Collect(ch chan<- prometheus.Metric) {
603612
"description": mqmetric.GetObjectDescription(qName, ibmmq.MQOT_Q),
604613
"cluster": mqmetric.GetQueueAttribute(qName, ibmmq.MQCA_CLUSTER_NAME),
605614
"queue": qName}
615+
if showAndSupportsCustomLabel() {
616+
labels["custom"] = mqmetric.GetObjectCustom(qName, ibmmq.MQOT_Q)
617+
}
606618
addMetaLabels(labels)
607619
m.addMetric(labels, f)
608620
}
@@ -666,6 +678,9 @@ func (e *exporter) Collect(ch chan<- prometheus.Metric) {
666678
if supportsHostnameLabel() {
667679
labels["hostname"] = mqmetric.GetQueueManagerAttribute(config.cf.QMgrName, ibmmq.MQCACF_HOST_NAME)
668680
}
681+
if showAndSupportsCustomLabel() {
682+
labels["custom"] = mqmetric.GetObjectCustom("", ibmmq.MQOT_Q_MGR)
683+
}
669684
addMetaLabels(labels)
670685
m.addMetric(labels, f)
671686
}
@@ -992,6 +1007,9 @@ when the metrics are collected by Prometheus.
9921007
*/
9931008
func newMqVec(elem *mqmetric.MonElement) *MQVec {
9941009
queueLabelNames := []string{"queue", "qmgr", "platform", "usage", "description", "cluster"}
1010+
if showAndSupportsCustomLabel() {
1011+
queueLabelNames = append(queueLabelNames, "custom")
1012+
}
9951013
nhaLabelNames := []string{"qmgr", "platform", "nha"}
9961014
// If the qmgr tags change, then check the special metric indicating qmgr unavailable as that's
9971015
// not part of the regular collection blocks.
@@ -1000,6 +1018,9 @@ func newMqVec(elem *mqmetric.MonElement) *MQVec {
10001018
if supportsHostnameLabel() {
10011019
qmgrLabelNames = append(qmgrLabelNames, "hostname")
10021020
}
1021+
if showAndSupportsCustomLabel() {
1022+
qmgrLabelNames = append(qmgrLabelNames, "custom")
1023+
}
10031024
labels := qmgrLabelNames
10041025
prefix := "qmgr_"
10051026

@@ -1101,6 +1122,9 @@ func newMqVecObj(attr *mqmetric.StatusAttribute, objectType string) *MQVec {
11011122
if supportsHostnameLabel() {
11021123
qmgrLabels = append(qmgrLabels, "hostname")
11031124
}
1125+
if showAndSupportsCustomLabel() {
1126+
qmgrLabels = append(qmgrLabels, "custom")
1127+
}
11041128
// With topic status, need to know if type is "pub" or "sub"
11051129
topicLabels := []string{"qmgr", "platform", objectType, "type"}
11061130
subLabels := []string{"qmgr", "platform", objectType, "subid", "topic", "type"}
@@ -1115,6 +1139,9 @@ func newMqVecObj(attr *mqmetric.StatusAttribute, objectType string) *MQVec {
11151139
// additional attributes. They should have the same labels as the stats generated
11161140
// through resource publications.
11171141
queueLabels := []string{"qmgr", "platform", objectType, "usage", "description", "cluster"}
1142+
if showAndSupportsCustomLabel() {
1143+
queueLabels = append(queueLabels, "custom")
1144+
}
11181145

11191146
switch objectType {
11201147
case "channel":
@@ -1200,6 +1227,10 @@ func supportsHostnameLabel() bool {
12001227
return rc
12011228
}
12021229

1230+
func showAndSupportsCustomLabel() bool {
1231+
return config.cf.CC.ShowCustomAttribute
1232+
}
1233+
12031234
func addMetaLabels(labels prometheus.Labels) {
12041235
if len(config.cf.MetadataTagsArray) > 0 {
12051236
for i := 0; i < len(config.cf.MetadataTagsArray); i++ {

0 commit comments

Comments
 (0)