|
| 1 | +# Notes on the `mqmetric` package |
| 2 | + |
| 3 | +This package was originally designed with the specific intention of supporting monitoring |
| 4 | +programs that put MQ metrics into databases such as Prometheus. Those programs started off in |
| 5 | +this repository. When they were moved to the `mq-metrics-samples` repository, it might have been |
| 6 | +better to move this package with them. But that wasn't done. And it would be difficult to move them |
| 7 | +now, as I know of some other monitoring solutions that have made use of the package. |
| 8 | + |
| 9 | +So it was never intended to be a general purpose API, but builds on the core `ibmmq` API to |
| 10 | +simplify a number of tasks needed for the monitors. |
| 11 | + |
| 12 | +### Main APIs |
| 13 | +The core public APIs are in `mqif` and `discover`. |
| 14 | + |
| 15 | +* `mqif.go`: Manages the connection to a queue manager (via `InitConnection`) and can |
| 16 | +return some information about the queue manager |
| 17 | + * InitConnection |
| 18 | + * InitConnectionKey |
| 19 | + * EndConnection |
| 20 | + * GetPlatform |
| 21 | + * GetCommandLevel |
| 22 | +* `discover.go`: Handles the discovery of the metrics published by a queue manager, and then makes the |
| 23 | +subscriptions to required topics. It also processes those publications, building maps containing the |
| 24 | +various metrics and their values, tied to the object names. |
| 25 | + * VerifyConfig |
| 26 | + * DiscoverAndSubscribe |
| 27 | + * RediscoverAndSubscribe |
| 28 | + * RediscoverAttributes |
| 29 | + * ProcessPublications |
| 30 | + * Normalise |
| 31 | + * ReadPatterns |
| 32 | + * VerifyPattern |
| 33 | + * VerifyQueuePatterns |
| 34 | + * FilterRegExp |
| 35 | + * SetLocale |
| 36 | + * GetProcessPublicationCount |
| 37 | + * GetObjectDescription |
| 38 | + * GetDiscoveredQueues |
| 39 | +* `globals.go`: Ways to access the metrics without directly referring to global variables. Added to deal |
| 40 | +with the multiple connection redesign |
| 41 | + * GetObjectStatus |
| 42 | + * GetPublishedMetrics |
| 43 | + * SetConnectionKey |
| 44 | + * GetConnectionKey |
| 45 | +* `<objecttype>.go`: Similar processing is available for each object type such as channel or queue. The |
| 46 | +public APIs first initialise the status attributes explicitly supported (ie not coming from the published metadata) |
| 47 | +and then collect the values. The xxNormalise functions ensure the metrics are in a suitable scale and datatype. |
| 48 | + * xxInitAttributes (eg UsageInitAttributes) |
| 49 | + * CollectXxStatus (eg CollectQueueStatus) |
| 50 | + * xxNormalise (eg ChannelNormalise) |
| 51 | + * InquireXxs (eg InquireTopics) |
| 52 | +* `log.go`: The `SetLogger` function is called by a collector program to setup the output location for |
| 53 | +error/info/trace logging. |
| 54 | + |
| 55 | +### Multiple connection support |
| 56 | +The code was written with the intention of just handling a single connection to a single queue manager |
| 57 | +and collecting its various metrics serially. The close integration of the collectors and this package led to |
| 58 | +various global public variables that could be accessed directly. |
| 59 | + |
| 60 | +The March 2021 iteration has extended the design to try to support |
| 61 | +monitoring multiple queue managers from a single collector program. The API extensions may not be |
| 62 | +the most natural way of doing it, but I tried to do it while maintaining compatibility. Essentially, |
| 63 | +all of the global variables are now semi-hidden behind getter functions; the globals are still available |
| 64 | +for now, but access is deprecated. If there is a future major version change, those globals will disappear. |
| 65 | + |
| 66 | +The new design allows a collector to associate a connection with a key. There's still expected to be |
| 67 | +serialisation for now, so I doubt that you could process metrics from several qmgrs in parallel, in different |
| 68 | +threads. The fundamental new API in the package is `InitConnectionKey`. Once you've done that, then |
| 69 | +before calling other APIs in the package such as DiscoverAndSubscribe, you call `SetConnectionKey` to get the |
| 70 | +appropriate connection in place. Calling that function another time would let you switch to a |
| 71 | +different connection. |
| 72 | + |
| 73 | +I have thoughts on how the APIs can be extended or modified (breaking) to permit parallel collection, |
| 74 | +but this first phase gets the core data structures moved into better places. And it's not clear how valuable |
| 75 | +the extensions would be - how many people would be interested. |
0 commit comments