Skip to content

Commit 2b9779c

Browse files
committed
Update to 905
Add MQ userid/password to prometheus monitor
1 parent 44e1f1e commit 2b9779c

File tree

24 files changed

+803
-175
lines changed

24 files changed

+803
-175
lines changed

README.md

Lines changed: 12 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ packages including Prometheus, InfluxDB and OpenTSDB.
66

77
A minimum level of MQ V9 is required to build this package.
88
The monitoring data published by the queue manager is not available before
9-
that version.
9+
that version; the interface also assumes availability of
10+
MQI structures from that level of MQ.
1011

1112
## MQI Description
1213

@@ -30,14 +31,9 @@ have a copy of MQ installed to build against. It uses cgo to access the MQI C st
3031
installed in the default location on a Linux platform (/opt/mqm) but you can easily change the
3132
cgo directives in the source files if necessary.
3233

33-
A minimum level of MQ V9 is required. The monitoring data published
34-
by the queue manager is not available before that version.
35-
36-
Some Windows capability is also included. One constraint in the cgo package is its support
37-
for path names containing spaces and special characters, which makes it tricky to
38-
compile against a copy of MQ installed in the regular location. To build these packages I copied
39-
<mq install>/tools/c/include and <mq install>/bin64 to be under a temporary directory, shown
40-
in the CFLAGS and LDFLAGS directives.
34+
Some Windows capability is also included. This has been tested with Go 1.10
35+
compiler, which now permits standard Windows paths (eg including spaces)
36+
so the CGO directives can point at the normal MQ install path.
4137

4238
## Getting started
4339

@@ -57,6 +53,10 @@ but a typical directory for the code is /usr/lib/golang.
5753

5854
export GOPATH=$HOME/gowork
5955

56+
* If using a version of Go from after 2017, you must set environment variables
57+
to permit some compile/link flags. This is due to a security fix in the compiler.
58+
export CGO_LDFLAGS_ALLOW="-Wl,-rpath.*"
59+
6060
* Install the git client
6161

6262
### Windows
@@ -75,6 +75,7 @@ be used on systems without Cygwin installed
7575

7676
set CC=x86_64-w64-mingw32-gcc.exe
7777

78+
* The CGO_LDFLAGS_ALLOW variable is not needed on Windows
7879
* Install the git client
7980
* Make sure the MQ include files and libraries are in a path that does
8081
not include spaces or other special characters, as discussed above.
@@ -121,83 +122,14 @@ There are also no structure handlers for message headers such as MQRFH2 or MQDLH
121122

122123
## History
123124

