@@ -44,11 +44,12 @@ import (
4444
4545// MonElement describes the real metric element generated by MQ
4646type MonElement struct {
47- Parent * MonType
48- Description string // An English phrase describing the element
49- MetricName string // Reformatted description suitable as label
50- Datatype int32
51- Values map [string ]int64
47+ Parent * MonType
48+ Description string // An English phrase describing the element
49+ DescriptionNLS string // A translated phrase for the current locale
50+ MetricName string // Reformatted description suitable as label
51+ Datatype int32
52+ Values map [string ]int64
5253}
5354
5455// MonType describes the "types" of data generated by MQ. Each class generates
@@ -89,11 +90,20 @@ const maxBufSize = 100 * 1024 * 1024 // 100 MB
8990var Metrics AllMetrics
9091
9192var qList []string
93+ var locale string
9294
9395func GetDiscoveredQueues () []string {
9496 return qList
9597}
9698
99+ /*
100+ * A collector can set the locale (eg "Fr_FR") before doing the discovery
101+ * process to get access to the MQ-translated strings
102+ */
103+ func SetLocale (l string ) {
104+ locale = l
105+ }
106+
97107/*
98108DiscoverAndSubscribe does all the work of finding the
99109different resources available from a queue manager and
@@ -284,6 +294,70 @@ func discoverElements(ty *MonType) error {
284294 return err
285295}
286296
297+ // Rerun the subscription for elements, but this time adding a locale into the topic
298+ // so that we can get the translated description. It's up to the collector program to
299+ // then make use of that description.
300+ func discoverElementsNLS (ty * MonType , locale string ) error {
301+ var err error
302+ var data []byte
303+ var sub ibmmq.MQObject
304+
305+ if locale == "" {
306+ return nil
307+ }
308+
309+ sub , err = subscribe (ty .elementTopic + "/" + locale )
310+ if err == nil {
311+ // Don't wait - if there's nothing on that topic, then get out fast
312+ data , err = getMessage (false )
313+ sub .Close (0 )
314+
315+ if err != nil {
316+ mqreturn := err .(* ibmmq.MQReturn )
317+ if mqreturn .MQRC == ibmmq .MQRC_NO_MSG_AVAILABLE {
318+ err = nil
319+ }
320+ }
321+
322+ elemList , _ := parsePCFResponse (data )
323+
324+ for i := 0 ; i < len (elemList ); i ++ {
325+
326+ if elemList [i ].Type == ibmmq .MQCFT_STRING && elemList [i ].Parameter == ibmmq .MQCA_TOPIC_STRING {
327+ continue
328+ }
329+
330+ if elemList [i ].Type != ibmmq .MQCFT_GROUP {
331+ continue
332+ }
333+
334+ group := elemList [i ]
335+ description := ""
336+ elementIndex := 0
337+
338+ for j := 0 ; j < len (group .GroupList ); j ++ {
339+ e := group .GroupList [j ]
340+ switch e .Parameter {
341+
342+ case ibmmq .MQIAMO_MONITOR_ELEMENT :
343+ elementIndex = int (e .Int64Value [0 ])
344+
345+ case ibmmq .MQCAMO_MONITOR_DESC :
346+ description = e .String [0 ]
347+
348+ }
349+ }
350+
351+ if description != "" {
352+ ty .Elements [elementIndex ].DescriptionNLS = description
353+ fmt .Printf ("Updated element %v\n " , ty .Elements [elementIndex ])
354+ }
355+ }
356+ }
357+
358+ return err
359+ }
360+
287361/*
288362Discover the complete set of available statistics in the queue manager
289363by working through the classes, types and individual elements.
@@ -312,6 +386,9 @@ func discoverStats(metaPrefix string) error {
312386 if err == nil {
313387 for _ , ty := range cl .Types {
314388 err = discoverElements (ty )
389+ if err == nil && locale != "" {
390+ err = discoverElementsNLS (ty , locale )
391+ }
315392 }
316393 }
317394 }
0 commit comments