Skip to content

Commit 24c1cc7

Browse files
committed
* Copy in metrics.txt summary of available metrics from mq-golang
* JSON exporter - consistent objecttype for qmgr, merge published and polled metrics (#188) * JSON exporter - allow configuration (`recordmax`) for number of objects printed in a single JSON record (also #188) * AWS exporter -correct interval processing (#192) * Simplified build/run in a single Dockerfile (#194)
1 parent 0c6d9a5 commit 24c1cc7

File tree

29 files changed

+701
-137
lines changed

29 files changed

+701
-137
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
# Changelog
22
Newest updates are at the top of this file.
33

4+
### Jan 10 2023 (v5.3.3)
5+
* Copy in metrics.txt summary of available metrics from mq-golang
6+
* JSON exporter - consistent objecttype for qmgr, merge published and
7+
polled metrics (#188)
8+
* JSON exporter - allow configuration (`recordmax`) for number of objects
9+
printed in a single JSON record (also #188)
10+
* AWS exporter -correct interval processing (#192)
11+
* Simplified build/run in a single Dockerfile (#194)
12+
413
### Oct 18 2022 (v5.3.2)
514
* Update to MQ 9.3.1
615
* Update to use v5.3.2 of mq-golang repository

Dockerfile

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,17 +83,14 @@ RUN apt-get update \
8383
ca-certificates \
8484
&& rm -rf /var/lib/apt/lists/*
8585

86-
# Install MQ client
86+
# Create MQ client directories
8787
WORKDIR /opt/mqm
88-
RUN curl -LO "$RDURL/$VRMF-$RDTAR" \
89-
&& tar -zxf ./*.tar.gz \
90-
&& rm -f ./*.tar.gz \
91-
&& bin/genmqpkg.sh -b /opt/mqm \
92-
&& mkdir -p /IBM/MQ/data/errors \
88+
RUN mkdir -p /IBM/MQ/data/errors \
9389
&& mkdir -p /.mqm \
9490
&& chmod -R 777 /IBM \
9591
&& chmod -R 777 /.mqm
9692

97-
COPY --chmod=777 --from=builder /go/bin/${EXPORTER} /opt/bin/${EXPORTER}
93+
COPY --chmod=555 --from=builder /go/bin/${EXPORTER} /opt/bin/${EXPORTER}
94+
COPY --from=builder /opt/mqm/ /opt/mqm/
9895

99-
CMD ["sh", "-c", "/opt/bin/${EXPORTER}"]
96+
CMD ["sh", "-c", "/opt/bin/${EXPORTER}"]

README.md

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ any privileges to install:
4848
See the README file in the mq-golang repository for more information about any environment variables that may
4949
be required to point at non-default directories for the MQ C SDK.
5050

51-
### Building a component
51+
### Building a component on your system directly
5252

5353
* You need to have the MQ client libraries installed first.
5454
* Create a directory where you want to work with the programs.
@@ -78,14 +78,24 @@ with getting the agent running in your specific environment.
7878
The `-mod=vendor` option is important so that the build process does not need to
7979
download additional files from external repositories.
8080

81-
## Using a Docker container to build the programs
82-
You can use the `buildMonitors.sh` script in the `scripts` subdirectory to build a Docker container that
83-
in turn will build all the binary programs and copy them to a local directory. That script also
84-
sets some extra version-related flags that will be shown when the program starts. The container will
85-
automatically download and install the MQ client runtime files needed for compilation.
81+
## Using containers to build the programs
82+
The `Dockerfile` in the root directory gives a simple way to both build and run a collector program through
83+
containers. You still need to provide the configuration file at runtime, perhaps as a mounted volume. For example:
8684

87-
## Building on Windows
88-
There is a `buildMonitors.bat` file that may help with building on Windows. It assumes you have
85+
```
86+
docker build -t mqprom:1.0 .
87+
docker run -v <directory>/mq_prometheus.yaml:/opt/config/mq_prometheus.yaml mqprom:1.0
88+
```
89+
90+
As a more flexible example, you can use the `buildMonitors.sh` script in the `scripts` subdirectory to
91+
build a Docker container that in turn will build all the binary programs and copy them to a local directory.
92+
That script also sets some extra version-related flags that will be shown when the program starts. The container will
93+
automatically download and install the MQ client runtime files needed for compilation. This might be a preferred approach when you want to run a collector program alongside
94+
a queue manager (perhaps as an MQ SERVICE) and you need to copy the binaries to the
95+
target system.
96+
97+
## Building to run on Windows
98+
There is a `buildMonitors.bat` file to help with building on Windows. It assumes you have
8999
the [tdm-gcc-64](https://jmeubank.github.io/tdm-gcc/download/) 64-bit compiler suite installed. It
90100
builds all the collectors and corresponding YAML configuration files into %GOPATH%/bin
91101

@@ -111,7 +121,7 @@ An alternative collection mechanism uses durable subscriptions for the queue met
111121
the MAXHANDS attribute on a queue manager. (Queue manager-level metrics are still collected using non-durable subscriptions.)
112122

113123
To set it up, you must provide suitable configuration options. In the
114-
YAML configuration, these are the attributes (command line or environment variable equivalents exist):
124+
YAML configuration, these are the attributes (command line or environment variable equivalents also exist):
115125
- `replyQueue` must refer to a local queue (not a model queue)
116126
- `replyQueue2` must also be set, referring to a different local queue
117127
- `durableSubPrefix` is a string that is unique across any collectors that might be connected to this queue manager
@@ -237,7 +247,7 @@ That allows it to be piped from an external stash file or some other
237247
mechanism. Using the command line flags for controlling passwords is not
238248
recommended for security-sensitive environments.
239249

240-
Where authentication is needed for access to the database, passwords for those can
250+
Where authentication is needed for access to a database, passwords for those can
241251
also be passed via stdin.
242252

243253
## YAML configuration for all exporters
@@ -272,7 +282,8 @@ The command line flags are highest precedence. Environment variables override se
272282

273283
## More information
274284
Each of the sample monitor programs has its own README file describing any particular
275-
considerations.
285+
considerations. The metrics.txt file in this directory has a summary of the available
286+
metrics for each object type.
276287

277288
## History
278289

@@ -289,4 +300,4 @@ in the DCO.
289300

290301
## Copyright
291302

292-
© Copyright IBM Corporation 2016, 2022
303+
© Copyright IBM Corporation 2016, 2023

cmd/mq_aws/exporter.go

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

33
/*
4-
Copyright (c) IBM Corporation 2016,2021
4+
Copyright (c) IBM Corporation 2016,2022
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.
@@ -245,23 +245,25 @@ func Collect() error {
245245
}
246246

247247
series = "qmgr"
248-
if key != mqmetric.QMgrMapKey {
248+
if key == mqmetric.QMgrMapKey {
249+
tags["description"] = mqmetric.GetObjectDescription("", ibmmq.MQOT_Q_MGR)
250+
} else {
249251
tags["queue"] = key
250252
series = "queue"
251-
}
252253

253-
usage := ""
254-
if usageAttr, ok := mqmetric.GetObjectStatus("", mqmetric.OT_Q).Attributes[mqmetric.ATTR_Q_USAGE].Values[key]; ok {
255-
if usageAttr.ValueInt64 == 1 {
256-
usage = "XMITQ"
257-
} else {
258-
usage = "NORMAL"
254+
usage := ""
255+
if usageAttr, ok := mqmetric.GetObjectStatus("", mqmetric.OT_Q).Attributes[mqmetric.ATTR_Q_USAGE].Values[key]; ok {
256+
if usageAttr.ValueInt64 == 1 {
257+
usage = "XMITQ"
258+
} else {
259+
usage = "NORMAL"
260+
}
259261
}
260-
}
261262

262-
tags["usage"] = usage
263-
tags["description"] = mqmetric.GetObjectDescription(key, ibmmq.MQOT_Q)
264-
tags["cluster"] = mqmetric.GetQueueAttribute(key, ibmmq.MQCA_CLUSTER_NAME)
263+
tags["usage"] = usage
264+
tags["description"] = mqmetric.GetObjectDescription(key, ibmmq.MQOT_Q)
265+
tags["cluster"] = mqmetric.GetQueueAttribute(key, ibmmq.MQCA_CLUSTER_NAME)
266+
}
265267

266268
pt, _ := newPoint(series+"."+elem.MetricName, t, float64(f), tags)
267269
bp.addPoint(pt)
@@ -451,8 +453,9 @@ func Collect() error {
451453
qMgrName := strings.TrimSpace(config.cf.QMgrName)
452454

453455
tags := map[string]string{
454-
"qmgr": qMgrName,
455-
"platform": platformString,
456+
"qmgr": qMgrName,
457+
"platform": platformString,
458+
"description": mqmetric.GetObjectDescription("", ibmmq.MQOT_Q_MGR),
456459
}
457460

458461
f := mqmetric.QueueManagerNormalise(attr, value.ValueInt64)

cmd/mq_aws/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func main() {
4949

5050
if err == nil {
5151
interval := config.ci.Interval
52-
d, err := time.ParseDuration(interval)
52+
d, err = time.ParseDuration(interval)
5353
if err != nil || d.Seconds() <= 1 {
5454
log.Errorln("Invalid value or too short for interval parameter: ", err)
5555
os.Exit(1)

cmd/mq_coll/exporter.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,10 @@ func Collect() error {
200200
}
201201

202202
series = "qmgr"
203-
if key != mqmetric.QMgrMapKey {
203+
if key == mqmetric.QMgrMapKey {
204+
tags["description"] = mqmetric.GetObjectDescription("", ibmmq.MQOT_Q_MGR)
205+
206+
} else {
204207
series = "queue"
205208
tags[series] = key
206209
usage := ""
@@ -365,8 +368,9 @@ func Collect() error {
365368
qMgrName := strings.TrimSpace(config.cf.QMgrName)
366369

367370
tags := map[string]string{
368-
"qmgr": qMgrName,
369-
"platform": platformString,
371+
"qmgr": qMgrName,
372+
"platform": platformString,
373+
"description": mqmetric.GetObjectDescription("", ibmmq.MQOT_Q_MGR),
370374
}
371375

372376
f := mqmetric.QueueManagerNormalise(attr, value.ValueInt64)

cmd/mq_influx/exporter.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,9 @@ func Collect(c client.Client) error {
230230
}
231231

232232
series = "qmgr"
233-
if key != mqmetric.QMgrMapKey {
233+
if key == mqmetric.QMgrMapKey {
234+
tags["description"] = mqmetric.GetObjectDescription("", ibmmq.MQOT_Q_MGR)
235+
} else {
234236
tags["queue"] = key
235237
series = "queue"
236238
usage := ""
@@ -422,8 +424,9 @@ func Collect(c client.Client) error {
422424
qMgrName := strings.TrimSpace(config.cf.QMgrName)
423425

424426
tags := map[string]string{
425-
"qmgr": qMgrName,
426-
"platform": platformString,
427+
"qmgr": qMgrName,
428+
"platform": platformString,
429+
"description": mqmetric.GetObjectDescription("", ibmmq.MQOT_Q_MGR),
427430
}
428431

429432
f := mqmetric.QueueManagerNormalise(attr, value.ValueInt64)

cmd/mq_json/README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,18 @@ jq -c '.collectionTime.timeStamp as $t | .points[] |
9696
{"time":$t, "chl":.tags.channel, "msg":.metrics.messages}'
9797
```
9898

99-
The configuration option `oneline`can be used to print a complete JSON record as a single
99+
### Collector configuration options
100+
The collector-specific options can be seen in `config.collector.yaml` in this directory.
101+
102+
* The `oneline` option can be used to print a complete JSON record as a single
100103
line instead of pretty-printed across mutiple lines. That might be helpful for some tools that
101104
ingest JSON and prefer to have a single line inputs.
102105

106+
* The `recordmax` option declares how many objects are printed in a single array at each interval. If
107+
more objects have been recorded, then additional arrays are printed. This may help if processing tools
108+
have limits on the total record size that can be handled for a single JSON object. Setting the value to `0`
109+
means there is no effective limit.
110+
103111
## Metrics
104112
Once the monitor program has been started, you will see metrics being available.
105113
More information on the metrics collected through the publish/subscribe

cmd/mq_json/config.collector.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11

22

33
# This is the collector-specific piece of the configuration
4+
# The defaults here record the output on single lines, with at most 100 objects reported in
5+
# each JSON object. Additional objects will be reported in a separate JSON object with the same
6+
# timestamp.
47
json:
58
interval: 10s
9+
oneline: true
10+
recordmax: 100

cmd/mq_json/config.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,16 @@ import (
2323
)
2424

2525
type mqTTYConfig struct {
26-
cf cf.Config
27-
interval string
28-
oneline bool
26+
cf cf.Config
27+
interval string
28+
oneline bool
29+
recordmax int
2930
}
3031

3132
type ConfigYJson struct {
32-
Interval string
33-
OneLine bool
33+
Interval string
34+
OneLine bool `yaml:"oneline"`
35+
RecordMax int `yaml:"recordmax"`
3436
}
3537

3638
type mqExporterConfigYaml struct {
@@ -54,6 +56,7 @@ func initConfig() error {
5456

5557
cf.AddParm(&config.interval, "10s", cf.CP_STR, "ibmmq.interval", "json", "interval", "How long between each collection")
5658
cf.AddParm(&config.oneline, false, cf.CP_BOOL, "ibmmq.oneline", "json", "oneline", "JSON output on a single line")
59+
cf.AddParm(&config.recordmax, 100, cf.CP_INT, "ibmmq.recordmax", "json", "recordmax", "Max records in a single JSON array")
5760

5861
err = cf.ParseParms()
5962

@@ -64,6 +67,7 @@ func initConfig() error {
6467
cf.CopyYamlConfig(&config.cf, cfy.Global, cfy.Connection, cfy.Objects, cfy.Filters)
6568
config.interval = cf.CopyParmIfNotSetStr("json", "interval", cfy.JSON.Interval)
6669
config.oneline = cf.CopyParmIfNotSetBool("json", "oneline", cfy.JSON.OneLine)
70+
config.recordmax = cf.CopyParmIfNotSetInt("json", "recordmax", cfy.JSON.RecordMax)
6771
}
6872
}
6973
}

0 commit comments

Comments
 (0)