Skip to content

Commit 1b39874

Browse files
committed
Merge branch 'feature/add-custom-data-as-tag-or-label' of github.com:dol/mq-metric-samples into dol-feature/add-custom-data-as-tag-or-label
2 parents 6ba0f32 + 7fae626 commit 1b39874

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
@@ -19,6 +19,7 @@ Newest updates are at the top of this file.
1919
### Unreleased
2020
* Fix boolean logic for `isFirstCollection` in `mq_prometheus (#385)`
2121
* Ensure proper collection on the first poll and at regular intervals thereafter
22+
* Add showCustomAttribute filter config setting to include the CUSTOM attribute as metric tag/label
2223

2324
### Feb 28 2025 (v5.6.2)
2425
* 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
@@ -264,6 +264,9 @@ func Collect() error {
264264
if hostname != mqmetric.DUMMY_STRING {
265265
tags["hostname"] = hostname
266266
}
267+
if showAndSupportsCustomLabel() {
268+
tags["custom"] = mqmetric.GetObjectCustom("", ibmmq.MQOT_Q_MGR)
269+
}
267270
} else if strings.HasPrefix(key, mqmetric.NativeHAKeyPrefix) {
268271
series = "nha"
269272
tags["nha"] = strings.Replace(key, mqmetric.NativeHAKeyPrefix, "", -1)
@@ -283,6 +286,9 @@ func Collect() error {
283286
tags["usage"] = usage
284287
tags["description"] = mqmetric.GetObjectDescription(key, ibmmq.MQOT_Q)
285288
tags["cluster"] = mqmetric.GetQueueAttribute(key, ibmmq.MQCA_CLUSTER_NAME)
289+
if showAndSupportsCustomLabel() {
290+
tags["custom"] = mqmetric.GetObjectCustom(key, ibmmq.MQOT_Q)
291+
}
286292
}
287293
addMetaLabels(tags)
288294

@@ -371,6 +377,9 @@ func Collect() error {
371377
tags["usage"] = usage
372378
tags["description"] = mqmetric.GetObjectDescription(key, ibmmq.MQOT_Q)
373379
tags["cluster"] = mqmetric.GetQueueAttribute(key, ibmmq.MQCA_CLUSTER_NAME)
380+
if showAndSupportsCustomLabel() {
381+
tags["custom"] = mqmetric.GetObjectCustom(key, ibmmq.MQOT_Q)
382+
}
374383
addMetaLabels(tags)
375384

376385
f := mqmetric.QueueNormalise(attr, value.ValueInt64)
@@ -496,6 +505,9 @@ func Collect() error {
496505
if hostname != mqmetric.DUMMY_STRING {
497506
tags["hostname"] = hostname
498507
}
508+
if showAndSupportsCustomLabel() {
509+
tags["custom"] = mqmetric.GetObjectCustom("", ibmmq.MQOT_Q_MGR)
510+
}
499511
addMetaLabels(tags)
500512

501513
f := mqmetric.QueueManagerNormalise(attr, value.ValueInt64)
@@ -690,3 +702,7 @@ func addMetaLabels(tags map[string]string) {
690702
}
691703
}
692704
}
705+
706+
func showAndSupportsCustomLabel() bool {
707+
return config.cf.CC.ShowCustomAttribute
708+
}

cmd/mq_coll/exporter.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,9 @@ func Collect() error {
216216
if hostname != mqmetric.DUMMY_STRING {
217217
tags["hostname"] = hostname
218218
}
219+
if showAndSupportsCustomLabel() {
220+
tags["custom"] = mqmetric.GetObjectCustom("", ibmmq.MQOT_Q_MGR)
221+
}
219222
} else if strings.HasPrefix(key, mqmetric.NativeHAKeyPrefix) {
220223
series = "nha"
221224
tags["nha"] = strings.Replace(key, mqmetric.NativeHAKeyPrefix, "", -1)
@@ -234,6 +237,9 @@ func Collect() error {
234237
tags["usage"] = usage
235238
tags["description"] = mqmetric.GetObjectDescription(key, ibmmq.MQOT_Q)
236239
tags["cluster"] = mqmetric.GetQueueAttribute(key, ibmmq.MQCA_CLUSTER_NAME)
240+
if showAndSupportsCustomLabel() {
241+
tags["custom"] = mqmetric.GetObjectCustom(key, ibmmq.MQOT_Q)
242+
}
237243
}
238244
addMetaLabels(tags)
239245

@@ -306,6 +312,9 @@ func Collect() error {
306312
tags["usage"] = usage
307313
tags["description"] = mqmetric.GetObjectDescription(key, ibmmq.MQOT_Q)
308314
tags["cluster"] = mqmetric.GetQueueAttribute(key, ibmmq.MQCA_CLUSTER_NAME)
315+
if showAndSupportsCustomLabel() {
316+
tags["custom"] = mqmetric.GetObjectCustom(key, ibmmq.MQOT_Q)
317+
}
309318
addMetaLabels(tags)
310319

311320
f := mqmetric.QueueNormalise(attr, value.ValueInt64)
@@ -405,6 +414,9 @@ func Collect() error {
405414
if hostname != mqmetric.DUMMY_STRING {
406415
tags["hostname"] = hostname
407416
}
417+
if showAndSupportsCustomLabel() {
418+
tags["custom"] = mqmetric.GetObjectCustom("", ibmmq.MQOT_Q_MGR)
419+
}
408420
addMetaLabels(tags)
409421

410422
f := mqmetric.QueueManagerNormalise(attr, value.ValueInt64)
@@ -571,3 +583,7 @@ func addMetaLabels(tags map[string]string) {
571583
}
572584
}
573585
}
586+
587+
func showAndSupportsCustomLabel() bool {
588+
return config.cf.CC.ShowCustomAttribute
589+
}

cmd/mq_influx/exporter.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,9 @@ func Collect(c client.Client) error {
247247
if hostname != mqmetric.DUMMY_STRING {
248248
tags["hostname"] = hostname
249249
}
250+
if showAndSupportsCustomLabel() {
251+
tags["custom"] = mqmetric.GetObjectCustom("", ibmmq.MQOT_Q_MGR)
252+
}
250253
} else if strings.HasPrefix(key, mqmetric.NativeHAKeyPrefix) {
251254
series = "nha"
252255
tags["nha"] = strings.Replace(key, mqmetric.NativeHAKeyPrefix, "", -1)
@@ -266,6 +269,9 @@ func Collect(c client.Client) error {
266269
tags["usage"] = usage
267270
tags["description"] = mqmetric.GetObjectDescription(key, ibmmq.MQOT_Q)
268271
tags["cluster"] = mqmetric.GetQueueAttribute(key, ibmmq.MQCA_CLUSTER_NAME)
272+
if showAndSupportsCustomLabel() {
273+
tags["custom"] = mqmetric.GetObjectCustom(key, ibmmq.MQOT_Q)
274+
}
269275
addMetaLabels(tags)
270276

271277
}
@@ -346,6 +352,9 @@ func Collect(c client.Client) error {
346352
tags["usage"] = usage
347353
tags["description"] = mqmetric.GetObjectDescription(key, ibmmq.MQOT_Q)
348354
tags["cluster"] = mqmetric.GetQueueAttribute(key, ibmmq.MQCA_CLUSTER_NAME)
355+
if showAndSupportsCustomLabel() {
356+
tags["custom"] = mqmetric.GetObjectCustom(key, ibmmq.MQOT_Q)
357+
}
349358
addMetaLabels(tags)
350359

351360
f := mqmetric.QueueNormalise(attr, value.ValueInt64)
@@ -464,6 +473,9 @@ func Collect(c client.Client) error {
464473
if hostname != mqmetric.DUMMY_STRING {
465474
tags["hostname"] = hostname
466475
}
476+
if showAndSupportsCustomLabel() {
477+
tags["custom"] = mqmetric.GetObjectCustom("", ibmmq.MQOT_Q_MGR)
478+
}
467479
addMetaLabels(tags)
468480

469481
f := mqmetric.QueueManagerNormalise(attr, value.ValueInt64)
@@ -621,3 +633,7 @@ func addMetaLabels(tags map[string]string) {
621633
}
622634
}
623635
}
636+
637+
func showAndSupportsCustomLabel() bool {
638+
return config.cf.CC.ShowCustomAttribute
639+
}

cmd/mq_json/exporter.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,9 @@ func Collect() error {
245245
if hostname != mqmetric.DUMMY_STRING {
246246
pt.Tags["hostname"] = hostname
247247
}
248+
if showAndSupportsCustomLabel() {
249+
pt.Tags["custom"] = mqmetric.GetObjectCustom("", ibmmq.MQOT_Q_MGR)
250+
}
248251
} else if strings.HasPrefix(key, mqmetric.NativeHAKeyPrefix) {
249252
pt.Tags["nha"] = strings.Replace(key, mqmetric.NativeHAKeyPrefix, "", -1)
250253
pt.ObjectType = "nha"
@@ -256,7 +259,9 @@ func Collect() error {
256259
pt.ObjectType = "queue"
257260
pt.Tags["description"] = mqmetric.GetObjectDescription(key, ibmmq.MQOT_Q)
258261
pt.Tags["cluster"] = mqmetric.GetQueueAttribute(key, ibmmq.MQCA_CLUSTER_NAME)
259-
262+
if showAndSupportsCustomLabel() {
263+
pt.Tags["custom"] = mqmetric.GetObjectCustom(key, ibmmq.MQOT_Q)
264+
}
260265
}
261266
addMetaLabels(pt.Tags)
262267
}
@@ -345,6 +350,9 @@ func Collect() error {
345350
pt.Tags["queue"] = qName
346351
pt.Tags["usage"] = usageString
347352
pt.Tags["description"] = mqmetric.GetObjectDescription(qName, ibmmq.MQOT_Q)
353+
if showAndSupportsCustomLabel() {
354+
pt.Tags["custom"] = mqmetric.GetObjectCustom(qName, ibmmq.MQOT_Q)
355+
}
348356
pt.Tags["cluster"] = mqmetric.GetQueueAttribute(key, ibmmq.MQCA_CLUSTER_NAME)
349357
pt.Tags["platform"] = platformString
350358
addMetaLabels(pt.Tags)
@@ -400,6 +408,9 @@ func Collect() error {
400408
pt.Tags["qmgr"] = strings.TrimSpace(qMgrName)
401409
pt.Tags["platform"] = platformString
402410
pt.Tags["description"] = mqmetric.GetObjectDescription("", ibmmq.MQOT_Q_MGR)
411+
if showAndSupportsCustomLabel() {
412+
pt.Tags["custom"] = mqmetric.GetObjectCustom("", ibmmq.MQOT_Q_MGR)
413+
}
403414
hostname := mqmetric.GetQueueManagerAttribute(config.cf.QMgrName, ibmmq.MQCACF_HOST_NAME)
404415
if hostname != mqmetric.DUMMY_STRING {
405416
pt.Tags["hostname"] = hostname
@@ -695,3 +706,7 @@ func addMetaLabels(tags map[string]string) {
695706
}
696707
}
697708
}
709+
710+
func showAndSupportsCustomLabel() bool {
711+
return config.cf.CC.ShowCustomAttribute
712+
}

cmd/mq_opentsdb/exporter.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,9 @@ func Collect() error {
247247
if hostname != mqmetric.DUMMY_STRING {
248248
tags["hostname"] = hostname
249249
}
250+
if showAndSupportsCustomLabel() {
251+
tags["custom"] = mqmetric.GetObjectCustom("", ibmmq.MQOT_Q_MGR)
252+
}
250253
} else if strings.HasPrefix(key, mqmetric.NativeHAKeyPrefix) {
251254
series = "nha"
252255
tags["nha"] = strings.Replace(key, mqmetric.NativeHAKeyPrefix, "", -1)
@@ -265,7 +268,9 @@ func Collect() error {
265268
tags["usage"] = usage
266269
tags["description"] = mqmetric.GetObjectDescription(key, ibmmq.MQOT_Q)
267270
tags["cluster"] = mqmetric.GetQueueAttribute(key, ibmmq.MQCA_CLUSTER_NAME)
268-
271+
if showAndSupportsCustomLabel() {
272+
tags["custom"] = mqmetric.GetObjectCustom(key, ibmmq.MQOT_Q)
273+
}
269274
}
270275
addMetaLabels(tags)
271276

@@ -351,6 +356,9 @@ func Collect() error {
351356
tags["usage"] = usage
352357
tags["description"] = mqmetric.GetObjectDescription(key, ibmmq.MQOT_Q)
353358
tags["cluster"] = mqmetric.GetQueueAttribute(key, ibmmq.MQCA_CLUSTER_NAME)
359+
if showAndSupportsCustomLabel() {
360+
tags["custom"] = mqmetric.GetObjectCustom(key, ibmmq.MQOT_Q)
361+
}
354362
addMetaLabels(tags)
355363

356364
f := mqmetric.QueueNormalise(attr, value.ValueInt64)
@@ -473,6 +481,9 @@ func Collect() error {
473481
if hostname != mqmetric.DUMMY_STRING {
474482
tags["hostname"] = hostname
475483
}
484+
if showAndSupportsCustomLabel() {
485+
tags["custom"] = mqmetric.GetObjectCustom("", ibmmq.MQOT_Q_MGR)
486+
}
476487
addMetaLabels(tags)
477488

478489
f := mqmetric.QueueManagerNormalise(attr, value.ValueInt64)
@@ -707,3 +718,7 @@ func addMetaLabels(tags map[string]string) {
707718
}
708719
}
709720
}
721+
722+
func showAndSupportsCustomLabel() bool {
723+
return config.cf.CC.ShowCustomAttribute
724+
}

cmd/mq_otel/reader.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,9 @@ func GetMetrics(ctx context.Context, meter metric.Meter) error {
374374
if hostname != mqmetric.DUMMY_STRING {
375375
tags["hostname"] = hostname
376376
}
377+
if showAndSupportsCustomLabel() {
378+
tags["custom"] = mqmetric.GetObjectCustom("", ibmmq.MQOT_Q_MGR)
379+
}
377380
} else if strings.HasPrefix(key, mqmetric.NativeHAKeyPrefix) {
378381
series = "nha"
379382
tags["nha"] = strings.Replace(key, mqmetric.NativeHAKeyPrefix, "", -1)
@@ -392,6 +395,9 @@ func GetMetrics(ctx context.Context, meter metric.Meter) error {
392395
tags["usage"] = usage
393396
tags["description"] = mqmetric.GetObjectDescription(key, ibmmq.MQOT_Q)
394397
tags["cluster"] = mqmetric.GetQueueAttribute(key, ibmmq.MQCA_CLUSTER_NAME)
398+
if showAndSupportsCustomLabel() {
399+
tags["custom"] = mqmetric.GetObjectCustom(key, ibmmq.MQOT_Q)
400+
}
395401
}
396402

397403
addMetaLabels(tags)
@@ -426,6 +432,9 @@ func GetMetrics(ctx context.Context, meter metric.Meter) error {
426432
tags["usage"] = usage
427433
tags["description"] = mqmetric.GetObjectDescription(key, ibmmq.MQOT_Q)
428434
tags["cluster"] = mqmetric.GetQueueAttribute(key, ibmmq.MQCA_CLUSTER_NAME)
435+
if showAndSupportsCustomLabel() {
436+
tags["custom"] = mqmetric.GetObjectCustom(key, ibmmq.MQOT_Q)
437+
}
429438
addMetaLabels(tags)
430439

431440
f := mqmetric.QueueNormalise(attr, value.ValueInt64)
@@ -567,6 +576,9 @@ func GetMetrics(ctx context.Context, meter metric.Meter) error {
567576
if hostname != mqmetric.DUMMY_STRING {
568577
tags["hostname"] = hostname
569578
}
579+
if showAndSupportsCustomLabel() {
580+
tags["custom"] = mqmetric.GetObjectCustom("", ibmmq.MQOT_Q_MGR)
581+
}
570582
addMetaLabels(tags)
571583

572584
f := mqmetric.QueueManagerNormalise(attr, value.ValueInt64)
@@ -700,3 +712,7 @@ func addMetaLabels(tags map[string]string) {
700712
}
701713
}
702714
}
715+
716+
func showAndSupportsCustomLabel() bool {
717+
return config.cf.CC.ShowCustomAttribute
718+
}

cmd/mq_prometheus/exporter.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,9 @@ func (e *exporter) Collect(ch chan<- prometheus.Metric) {
240240
if supportsHostnameLabel() {
241241
labels["hostname"] = mqmetric.DUMMY_STRING
242242
}
243+
if showAndSupportsCustomLabel() {
244+
labels["custom"] = mqmetric.GetObjectCustom("", ibmmq.MQOT_Q_MGR)
245+
}
243246
addMetaLabels(labels)
244247
m.addMetric(labels, 0.0)
245248
m.Collect(ch)
@@ -501,6 +504,9 @@ func (e *exporter) Collect(ch chan<- prometheus.Metric) {
501504
if supportsHostnameLabel() {
502505
labels["hostname"] = mqmetric.GetQueueManagerAttribute(config.cf.QMgrName, ibmmq.MQCACF_HOST_NAME)
503506
}
507+
if showAndSupportsCustomLabel() {
508+
labels["custom"] = mqmetric.GetObjectCustom("", ibmmq.MQOT_Q_MGR)
509+
}
504510
addMetaLabels(labels)
505511
m.addMetric(labels, f)
506512
} else if strings.HasPrefix(key, mqmetric.NativeHAKeyPrefix) {
@@ -530,6 +536,9 @@ func (e *exporter) Collect(ch chan<- prometheus.Metric) {
530536
"description": mqmetric.GetObjectDescription(key, ibmmq.MQOT_Q),
531537
"cluster": mqmetric.GetQueueAttribute(key, ibmmq.MQCA_CLUSTER_NAME),
532538
"platform": platformString}
539+
if showAndSupportsCustomLabel() {
540+
labels["custom"] = mqmetric.GetObjectCustom(key, ibmmq.MQOT_Q)
541+
}
533542
addMetaLabels(labels)
534543
m.addMetric(labels, f)
535544
}
@@ -633,6 +642,9 @@ func (e *exporter) Collect(ch chan<- prometheus.Metric) {
633642
"description": mqmetric.GetObjectDescription(qName, ibmmq.MQOT_Q),
634643
"cluster": mqmetric.GetQueueAttribute(qName, ibmmq.MQCA_CLUSTER_NAME),
635644
"queue": qName}
645+
if showAndSupportsCustomLabel() {
646+
labels["custom"] = mqmetric.GetObjectCustom(qName, ibmmq.MQOT_Q)
647+
}
636648
addMetaLabels(labels)
637649
m.addMetric(labels, f)
638650
}
@@ -696,6 +708,9 @@ func (e *exporter) Collect(ch chan<- prometheus.Metric) {
696708
if supportsHostnameLabel() {
697709
labels["hostname"] = mqmetric.GetQueueManagerAttribute(config.cf.QMgrName, ibmmq.MQCACF_HOST_NAME)
698710
}
711+
if showAndSupportsCustomLabel() {
712+
labels["custom"] = mqmetric.GetObjectCustom("", ibmmq.MQOT_Q_MGR)
713+
}
699714
addMetaLabels(labels)
700715
m.addMetric(labels, f)
701716
}
@@ -1061,6 +1076,9 @@ when the metrics are collected by Prometheus.
10611076
*/
10621077
func newMqVec(elem *mqmetric.MonElement) *MQVec {
10631078
queueLabelNames := []string{"queue", "qmgr", "platform", "usage", "description", "cluster"}
1079+
if showAndSupportsCustomLabel() {
1080+
queueLabelNames = append(queueLabelNames, "custom")
1081+
}
10641082
nhaLabelNames := []string{"qmgr", "platform", "nha"}
10651083
// If the qmgr tags change, then check the special metric indicating qmgr unavailable as that's
10661084
// not part of the regular collection blocks.
@@ -1069,6 +1087,9 @@ func newMqVec(elem *mqmetric.MonElement) *MQVec {
10691087
if supportsHostnameLabel() {
10701088
qmgrLabelNames = append(qmgrLabelNames, "hostname")
10711089
}
1090+
if showAndSupportsCustomLabel() {
1091+
qmgrLabelNames = append(qmgrLabelNames, "custom")
1092+
}
10721093
labels := qmgrLabelNames
10731094
prefix := "qmgr_"
10741095

@@ -1171,6 +1192,9 @@ func newMqVecObj(attr *mqmetric.StatusAttribute, objectType string) *MQVec {
11711192
if supportsHostnameLabel() {
11721193
qmgrLabels = append(qmgrLabels, "hostname")
11731194
}
1195+
if showAndSupportsCustomLabel() {
1196+
qmgrLabels = append(qmgrLabels, "custom")
1197+
}
11741198
// With topic status, need to know if type is "pub" or "sub"
11751199
topicLabels := []string{"qmgr", "platform", objectType, "type"}
11761200
subLabels := []string{"qmgr", "platform", objectType, "subid", "topic", "type"}
@@ -1187,6 +1211,9 @@ func newMqVecObj(attr *mqmetric.StatusAttribute, objectType string) *MQVec {
11871211
// additional attributes. They should have the same labels as the stats generated
11881212
// through resource publications.
11891213
queueLabels := []string{"qmgr", "platform", objectType, "usage", "description", "cluster"}
1214+
if showAndSupportsCustomLabel() {
1215+
queueLabels = append(queueLabels, "custom")
1216+
}
11901217

11911218
switch objectType {
11921219
case "channel":
@@ -1274,6 +1301,10 @@ func supportsHostnameLabel() bool {
12741301
return rc
12751302
}
12761303

1304+
func showAndSupportsCustomLabel() bool {
1305+
return config.cf.CC.ShowCustomAttribute
1306+
}
1307+
12771308
func addMetaLabels(labels prometheus.Labels) {
12781309
if len(config.cf.MetadataTagsArray) > 0 {
12791310
for i := 0; i < len(config.cf.MetadataTagsArray); i++ {

0 commit comments

Comments
 (0)