@@ -35,6 +35,7 @@ import (
35
35
"bufio"
36
36
"fmt"
37
37
"os"
38
+ "regexp"
38
39
"strings"
39
40
40
41
"github.com/ibm-messaging/mq-golang/ibmmq"
@@ -263,7 +264,7 @@ func discoverElements(ty *MonType) error {
263
264
}
264
265
}
265
266
266
- elem .MetricName = formatDescriptionElem (elem )
267
+ elem .MetricName = formatDescription (elem )
267
268
ty .Elements [elementIndex ] = elem
268
269
}
269
270
}
@@ -631,59 +632,49 @@ bytes etc), and organisation of the elements of the name (units last)
631
632
While we can't change the MQ-generated descriptions for its statistics,
632
633
we can reformat most of them heuristically here.
633
634
*/
634
- func formatDescriptionElem (elem * MonElement ) string {
635
- s := formatDescription (elem .Description )
636
-
637
- unit := ""
638
- switch elem .Datatype {
639
- case ibmmq .MQIAMO_MONITOR_MICROSEC :
640
- // Although the qmgr captures in us, we convert when
641
- // pushing out to the backend, so this label needs to match
642
- unit = "_seconds"
643
- }
644
- s += unit
645
-
646
- return s
647
- }
648
-
649
- func formatDescription (baseName string ) string {
650
- s := baseName
635
+ func formatDescription (elem * MonElement ) string {
636
+ s := elem .Description
651
637
s = strings .Replace (s , " " , "_" , - 1 )
652
638
s = strings .Replace (s , "/" , "_" , - 1 )
653
639
s = strings .Replace (s , "-" , "_" , - 1 )
654
640
655
- /* common pattern is "xxx - yyy" leading to 3 ugly adjacent underscores */
656
- s = strings . Replace ( s , "___" , "_" , - 1 )
657
- s = strings . Replace (s , "__" , "_" , - 1 )
641
+ /* Make sure we don't have multiple underscores */
642
+ multiunder := regexp . MustCompile ( "__*" )
643
+ s = multiunder . ReplaceAllLiteralString (s , "_" )
658
644
659
645
/* make it all lowercase. Not essential, but looks better */
660
646
s = strings .ToLower (s )
661
647
662
- // Do not use _count
648
+ /* Remove all cases of bytes, seconds, count or percentage (we add them back in later) */
663
649
s = strings .Replace (s , "_count" , "" , - 1 )
650
+ s = strings .Replace (s , "_bytes" , "" , - 1 )
651
+ s = strings .Replace (s , "_byte" , "" , - 1 )
652
+ s = strings .Replace (s , "_seconds" , "" , - 1 )
653
+ s = strings .Replace (s , "_second" , "" , - 1 )
654
+ s = strings .Replace (s , "_percentage" , "" , - 1 )
664
655
665
656
// Switch round a couple of specific names
666
- s = strings .Replace (s , "bytes_written" , "written_bytes" , - 1 )
667
- s = strings .Replace (s , "bytes_max" , "max_bytes" , - 1 )
668
- s = strings .Replace (s , "bytes_in_use" , "in_use_bytes" , - 1 )
669
657
s = strings .Replace (s , "messages_expired" , "expired_messages" , - 1 )
670
658
671
- if strings .HasSuffix (s , "free_space" ) {
659
+ // Add the unit at end
660
+ switch elem .Datatype {
661
+ case ibmmq .MQIAMO_MONITOR_PERCENT , ibmmq .MQIAMO_MONITOR_HUNDREDTHS :
672
662
s = s + "_percentage"
673
- s = strings .Replace (s , "__" , "_" , - 1 )
674
- }
675
-
676
- // Make "byte", "file" and "message" units plural
677
- if strings .HasSuffix (s , "byte" ) ||
678
- strings .HasSuffix (s , "message" ) ||
679
- strings .HasSuffix (s , "file" ) {
680
- s = s + "s"
681
- }
682
-
683
- // Move % to the end
684
- if strings .Contains (s , "_percentage_" ) {
685
- s = strings .Replace (s , "_percentage_" , "_" , - 1 )
686
- s += "_percentage"
663
+ case ibmmq .MQIAMO_MONITOR_MB , ibmmq .MQIAMO_MONITOR_GB :
664
+ s = s + "_bytes"
665
+ case ibmmq .MQIAMO_MONITOR_MICROSEC :
666
+ s = s + "_seconds"
667
+ default :
668
+ if strings .Contains (s , "_total" ) {
669
+ /* If we specify it is a total in description put that at the end */
670
+ s = strings .Replace (s , "_total" , "" , - 1 )
671
+ s = s + "_total"
672
+ } else if strings .Contains (s , "log_" ) {
673
+ /* Weird case where the log datatype is not MB or GB but should be bytes */
674
+ s = s + "_bytes"
675
+ } else {
676
+ s = s + "_count"
677
+ }
687
678
}
688
679
689
680
return s
0 commit comments