Skip to content

Commit cbe31d3

Browse files
committed
Minor updates to the "custom" tag PR
1 parent 1b39874 commit cbe31d3

File tree

10 files changed

+88
-10
lines changed

10 files changed

+88
-10
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+
### xxx xx 2025 (v5.6.5)
5+
* Update to MQ 9.4.4
6+
* Add showCustomAttribute filter config setting to include the CUSTOM attribute as metric tag/label
7+
48
### Jun 19 2025 (no new version)
59
* Improve container building
610

cmd/mq_aws/exporter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package main
22

33
/*
4-
Copyright (c) IBM Corporation 2016,2022
4+
Copyright (c) IBM Corporation 2016,2025
55
66
Licensed under the Apache License, Version 2.0 (the "License");
77
you may not use this file except in compliance with the License.

cmd/mq_coll/exporter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package main
22

33
/*
4-
Copyright (c) IBM Corporation 2022
4+
Copyright (c) IBM Corporation 2022, 2025
55
66
Licensed under the Apache License, Version 2.0 (the "License");
77
you may not use this file except in compliance with the License.

cmd/mq_influx/exporter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package main
22

33
/*
4-
Copyright (c) IBM Corporation 2016,2022
4+
Copyright (c) IBM Corporation 2016,2025
55
66
Licensed under the Apache License, Version 2.0 (the "License");
77
you may not use this file except in compliance with the License.

cmd/mq_json/exporter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package main
22

33
/*
4-
Copyright (c) IBM Corporation 2016, 2022
4+
Copyright (c) IBM Corporation 2016, 2025
55
66
Licensed under the Apache License, Version 2.0 (the "License");
77
you may not use this file except in compliance with the License.

cmd/mq_opentsdb/exporter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package main
22

33
/*
4-
Copyright (c) IBM Corporation 2016,2022
4+
Copyright (c) IBM Corporation 2016,2025
55
66
Licensed under the Apache License, Version 2.0 (the "License");
77
you may not use this file except in compliance with the License.

cmd/mq_otel/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,19 @@ package source code. But they include:
5555
- `OTEL_EXPORTER_OTLP_METRICS_INSECURE`
5656
- `OTEL_EXPORTER_OTLP_METRICS_TIMEOUT`
5757

58+
The `*HEADERS` can be used to add header information to the flows, which might permit
59+
use of Basic Auth options for communication to the collector. Something like:
60+
```
61+
s="$user:$password"
62+
b=`echo $s | base64`
63+
v="Basic $b"
64+
export OTEL_EXPORTER_OTLP_HEADERS="Authorization=\"$v\""
65+
```
66+
67+
There is also the `OTEL_RESOURCE_ATTRIBUTES` environment variable, allowing additional key/value
68+
pairs to be added to the reported spans. This propagator does not explicit use that variable as it
69+
does not emit its own spans. But it might be useful for other aspects of your application.
70+
5871

5972
For test purposes, you can get the default OpenTelemetry Collector program running in a container with
6073
```

cmd/mq_otel/reader.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package main
22

33
/*
4-
Copyright (c) IBM Corporation 2024
4+
Copyright (c) IBM Corporation 2024, 2025
55
66
Licensed under the Apache License, Version 2.0 (the "License");
77
you may not use this file except in compliance with the License.

cmd/mq_prometheus/exporter.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package main
22

33
/*
4-
Copyright (c) IBM Corporation 2016, 2024
4+
Copyright (c) IBM Corporation 2016, 2025
55
66
Licensed under the Apache License, Version 2.0 (the "License");
77
you may not use this file except in compliance with the License.
@@ -99,6 +99,7 @@ var (
9999
collectionTimeDesc *prometheus.Desc
100100

101101
supportsHostnameLabelVal *bool
102+
lastHostname = mqmetric.DUMMY_STRING
102103
)
103104

104105
/*
@@ -237,8 +238,15 @@ func (e *exporter) Collect(ch chan<- prometheus.Metric) {
237238
"qmgr": strings.TrimSpace(config.cf.QMgrName),
238239
"description": desc,
239240
"platform": platformString}
241+
242+
// If we are able to get the qmgr's hostname, then use the last-known
243+
// one in this disconnected metric.
244+
// It will get replaced if the qmgr is doing a failover to a different machine.
240245
if supportsHostnameLabel() {
241-
labels["hostname"] = mqmetric.DUMMY_STRING
246+
if lastHostname == "" {
247+
lastHostname = mqmetric.DUMMY_STRING
248+
}
249+
labels["hostname"] = lastHostname
242250
}
243251
if showAndSupportsCustomLabel() {
244252
labels["custom"] = mqmetric.GetObjectCustom("", ibmmq.MQOT_Q_MGR)
@@ -502,7 +510,9 @@ func (e *exporter) Collect(ch chan<- prometheus.Metric) {
502510
"platform": platformString,
503511
"description": desc}
504512
if supportsHostnameLabel() {
505-
labels["hostname"] = mqmetric.GetQueueManagerAttribute(config.cf.QMgrName, ibmmq.MQCACF_HOST_NAME)
513+
// Stash the current hostname so it can be used in the "qmgr down" metric
514+
lastHostname = mqmetric.GetQueueManagerAttribute(config.cf.QMgrName, ibmmq.MQCACF_HOST_NAME)
515+
labels["hostname"] = lastHostname
506516
}
507517
if showAndSupportsCustomLabel() {
508518
labels["custom"] = mqmetric.GetObjectCustom("", ibmmq.MQOT_Q_MGR)

cmd/mq_prometheus/main.go

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ func main() {
140140
discoverConfig.MetaPrefix = config.cf.MetaPrefix
141141
err = mqmetric.DiscoverAndSubscribe(discoverConfig)
142142
e := mqmetric.RediscoverAttributes(ibmmq.MQOT_CHANNEL, config.cf.MonitoredChannels)
143-
e = mqmetric.RediscoverAttributes(mqmetric.OT_CHANNEL_MQTT, config.cf.MonitoredMQTTChannels)
143+
_ = mqmetric.RediscoverAttributes(mqmetric.OT_CHANNEL_MQTT, config.cf.MonitoredMQTTChannels)
144144

145145
log.Debugf("Returned from RediscoverAttributes with error %v tempErr %v", err, e)
146146
}
@@ -205,16 +205,67 @@ func main() {
205205
}
206206
}
207207

208+
// Experimenting ...
209+
// See https://github.com/prometheus/exporter-toolkit/blob/master/web/handler.go
210+
// for an example of how we might add authentication via Basic Auth in here.
211+
//
212+
// This function lets us chain handlers, inserting our own processing on the way
213+
// before the prometheus handler does any work.
214+
// The basic_auth block in the prometheus engine yaml gives us a plaintext password that
215+
// can be crypted/hashed and compared to what's in a local config store. If it's OK, then
216+
// pass the request on to the real processor. Otherwise fail with a suitable HTTP code and
217+
// response. Since this is called on every scrape, we'd want to cache the results of the crypt.
218+
/*
219+
func myHandler(next http.HandlerFunc) http.HandlerFunc {
220+
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
221+
authOK := true
222+
u, p, auth := r.BasicAuth()
223+
// log.Infof(" U: %s P: %s A:%v", u, p, auth)
224+
//log.Infof("Handler headers: %v", r.Header)
225+
//authHeader, ok := r.Header["Authorization"]
226+
//if ok {
227+
// log.Infof("Auth header: %s", authHeader)
228+
//} else {
229+
// log.Infof("Auth header: %s", "N/A")
230+
//}
231+
if auth {
232+
authOK = validateUP(u, p)
233+
}
234+
235+
if authOK {
236+
next.ServeHTTP(w, r)
237+
} else {
238+
w.Header().Set("WWW-Authenticate", "Basic")
239+
http.Error(w, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized)
240+
}
241+
})
242+
}
243+
// A rather simplistic validator!
244+
func validateUP(u string, p string) bool {
245+
rc := true
246+
if u != "user" || p != "password" {
247+
rc = false
248+
}
249+
250+
return rc
251+
}
252+
*/
253+
208254
func startServer() {
209255
var err error
210256
// This function starts a new thread to handle the web server that will then run
211257
// permanently and drive the exporter callback that processes the metric messages
212258

213259
// Need to wait until signalled by the main thread that it's setup the gauges
214260
log.Debug("HTTP server - waiting until MQ connection ready")
261+
262+
//myHandlerFunc := myHandler(promhttp.Handler().(http.HandlerFunc))
263+
215264
<-startChannel
216265

217266
http.Handle(config.httpMetricPath, promhttp.Handler())
267+
//http.Handle(config.httpMetricPath, myHandlerFunc)
268+
218269
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
219270
w.Write(landingPage())
220271
})

0 commit comments

Comments
 (0)