Skip to content

feat: Add showCustomAttribute filter config setting to include the CUSTOM attribute as tag/label #392

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Newest updates are at the top of this file.
### Unreleased
* Fix boolean logic for `isFirstCollection` in `mq_prometheus (#385)`
* Ensure proper collection on the first poll and at regular intervals thereafter
* Add showCustomAttribute filter config setting to include the CUSTOM attribute as metric tag/label

### Feb 28 2025 (v5.6.2)
* Update to MQ 9.4.2
Expand Down
16 changes: 16 additions & 0 deletions cmd/mq_aws/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,9 @@ func Collect() error {
if hostname != mqmetric.DUMMY_STRING {
tags["hostname"] = hostname
}
if showAndSupportsCustomLabel() {
tags["custom"] = mqmetric.GetObjectCustom("", ibmmq.MQOT_Q_MGR)
}
} else if strings.HasPrefix(key, mqmetric.NativeHAKeyPrefix) {
series = "nha"
tags["nha"] = strings.Replace(key, mqmetric.NativeHAKeyPrefix, "", -1)
Expand All @@ -270,6 +273,9 @@ func Collect() error {
tags["usage"] = usage
tags["description"] = mqmetric.GetObjectDescription(key, ibmmq.MQOT_Q)
tags["cluster"] = mqmetric.GetQueueAttribute(key, ibmmq.MQCA_CLUSTER_NAME)
if showAndSupportsCustomLabel() {
tags["custom"] = mqmetric.GetObjectCustom(key, ibmmq.MQOT_Q)
}
}
addMetaLabels(tags)

Expand Down Expand Up @@ -351,6 +357,9 @@ func Collect() error {
tags["usage"] = usage
tags["description"] = mqmetric.GetObjectDescription(key, ibmmq.MQOT_Q)
tags["cluster"] = mqmetric.GetQueueAttribute(key, ibmmq.MQCA_CLUSTER_NAME)
if showAndSupportsCustomLabel() {
tags["custom"] = mqmetric.GetObjectCustom(key, ibmmq.MQOT_Q)
}
addMetaLabels(tags)

f := mqmetric.QueueNormalise(attr, value.ValueInt64)
Expand Down Expand Up @@ -476,6 +485,9 @@ func Collect() error {
if hostname != mqmetric.DUMMY_STRING {
tags["hostname"] = hostname
}
if showAndSupportsCustomLabel() {
tags["custom"] = mqmetric.GetObjectCustom("", ibmmq.MQOT_Q_MGR)
}
addMetaLabels(tags)

f := mqmetric.QueueManagerNormalise(attr, value.ValueInt64)
Expand Down Expand Up @@ -640,3 +652,7 @@ func addMetaLabels(tags map[string]string) {
}
}
}

func showAndSupportsCustomLabel() bool {
return config.cf.CC.ShowCustomAttribute
}
16 changes: 16 additions & 0 deletions cmd/mq_coll/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@ func Collect() error {
if hostname != mqmetric.DUMMY_STRING {
tags["hostname"] = hostname
}
if showAndSupportsCustomLabel() {
tags["custom"] = mqmetric.GetObjectCustom("", ibmmq.MQOT_Q_MGR)
}
} else if strings.HasPrefix(key, mqmetric.NativeHAKeyPrefix) {
series = "nha"
tags["nha"] = strings.Replace(key, mqmetric.NativeHAKeyPrefix, "", -1)
Expand All @@ -223,6 +226,9 @@ func Collect() error {
tags["usage"] = usage
tags["description"] = mqmetric.GetObjectDescription(key, ibmmq.MQOT_Q)
tags["cluster"] = mqmetric.GetQueueAttribute(key, ibmmq.MQCA_CLUSTER_NAME)
if showAndSupportsCustomLabel() {
tags["custom"] = mqmetric.GetObjectCustom(key, ibmmq.MQOT_Q)
}
}
addMetaLabels(tags)

Expand Down Expand Up @@ -290,6 +296,9 @@ func Collect() error {
tags["usage"] = usage
tags["description"] = mqmetric.GetObjectDescription(key, ibmmq.MQOT_Q)
tags["cluster"] = mqmetric.GetQueueAttribute(key, ibmmq.MQCA_CLUSTER_NAME)
if showAndSupportsCustomLabel() {
tags["custom"] = mqmetric.GetObjectCustom(key, ibmmq.MQOT_Q)
}
addMetaLabels(tags)

f := mqmetric.QueueNormalise(attr, value.ValueInt64)
Expand Down Expand Up @@ -389,6 +398,9 @@ func Collect() error {
if hostname != mqmetric.DUMMY_STRING {
tags["hostname"] = hostname
}
if showAndSupportsCustomLabel() {
tags["custom"] = mqmetric.GetObjectCustom("", ibmmq.MQOT_Q_MGR)
}
addMetaLabels(tags)

f := mqmetric.QueueManagerNormalise(attr, value.ValueInt64)
Expand Down Expand Up @@ -530,3 +542,7 @@ func addMetaLabels(tags map[string]string) {
}
}
}

func showAndSupportsCustomLabel() bool {
return config.cf.CC.ShowCustomAttribute
}
16 changes: 16 additions & 0 deletions cmd/mq_influx/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,9 @@ func Collect(c client.Client) error {
if hostname != mqmetric.DUMMY_STRING {
tags["hostname"] = hostname
}
if showAndSupportsCustomLabel() {
tags["custom"] = mqmetric.GetObjectCustom("", ibmmq.MQOT_Q_MGR)
}
} else if strings.HasPrefix(key, mqmetric.NativeHAKeyPrefix) {
series = "nha"
tags["nha"] = strings.Replace(key, mqmetric.NativeHAKeyPrefix, "", -1)
Expand All @@ -255,6 +258,9 @@ func Collect(c client.Client) error {
tags["usage"] = usage
tags["description"] = mqmetric.GetObjectDescription(key, ibmmq.MQOT_Q)
tags["cluster"] = mqmetric.GetQueueAttribute(key, ibmmq.MQCA_CLUSTER_NAME)
if showAndSupportsCustomLabel() {
tags["custom"] = mqmetric.GetObjectCustom(key, ibmmq.MQOT_Q)
}
addMetaLabels(tags)

}
Expand Down Expand Up @@ -329,6 +335,9 @@ func Collect(c client.Client) error {
tags["usage"] = usage
tags["description"] = mqmetric.GetObjectDescription(key, ibmmq.MQOT_Q)
tags["cluster"] = mqmetric.GetQueueAttribute(key, ibmmq.MQCA_CLUSTER_NAME)
if showAndSupportsCustomLabel() {
tags["custom"] = mqmetric.GetObjectCustom(key, ibmmq.MQOT_Q)
}
addMetaLabels(tags)

f := mqmetric.QueueNormalise(attr, value.ValueInt64)
Expand Down Expand Up @@ -447,6 +456,9 @@ func Collect(c client.Client) error {
if hostname != mqmetric.DUMMY_STRING {
tags["hostname"] = hostname
}
if showAndSupportsCustomLabel() {
tags["custom"] = mqmetric.GetObjectCustom("", ibmmq.MQOT_Q_MGR)
}
addMetaLabels(tags)

f := mqmetric.QueueManagerNormalise(attr, value.ValueInt64)
Expand Down Expand Up @@ -574,3 +586,7 @@ func addMetaLabels(tags map[string]string) {
}
}
}

func showAndSupportsCustomLabel() bool {
return config.cf.CC.ShowCustomAttribute
}
17 changes: 16 additions & 1 deletion cmd/mq_json/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,9 @@ func Collect() error {
if hostname != mqmetric.DUMMY_STRING {
pt.Tags["hostname"] = hostname
}
if showAndSupportsCustomLabel() {
pt.Tags["custom"] = mqmetric.GetObjectCustom("", ibmmq.MQOT_Q_MGR)
}
} else if strings.HasPrefix(key, mqmetric.NativeHAKeyPrefix) {
pt.Tags["nha"] = strings.Replace(key, mqmetric.NativeHAKeyPrefix, "", -1)
pt.ObjectType = "nha"
Expand All @@ -244,7 +247,9 @@ func Collect() error {
pt.ObjectType = "queue"
pt.Tags["description"] = mqmetric.GetObjectDescription(key, ibmmq.MQOT_Q)
pt.Tags["cluster"] = mqmetric.GetQueueAttribute(key, ibmmq.MQCA_CLUSTER_NAME)

if showAndSupportsCustomLabel() {
pt.Tags["custom"] = mqmetric.GetObjectCustom(key, ibmmq.MQOT_Q)
}
}
addMetaLabels(pt.Tags)
}
Expand Down Expand Up @@ -327,6 +332,9 @@ func Collect() error {
pt.Tags["queue"] = qName
pt.Tags["usage"] = usageString
pt.Tags["description"] = mqmetric.GetObjectDescription(qName, ibmmq.MQOT_Q)
if showAndSupportsCustomLabel() {
pt.Tags["custom"] = mqmetric.GetObjectCustom(qName, ibmmq.MQOT_Q)
}
pt.Tags["cluster"] = mqmetric.GetQueueAttribute(key, ibmmq.MQCA_CLUSTER_NAME)
pt.Tags["platform"] = platformString
addMetaLabels(pt.Tags)
Expand Down Expand Up @@ -382,6 +390,9 @@ func Collect() error {
pt.Tags["qmgr"] = strings.TrimSpace(qMgrName)
pt.Tags["platform"] = platformString
pt.Tags["description"] = mqmetric.GetObjectDescription("", ibmmq.MQOT_Q_MGR)
if showAndSupportsCustomLabel() {
pt.Tags["custom"] = mqmetric.GetObjectCustom("", ibmmq.MQOT_Q_MGR)
}
hostname := mqmetric.GetQueueManagerAttribute(config.cf.QMgrName, ibmmq.MQCACF_HOST_NAME)
if hostname != mqmetric.DUMMY_STRING {
pt.Tags["hostname"] = hostname
Expand Down Expand Up @@ -650,3 +661,7 @@ func addMetaLabels(tags map[string]string) {
}
}
}

func showAndSupportsCustomLabel() bool {
return config.cf.CC.ShowCustomAttribute
}
17 changes: 16 additions & 1 deletion cmd/mq_opentsdb/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,9 @@ func Collect() error {
if hostname != mqmetric.DUMMY_STRING {
tags["hostname"] = hostname
}
if showAndSupportsCustomLabel() {
tags["custom"] = mqmetric.GetObjectCustom("", ibmmq.MQOT_Q_MGR)
}
} else if strings.HasPrefix(key, mqmetric.NativeHAKeyPrefix) {
series = "nha"
tags["nha"] = strings.Replace(key, mqmetric.NativeHAKeyPrefix, "", -1)
Expand All @@ -254,7 +257,9 @@ func Collect() error {
tags["usage"] = usage
tags["description"] = mqmetric.GetObjectDescription(key, ibmmq.MQOT_Q)
tags["cluster"] = mqmetric.GetQueueAttribute(key, ibmmq.MQCA_CLUSTER_NAME)

if showAndSupportsCustomLabel() {
tags["custom"] = mqmetric.GetObjectCustom(key, ibmmq.MQOT_Q)
}
}
addMetaLabels(tags)

Expand Down Expand Up @@ -335,6 +340,9 @@ func Collect() error {
tags["usage"] = usage
tags["description"] = mqmetric.GetObjectDescription(key, ibmmq.MQOT_Q)
tags["cluster"] = mqmetric.GetQueueAttribute(key, ibmmq.MQCA_CLUSTER_NAME)
if showAndSupportsCustomLabel() {
tags["custom"] = mqmetric.GetObjectCustom(key, ibmmq.MQOT_Q)
}
addMetaLabels(tags)

f := mqmetric.QueueNormalise(attr, value.ValueInt64)
Expand Down Expand Up @@ -457,6 +465,9 @@ func Collect() error {
if hostname != mqmetric.DUMMY_STRING {
tags["hostname"] = hostname
}
if showAndSupportsCustomLabel() {
tags["custom"] = mqmetric.GetObjectCustom("", ibmmq.MQOT_Q_MGR)
}
addMetaLabels(tags)

f := mqmetric.QueueManagerNormalise(attr, value.ValueInt64)
Expand Down Expand Up @@ -662,3 +673,7 @@ func addMetaLabels(tags map[string]string) {
}
}
}

func showAndSupportsCustomLabel() bool {
return config.cf.CC.ShowCustomAttribute
}
16 changes: 16 additions & 0 deletions cmd/mq_otel/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,9 @@ func GetMetrics(ctx context.Context, meter metric.Meter) error {
if hostname != mqmetric.DUMMY_STRING {
tags["hostname"] = hostname
}
if showAndSupportsCustomLabel() {
tags["custom"] = mqmetric.GetObjectCustom("", ibmmq.MQOT_Q_MGR)
}
} else if strings.HasPrefix(key, mqmetric.NativeHAKeyPrefix) {
series = "nha"
tags["nha"] = strings.Replace(key, mqmetric.NativeHAKeyPrefix, "", -1)
Expand All @@ -379,6 +382,9 @@ func GetMetrics(ctx context.Context, meter metric.Meter) error {
tags["usage"] = usage
tags["description"] = mqmetric.GetObjectDescription(key, ibmmq.MQOT_Q)
tags["cluster"] = mqmetric.GetQueueAttribute(key, ibmmq.MQCA_CLUSTER_NAME)
if showAndSupportsCustomLabel() {
tags["custom"] = mqmetric.GetObjectCustom(key, ibmmq.MQOT_Q)
}
}

addMetaLabels(tags)
Expand Down Expand Up @@ -413,6 +419,9 @@ func GetMetrics(ctx context.Context, meter metric.Meter) error {
tags["usage"] = usage
tags["description"] = mqmetric.GetObjectDescription(key, ibmmq.MQOT_Q)
tags["cluster"] = mqmetric.GetQueueAttribute(key, ibmmq.MQCA_CLUSTER_NAME)
if showAndSupportsCustomLabel() {
tags["custom"] = mqmetric.GetObjectCustom(key, ibmmq.MQOT_Q)
}
addMetaLabels(tags)

f := mqmetric.QueueNormalise(attr, value.ValueInt64)
Expand Down Expand Up @@ -549,6 +558,9 @@ func GetMetrics(ctx context.Context, meter metric.Meter) error {
if hostname != mqmetric.DUMMY_STRING {
tags["hostname"] = hostname
}
if showAndSupportsCustomLabel() {
tags["custom"] = mqmetric.GetObjectCustom("", ibmmq.MQOT_Q_MGR)
}
addMetaLabels(tags)

f := mqmetric.QueueManagerNormalise(attr, value.ValueInt64)
Expand Down Expand Up @@ -657,3 +669,7 @@ func addMetaLabels(tags map[string]string) {
}
}
}

func showAndSupportsCustomLabel() bool {
return config.cf.CC.ShowCustomAttribute
}
31 changes: 31 additions & 0 deletions cmd/mq_prometheus/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,9 @@ func (e *exporter) Collect(ch chan<- prometheus.Metric) {
if supportsHostnameLabel() {
labels["hostname"] = mqmetric.DUMMY_STRING
}
if showAndSupportsCustomLabel() {
labels["custom"] = mqmetric.GetObjectCustom("", ibmmq.MQOT_Q_MGR)
}
addMetaLabels(labels)
m.addMetric(labels, 0.0)
m.Collect(ch)
Expand Down Expand Up @@ -477,6 +480,9 @@ func (e *exporter) Collect(ch chan<- prometheus.Metric) {
if supportsHostnameLabel() {
labels["hostname"] = mqmetric.GetQueueManagerAttribute(config.cf.QMgrName, ibmmq.MQCACF_HOST_NAME)
}
if showAndSupportsCustomLabel() {
labels["custom"] = mqmetric.GetObjectCustom("", ibmmq.MQOT_Q_MGR)
}
addMetaLabels(labels)
m.addMetric(labels, f)
} else if strings.HasPrefix(key, mqmetric.NativeHAKeyPrefix) {
Expand Down Expand Up @@ -506,6 +512,9 @@ func (e *exporter) Collect(ch chan<- prometheus.Metric) {
"description": mqmetric.GetObjectDescription(key, ibmmq.MQOT_Q),
"cluster": mqmetric.GetQueueAttribute(key, ibmmq.MQCA_CLUSTER_NAME),
"platform": platformString}
if showAndSupportsCustomLabel() {
labels["custom"] = mqmetric.GetObjectCustom(key, ibmmq.MQOT_Q)
}
addMetaLabels(labels)
m.addMetric(labels, f)
}
Expand Down Expand Up @@ -603,6 +612,9 @@ func (e *exporter) Collect(ch chan<- prometheus.Metric) {
"description": mqmetric.GetObjectDescription(qName, ibmmq.MQOT_Q),
"cluster": mqmetric.GetQueueAttribute(qName, ibmmq.MQCA_CLUSTER_NAME),
"queue": qName}
if showAndSupportsCustomLabel() {
labels["custom"] = mqmetric.GetObjectCustom(qName, ibmmq.MQOT_Q)
}
addMetaLabels(labels)
m.addMetric(labels, f)
}
Expand Down Expand Up @@ -666,6 +678,9 @@ func (e *exporter) Collect(ch chan<- prometheus.Metric) {
if supportsHostnameLabel() {
labels["hostname"] = mqmetric.GetQueueManagerAttribute(config.cf.QMgrName, ibmmq.MQCACF_HOST_NAME)
}
if showAndSupportsCustomLabel() {
labels["custom"] = mqmetric.GetObjectCustom("", ibmmq.MQOT_Q_MGR)
}
addMetaLabels(labels)
m.addMetric(labels, f)
}
Expand Down Expand Up @@ -992,6 +1007,9 @@ when the metrics are collected by Prometheus.
*/
func newMqVec(elem *mqmetric.MonElement) *MQVec {
queueLabelNames := []string{"queue", "qmgr", "platform", "usage", "description", "cluster"}
if showAndSupportsCustomLabel() {
queueLabelNames = append(queueLabelNames, "custom")
}
nhaLabelNames := []string{"qmgr", "platform", "nha"}
// If the qmgr tags change, then check the special metric indicating qmgr unavailable as that's
// not part of the regular collection blocks.
Expand All @@ -1000,6 +1018,9 @@ func newMqVec(elem *mqmetric.MonElement) *MQVec {
if supportsHostnameLabel() {
qmgrLabelNames = append(qmgrLabelNames, "hostname")
}
if showAndSupportsCustomLabel() {
qmgrLabelNames = append(qmgrLabelNames, "custom")
}
labels := qmgrLabelNames
prefix := "qmgr_"

Expand Down Expand Up @@ -1101,6 +1122,9 @@ func newMqVecObj(attr *mqmetric.StatusAttribute, objectType string) *MQVec {
if supportsHostnameLabel() {
qmgrLabels = append(qmgrLabels, "hostname")
}
if showAndSupportsCustomLabel() {
qmgrLabels = append(qmgrLabels, "custom")
}
// With topic status, need to know if type is "pub" or "sub"
topicLabels := []string{"qmgr", "platform", objectType, "type"}
subLabels := []string{"qmgr", "platform", objectType, "subid", "topic", "type"}
Expand All @@ -1115,6 +1139,9 @@ func newMqVecObj(attr *mqmetric.StatusAttribute, objectType string) *MQVec {
// additional attributes. They should have the same labels as the stats generated
// through resource publications.
queueLabels := []string{"qmgr", "platform", objectType, "usage", "description", "cluster"}
if showAndSupportsCustomLabel() {
queueLabels = append(queueLabels, "custom")
}

switch objectType {
case "channel":
Expand Down Expand Up @@ -1200,6 +1227,10 @@ func supportsHostnameLabel() bool {
return rc
}

func showAndSupportsCustomLabel() bool {
return config.cf.CC.ShowCustomAttribute
}

func addMetaLabels(labels prometheus.Labels) {
if len(config.cf.MetadataTagsArray) > 0 {
for i := 0; i < len(config.cf.MetadataTagsArray); i++ {
Expand Down
Loading