124-
08 Jul 2016
125-
* Initial release
126-
127-
18 Jul 2016
128-
* Changed structures so that most applications will not need to use cgo to imbed the MQ C headers
129-
* Go programs will now use int32 where C programs use MQLONG
130-
* Use of message handles, distribution lists require cgo for now
131-
* Package ibmmq now includes the numeric #defines as a Go file, cmqc.go, for easier use
132-
* Removed "src/" prefix from tree in github repo
133-
* Removed need for buffer length parm on Put/Put1
134-
* Updated comments
135-
* Added MQINQ
136-
* Added MQItoString function for some maps of values to constant names
137-
138-
25 Jul 2016
139-
* Added functions to handle basic PCF creation and parsing
140-
* Added a monitor command for exporting MQ V9 queue manager data to Prometheus. See
141-
the [README](cmd/mq_prometheus/README.md) for more details
142-
143-
04 Aug 2016
144-
* Added a monitor command for exporting MQ data to InfluxDB. See the [README]
145-
(cmd/mq_influx/README.md) for more details
146-
* Restructured the monitoring code to put common material in the mqmetric
147-
package, called from the Influx and Prometheus monitors.
148-
149-
12 Aug 2016
150-
* Added a OpenTSDB monitor. See the [README](cmd/mq_opentsdb/README.md) for
151-
more details.
152-
* Added a Collectd monitor. See the [README](cmd/mq_coll/README.md) for
153-
more details.
154-
* Added MQI MQCNO/MQCSP structures to support client connections and password authentication
155-
with MQCONNX.
156-
* Allow client-mode connections from the monitor programs
157-
* Added Grafana dashboards for the different monitors to show how to query them
158-
* Changed database password mechanism so that "exec" maintains the PID for MQ services
159-
160-
23 Aug 2016
161-
* Added a collector for Amazon AWS CloudWatch monitoring. See the [README](cmd/mq_aws/README.md)
162-
for more details.
163-
164-
17 Oct 2016
165-
* Added some Windows support. An example batch file is included in the mq_influx directory;
166-
changes would be needed to the MQSC script to call it. The other monitor programs can be
167-
supported with similar modifications.
168-
* Added a "getting started" section to this README.
169-
170-
07 Nov 2016
171-
* Added a collector that prints metrics in a simple JSON format.
172-
See the [README](cmd/mq_json/README.md) for more details.
173-
* Fixed bug where freespace metrics were showing as non-integer bytes, not percentages
174-
175-
14 Dec 2016
176-
* Minor updates to this README for formatting
177-
* Removed xxx_CURRENT_LENGTH definitions from cmqc
178-
179-
10 Jan 2017
180-
* Added support for the MQCD and MQSCO structures to allow programmable client
181-
connectivity, without requiring a CCDT. See the clientconn sample program
182-
for an example of using the MQCD.
183-
* Moved sample programs into subdirectory
184-
185-
15 Feb 2017
186-
* API BREAKING CHANGE: The MQI verbs have been changed to return a single
187-
error indicator instead of two separate values. See mqitest.go for
188-
examples of how MQRC/MQCC codes can now be tested and extracted. This change
189-
makes the MQI implementation a bit more natural for Go environments.
190-
191-
25 Mar 2017
192-
* Added the metaPrefix option to the Prometheus monitor. This allows selection of non-default resources such as the MQ Bridge for Salesforce included in MQ 9.0.2.
193-
125+
See [CHANGES](https://github.com/ibm-messaging/mq-golang/CHANGES.md).
194126

195127
## Health Warning
196128

197129
This package is provided as-is with no guarantees of support or updates. There are also no guarantees of compatibility
198130
with any future versions of the package; the API is subject to change based on any feedback.
199131

200-
##Issues and Contributions
132+
## Issues and Contributions
201133

202134
For feedback and issues relating specifically to this package, please use the [GitHub issue tracker](https://github.com/ibm-messaging/mq-golang/issues).
203135

cmd/mq_aws/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ type mqCloudWatchConfig struct {
3333

3434
namespace string
3535

36-
cc mqmetric.ClientConfig
36+
cc mqmetric.ConnectionConfig
3737

3838
interval string
3939
maxErrors int

cmd/mq_coll/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ type mqTTYConfig struct {
3232
hostname string
3333
hostlabel string // Used in the output string
3434

35-
cc mqmetric.ClientConfig
35+
cc mqmetric.ConnectionConfig
3636

3737
interval string
3838

cmd/mq_influx/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ type mqInfluxConfig struct {
3333
monitoredQueues string
3434
monitoredQueuesFile string
3535

36-
cc mqmetric.ClientConfig
36+
cc mqmetric.ConnectionConfig
3737

3838
databaseName string
3939
databaseAddress string

cmd/mq_json/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ type mqTTYConfig struct {
2929
monitoredQueues string
3030
monitoredQueuesFile string
3131

32-
cc mqmetric.ClientConfig
32+
cc mqmetric.ConnectionConfig
3333

3434
interval string
3535

cmd/mq_opentsdb/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ type mqOpenTSDBConfig struct {
3333
monitoredQueues string
3434
monitoredQueuesFile string
3535

36-
cc mqmetric.ClientConfig
36+
cc mqmetric.ConnectionConfig
3737

3838
databaseName string
3939
databaseAddress string

cmd/mq_prometheus/README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ create a data source in Grafana called "MQ Prometheus" that points at your
2121
database server, and then import the JSON file.
2222

2323
There is also a script to start the collector so that it processes
24-
the statistics generated by the MQ Bridge for Salesforce, included in
24+
the statistics generated by the MQ Bridge for Salesforce, included in
2525
MQ V9.0.2
2626

2727

@@ -77,6 +77,14 @@ of the monitor program. If you want to change the patterns, or new
7777
queues are defined that match an existing pattern, the monitor must be
7878
restarted with a `STOP SERVICE` and `START SERVICE` pair of commands.
7979

80+
### Authentication
81+
This monitor can be configured to authenticate to the queue manager,
82+
sending a userid and password.
83+
84+
The userid is configured using the `-ibmmq.userid` flag. The password can
85+
be set either by using the `-ibmmq.password` flag, or by passing it via stdin.
86+
That allows it to be piped from an external stash file or some other
87+
mechanism. Command line flags for controlling passwords are not recommended!
8088

8189
## Configuring Prometheus
8290
The Prometheus server has to know how to contact the MQ monitor. The

cmd/mq_prometheus/config.go

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,11 @@ package main
1919
*/
2020

2121
import (
22+
"bufio"
2223
"flag"
24+
"fmt"
2325
"mqmetric"
26+
"os"
2427
)
2528

2629
type mqExporterConfig struct {
@@ -29,17 +32,23 @@ type mqExporterConfig struct {
2932
monitoredQueues string
3033
monitoredQueuesFile string
3134

35+
// TODO: enable these
36+
monitorChannelStatistics bool
37+
statisticsQueueName string
38+
3239
metaPrefix string
3340

34-
cc mqmetric.ClientConfig
41+
cc mqmetric.ConnectionConfig
3542

3643
httpListenPort string
3744
httpMetricPath string
3845
logLevel string
46+
namespace string
3947
}
4048

4149
const (
42-
defaultPort = "9157" // reserved in the prometheus wiki
50+
defaultPort = "9157" // reserved in the prometheus wiki
51+
defaultNamespace = "ibmmq"
4352
)
4453

4554
var config mqExporterConfig
@@ -61,15 +70,32 @@ func initConfig() {
6170
flag.StringVar(&config.metaPrefix, "metaPrefix", "", "Override path to monitoring resource topic")
6271

6372
flag.BoolVar(&config.cc.ClientMode, "ibmmq.client", false, "Connect as MQ client")
73+
flag.StringVar(&config.cc.UserId, "ibmmq.userid", "", "UserId for MQ connection")
74+
// TODO: Also enable a different mechanism to read the password
75+
flag.StringVar(&config.cc.Password, "ibmmq.password", "", "Password for MQ connection")
76+
77+
// TODO: turn these on
78+
//flag.BoolVar(&config.monitorChannelStatistics, "ibmmq.monitorChannelStatistics", false, "Whether to collect channel stats")
79+
//flag.StringVar(&config.statisticsQueueName, "ibmmq.statisticsQueueName", "SYSTEM.ADMIN.STATISTICS.QUEUE", "Which queue holds channel stats")
80+
config.monitorChannelStatistics = false
81+
config.statisticsQueueName = ""
6482

6583
flag.StringVar(&config.httpListenPort, "ibmmq.httpListenPort", defaultPort, "HTTP Listener")
6684
flag.StringVar(&config.httpMetricPath, "ibmmq.httpMetricPath", "/metrics", "Path to exporter metrics")
6785

6886
flag.StringVar(&config.logLevel, "log.level", "error", "Log level - debug, info, error")
87+
flag.StringVar(&config.namespace, "namespace", defaultNamespace, "Log level - debug, info, error")
6988

7089
flag.Parse()
7190

7291
if config.monitoredQueuesFile != "" {
7392
config.monitoredQueues = mqmetric.ReadPatterns(config.monitoredQueuesFile)
7493
}
94+
95+
if config.cc.UserId != "" && config.cc.Password == "" {
96+
scanner := bufio.NewScanner(os.Stdin)
97+
fmt.Printf("Enter password: \n")
98+
scanner.Scan()
99+
config.cc.Password = scanner.Text()
100+
}
75101
}

cmd/mq_prometheus/exporter.go

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,6 @@ var (
4949
gaugeMap = make(map[string]*prometheus.GaugeVec)
5050
)
5151

52-
const (
53-
namespace = "ibmmq"
54-
)
55-
5652
/*
5753
Describe is called by Prometheus on startup of this monitor. It needs to tell
5854
the caller about all of the available metrics.
@@ -185,7 +181,7 @@ func newMqGaugeVec(elem *mqmetric.MonElement) *prometheus.GaugeVec {
185181

186182
gaugeVec := prometheus.NewGaugeVec(
187183
prometheus.GaugeOpts{
188-
Namespace: namespace,
184+
Namespace: config.namespace,
189185
Name: prefix + elem.MetricName,
190186
Help: elem.Description,
191187
},
@@ -195,3 +191,29 @@ func newMqGaugeVec(elem *mqmetric.MonElement) *prometheus.GaugeVec {
195191
log.Infof("Created gauge for %s", elem.MetricName)
196192
return gaugeVec
197193
}
194+
195+
/*
196+
newMqGaugeVec returns the structure which will contain the
197+
values and suitable labels. For queues we tag each entry
198+
with both the queue and qmgr name; for the qmgr-wide entries, we
199+
only need the single label.
200+
*/
201+
202+
// TODO: Finish this
203+
/*
204+
func newMqGaugeVecChl(elem *ibmmq.Statistic) *prometheus.GaugeVec {
205+
prefix := "channel_"
206+
207+
gaugeVec := prometheus.NewGaugeVec(
208+
prometheus.GaugeOpts{
209+
Namespace: config.namespace,
210+
Name: prefix + elem.MetricName,
211+
Help: elem.Description,
212+
},
213+
labels,
214+
)
215+
216+
log.Infof("Created gauge for %s", elem.MetricName)
217+
return gaugeVec
218+
}
219+
*/

cmd/mq_prometheus/main.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func main() {
4747
log.Infoln("Starting IBM MQ metrics exporter for Prometheus monitoring")
4848

4949
// Connect and open standard queues
50-
err = mqmetric.InitConnection(config.qMgrName, config.replyQ, &config.cc)
50+
err = mqmetric.InitConnectionStats(config.qMgrName, config.replyQ, config.statisticsQueueName, &config.cc)
5151
if err == nil {
5252
log.Infoln("Connected to queue manager ", config.qMgrName)
5353
defer mqmetric.EndConnection()
@@ -71,6 +71,12 @@ func main() {
7171
allocateGauges()
7272
}
7373

74+
// TODO: continue with the channel stat collection
75+
if err == nil && config.statisticsQueueName != "" {
76+
mqmetric.InitChlStatistics()
77+
//allocateChlGauges()
78+
}
79+
7480
// Go into main loop for handling requests from Prometheus
7581
if err == nil {
7682
exporter := newExporter()

0 commit comments

Comments
 (0)