Skip to content

Commit 86966e4

Browse files
committed
Add QSTATUS options
1 parent 6eb2358 commit 86966e4

File tree

8 files changed

+415
-31
lines changed

8 files changed

+415
-31
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Changelog
22

33
=======
4+
### November 2018
5+
* Added functions to mqmetric to issue DISPLAY QSTATUS for additional stats
6+
47
### October 2018
58
* Allow compilation against MQ v8
69

README.md

Lines changed: 50 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,41 +4,58 @@ This repository demonstrates how you can call IBM MQ from applications written i
44

55
> **NOTICE**: Please ensure that you use a dependency management tool such as [dep](https://github.com/golang/dep) or [Glide](http://glide.sh/), and add a specific version dependency.
66
7-
This repository previously contained sample programs that exported MQ statistics to some monitoring packages. These have now been moved to a new [GitHub repository called mq-metric-samples](https://github.com/ibm-messaging/mq-metric-samples).
7+
This repository previously contained sample programs that exported MQ statistics to
8+
some monitoring packages. These have now been moved to a
9+
new [GitHub repository called mq-metric-samples](https://github.com/ibm-messaging/mq-metric-samples).
810

9-
A minimum level of MQ V8 is required to build these packages.
10-
However, note that the monitoring data published by the queue manager is not available before MQ V9.
11+
A minimum level of MQ V8 is required to build these packages. However, note that
12+
the monitoring data published by the queue manager is not available before MQ V9.
1113

1214
## Health Warning
1315

14-
This package is provided as-is with no guarantees of support or updates. There are also no guarantees of compatibility with any future versions of the package; the API is subject to change based on any feedback.
16+
This package is provided as-is with no guarantees of support or updates. There are
17+
also no guarantees of compatibility with any future versions of the package; the API
18+
is subject to change based on any feedback. Versioned releases are made in this repository
19+
to assist with using stable APIs.
1520

1621
## MQI Description
1722

1823
The ibmmq directory contains a Go package, exposing an MQI-like interface.
1924

20-
The intention is to give an API that is more natural for Go programmers than the common procedural MQI. For example, fixed length string arrays from the C API such as MQCHAR48 are represented by the native Go string type. Conversion between these types is handled within the ibmmq package itself, removing the need for Go programmers to know about it.
25+
The intention is to give an API that is more natural for Go programmers than the
26+
common procedural MQI. For example, fixed length string arrays from the C API such
27+
as MQCHAR48 are represented by the native Go string type. Conversion between these
28+
types is handled within the ibmmq package itself, removing the need for Go programmers
29+
to know about it.
2130

22-
A short program in the samples/mqitest directory gives an example of using this interface, to put and get messages and to subscribe to a topic.
31+
A short program in the samples/mqitest directory gives an example of using this interface,
32+
to put and get messages and to subscribe to a topic.
2333

2434
The mqmetric directory contains functions to help monitoring programs access MQ status and
2535
statistics. This package is not needed for general application programs.
2636

27-
Feedback on the utility of this package, thoughts about whether it should be changed or extended are welcomed.
28-
2937
## Using the package
3038

31-
To use code in this repository, you will need to be able to build Go applications, and have a copy of MQ installed to build against. It uses cgo to access the MQI C structures and definitions. It assumes that MQ has been installed in the default location on a Linux platform (`/opt/mqm`) but you can easily change the cgo directives in the source files if necessary.
39+
To use code in this repository, you will need to be able to build Go applications, and
40+
have a copy of MQ installed to build against. It uses cgo to access the MQI C
41+
structures and definitions. It assumes that MQ has been installed in the default
42+
location (on a Linux platform this would be `/opt/mqm`) but this can be changed
43+
with environment variables if necessary.
3244

33-
Some Windows capability is also included. This has been tested with Go 1.10 compiler, which now permits standard Windows paths (eg including spaces) so the CGO directives can point at the normal MQ install path.
45+
Windows compatibility is also included. This has been tested with Go 1.10 compiler,
46+
which now permits standard Windows paths (eg including spaces) so the CGO directives
47+
can point at the normal MQ install path.
3448

3549
## Getting started
3650

37-
If you are unfamiliar with Go, the following steps can help create a working environment with source code in a suitable tree. Initial setup tends to be platform-specific, but subsequent steps are independent of the platform.
51+
If you are unfamiliar with Go, the following steps can help create a working environment
52+
with source code in a suitable tree. Initial setup tends to be platform-specific,
53+
but subsequent steps are independent of the platform.
3854

3955
### Linux
4056

41-
* Install the Go runtime and compiler. On Linux, the packaging may vary but a typical directory for the code is `/usr/lib/golang`.
57+
* Install the Go runtime and compiler. On Linux, the packaging may vary but a typical
58+
directory for the code is `/usr/lib/golang`.
4259

4360
* Create a working directory. For example, ```mkdir $HOME/gowork```
4461

@@ -81,6 +98,14 @@ set CC=x86_64-w64-mingw32-gcc.exe
8198

8299
`git clone https://github.com/ibm-messaging/mq-golang.git src/github.com/ibm-messaging/mq-golang`
83100

101+
* If you have not installed MQ libraries into the default location, then set environment variables
102+
for the C compiler to recognise those directories. For example,
103+
104+
```
105+
export CGO_CFLAGS="-I/my/mq/dir/inc"
106+
export CGO_LDFLAGS="-I/my/mq/dir/lib64"
107+
```
108+
84109
* Compile the `ibmmq` component:
85110

86111
`go install ./src/github.com/ibm-messaging/mq-golang/ibmmq`
@@ -89,9 +114,11 @@ set CC=x86_64-w64-mingw32-gcc.exe
89114

90115
`go install ./src/github.com/ibm-messaging/mq-golang/mqmetric`
91116

92-
* Follow the instructions in the [mq-metric-samples repository](https://github.com/ibm-messaging/mq-metric-samples) to compile the sample programs you are interested in.
117+
* Sample programs can be compiled in this way
118+
119+
`go build -o bin/mqitest ./src/github.com/ibm-messaging/mq-golang/samples/mqitest/*.go`
93120

94-
At this point, you should have a compiled copy of the code in `$GOPATH/bin`.
121+
At this point, you should have a compiled copy of the program in `$GOPATH/bin`.
95122

96123
## Limitations
97124

@@ -111,11 +138,16 @@ See [CHANGELOG](CHANGELOG.md) in this directory.
111138

112139
## Issues and Contributions
113140

114-
For feedback and issues relating specifically to this package, please use the [GitHub issue tracker](https://github.com/ibm-messaging/mq-golang/issues).
141+
Feedback on the utility of this package, thoughts about whether it should be changed
142+
or extended are welcomed.
143+
144+
For feedback and issues relating specifically to this package, please use
145+
the [GitHub issue tracker](https://github.com/ibm-messaging/mq-golang/issues).
115146

116-
Contributions to this package can be accepted under the terms of the IBM Contributor License Agreement,
117-
found in the [CLA file](CLA.md) of this repository. When submitting a pull request, you must include a statement stating
118-
you accept the terms in the CLA.
147+
Contributions to this package can be accepted under the terms of the IBM Contributor
148+
License Agreement, found in the [CLA file](CLA.md) of this repository. When
149+
submitting a pull request, you must include a statement stating you accept the terms
150+
in the CLA.
119151

120152
## Copyright
121153

ibmmq/mqi.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@ the particular MQRC or MQCC values.
1616
1717
The build directives assume the default MQ installation path
1818
which is in /opt/mqm (Linux) and c:\Program Files\IBM\MQ (Windows).
19-
These would need to be changed in this file if you use a
20-
non-default path.
19+
If you use a non-default path for the installation, you can set
20+
environment variables CGO_CFLAGS and CGO_LDFLAGS to reference those
21+
directories.
2122
*/
2223
package ibmmq
2324

2425
/*
25-
Copyright (c) IBM Corporation 2016
26+
Copyright (c) IBM Corporation 2016, 2018
2627
2728
Licensed under the Apache License, Version 2.0 (the "License");
2829
you may not use this file except in compliance with the License.

mqmetric/channel.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ const (
5353
)
5454

5555
var ChannelStatus StatusSet
56-
var attrsInit = false
56+
var chlAttrsInit = false
5757
var channelsSeen map[string]bool
5858

5959
/*
@@ -65,7 +65,7 @@ text. The elements can be expanded later; just trying to give a starting point
6565
for now.
6666
*/
6767
func ChannelInitAttributes() {
68-
if attrsInit {
68+
if chlAttrsInit {
6969
return
7070
}
7171
ChannelStatus.Attributes = make(map[string]*StatusAttribute)
@@ -98,7 +98,7 @@ func ChannelInitAttributes() {
9898
attr = ATTR_CHL_STATUS_SQUASH
9999
ChannelStatus.Attributes[attr] = newStatusAttribute(attr, "Channel Status - Simplified", ibmmq.MQIACH_CHANNEL_STATUS)
100100
ChannelStatus.Attributes[attr].squash = true
101-
attrsInit = true
101+
chlAttrsInit = true
102102
}
103103

104104
// If we need to list the channels that match a pattern. Not needed for
@@ -252,7 +252,7 @@ func collectChannelStatus(pattern string, instanceType int32) error {
252252
if cfh.Reason != ibmmq.MQRC_NONE {
253253
continue
254254
}
255-
key := parseData(instanceType, cfh, replyBuf[offset:datalen])
255+
key := parseChlData(instanceType, cfh, replyBuf[offset:datalen])
256256
if key != "" {
257257
channelsSeen[key] = true
258258
}
@@ -263,7 +263,7 @@ func collectChannelStatus(pattern string, instanceType int32) error {
263263
}
264264

265265
// Given a PCF response message, parse it to extract the desired statistics
266-
func parseData(instanceType int32, cfh *ibmmq.MQCFH, buf []byte) string {
266+
func parseChlData(instanceType int32, cfh *ibmmq.MQCFH, buf []byte) string {
267267
var elem *ibmmq.PCFParameter
268268

269269
chlName := ""

mqmetric/discover.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ var Metrics AllMetrics
9090

9191
var qList []string
9292

93+
func GetDiscoveredQueues() []string {
94+
return qList
95+
}
96+
9397
/*
9498
DiscoverAndSubscribe does all the work of finding the
9599
different resources available from a queue manager and
@@ -349,7 +353,7 @@ func discoverQueues(monitoredQueues string) error {
349353
var err error
350354
qList, err = inquireObjects(monitoredQueues, ibmmq.MQOT_Q)
351355
if len(qList) > 0 {
352-
fmt.Printf("Monitoring Queues: %v\n", qList)
356+
//fmt.Printf("Monitoring Queues: %v\n", qList)
353357
if err != nil {
354358
// fmt.Printf("Queue Discovery: %v\n", err)
355359
}

0 commit comments

Comments
 (0)