Skip to content

Commit

Permalink
Add object DESCRIPTION to Prometheus and Json collectors as a label f…
Browse files Browse the repository at this point in the history
…or queues and channels (#16)
  • Loading branch information
ibmmqmet committed Dec 10, 2019
1 parent fab67f0 commit 8820836
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
5 changes: 5 additions & 0 deletions cmd/mq_json/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ func Collect() error {
s := config.cf.MonitoredQueues
err = mqmetric.RediscoverAndSubscribe(s, true, "")
lastQueueDiscovery = thisDiscovery
err = mqmetric.RediscoverAttributes(ibmmq.MQOT_CHANNEL, config.cf.MonitoredChannels)
}
}

Expand Down Expand Up @@ -198,6 +199,8 @@ func Collect() error {
pt.Tags["queue"] = key
pt.Tags["usage"] = usageString
pt.ObjectType = "queue"
pt.Tags["description"] = mqmetric.GetObjectDescription(key, ibmmq.MQOT_Q)

}
}

Expand Down Expand Up @@ -245,6 +248,7 @@ func Collect() error {
pt.Tags["qmgr"] = strings.TrimSpace(config.cf.QMgrName)
pt.Tags["channel"] = chlName
pt.Tags["platform"] = platformString
pt.Tags["description"] = mqmetric.GetObjectDescription(chlName, ibmmq.MQOT_CHANNEL)
pt.Tags[mqmetric.ATTR_CHL_TYPE] = strings.TrimSpace(chlTypeString)
pt.Tags[mqmetric.ATTR_CHL_RQMNAME] = strings.TrimSpace(rqmName)
pt.Tags[mqmetric.ATTR_CHL_CONNNAME] = strings.TrimSpace(connName)
Expand Down Expand Up @@ -272,6 +276,7 @@ func Collect() error {
pt.Tags["qmgr"] = strings.TrimSpace(config.cf.QMgrName)
pt.Tags["queue"] = qName
pt.Tags["usage"] = usageString
pt.Tags["description"] = mqmetric.GetObjectDescription(qName, ibmmq.MQOT_Q)
pt.Tags["platform"] = platformString
}

Expand Down
5 changes: 4 additions & 1 deletion cmd/mq_json/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import (
"os"
"time"

"github.com/ibm-messaging/mq-golang/mqmetric"
ibmmq "github.com/ibm-messaging/mq-golang/ibmmq"
mqmetric "github.com/ibm-messaging/mq-golang/mqmetric"
log "github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -86,6 +87,8 @@ func main() {
wildcardResource = false
}
err = mqmetric.DiscoverAndSubscribe(config.cf.MonitoredQueues, wildcardResource, config.cf.MetaPrefix)
// Also get the static attributes for any configured channels
mqmetric.RediscoverAttributes(ibmmq.MQOT_CHANNEL, config.cf.MonitoredChannels)
}

// Go into main loop for sending data to stdout
Expand Down
23 changes: 13 additions & 10 deletions cmd/mq_prometheus/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,10 @@ func (e *exporter) Collect(ch chan<- prometheus.Metric) {
}
}
g.With(prometheus.Labels{"qmgr": config.cf.QMgrName,
"queue": key,
"usage": usage,
"platform": platformString}).Set(f)
"queue": key,
"usage": usage,
"description": mqmetric.GetObjectDescription(key, ibmmq.MQOT_Q),
"platform": platformString}).Set(f)
}
}
}
Expand Down Expand Up @@ -326,6 +327,7 @@ func (e *exporter) Collect(ch chan<- prometheus.Metric) {
"qmgr": strings.TrimSpace(config.cf.QMgrName),
"channel": chlName,
"platform": platformString,
"description": mqmetric.GetObjectDescription(chlName, ibmmq.MQOT_CHANNEL),
mqmetric.ATTR_CHL_TYPE: strings.TrimSpace(chlTypeString),
mqmetric.ATTR_CHL_RQMNAME: strings.TrimSpace(rqmname),
mqmetric.ATTR_CHL_CONNNAME: strings.TrimSpace(connName),
Expand All @@ -352,10 +354,11 @@ func (e *exporter) Collect(ch chan<- prometheus.Metric) {
log.Debugf("queue status - key: %s qName: %s metric: %s val: %v", key, qName, attr.MetricName, f)

g.With(prometheus.Labels{
"qmgr": strings.TrimSpace(config.cf.QMgrName),
"platform": platformString,
"usage": usage,
"queue": qName}).Set(f)
"qmgr": strings.TrimSpace(config.cf.QMgrName),
"platform": platformString,
"usage": usage,
"description": mqmetric.GetObjectDescription(qName, ibmmq.MQOT_Q),
"queue": qName}).Set(f)
}
}
}
Expand Down Expand Up @@ -625,7 +628,7 @@ with both the queue and qmgr name; for the qmgr-wide entries, we
only need the single label.
*/
func newMqGaugeVec(elem *mqmetric.MonElement) *prometheus.GaugeVec {
queueLabelNames := []string{"queue", "qmgr", "platform", "usage"}
queueLabelNames := []string{"queue", "qmgr", "platform", "usage", "description"}
qmgrLabelNames := []string{"qmgr", "platform"}

labels := qmgrLabelNames
Expand Down Expand Up @@ -673,7 +676,7 @@ func newMqGaugeVecObj(name string, description string, objectType string) *prome
// There can be several channels active of the same name. They can be independently
// identified by the MCAJobName attribute along with connName. So those are set as labels
// on the gauge. The remote qmgr is also useful information to know.
channelLabels := []string{"qmgr", "platform", objectType,
channelLabels := []string{"qmgr", "platform", objectType, "description",
mqmetric.ATTR_CHL_TYPE,
mqmetric.ATTR_CHL_RQMNAME,
mqmetric.ATTR_CHL_CONNNAME,
Expand All @@ -689,7 +692,7 @@ func newMqGaugeVecObj(name string, description string, objectType string) *prome
// Adding the polling queue status options means we can use this block for
// additional attributes. They should have the same labels as the stats generated
// through resource publications.
queueLabels := []string{"qmgr", "platform", objectType, "usage"}
queueLabels := []string{"qmgr", "platform", objectType, "usage", "description"}

switch objectType {
case "channel":
Expand Down

0 comments on commit 8820836

Please sign in to comment.