@@ -16,11 +16,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
16
16
package main
17
17
18
18
import (
19
+ "io/ioutil"
19
20
"log"
21
+ "os/exec"
22
+ "regexp"
20
23
"strings"
21
24
"strconv"
22
- "io/ioutil"
23
- "os/exec"
24
25
"github.com/prometheus/client_golang/prometheus"
25
26
)
26
27
@@ -53,28 +54,51 @@ func SchedulerData() []byte {
53
54
return out
54
55
}
55
56
56
- // Helper function to split a single line from the sdiag output
57
- func SplitColonValueToFloat (input string ) float64 {
58
- // Verify if the string extracted from the sdiag output is empty
59
- if input == "" { return 0 }
60
- str := strings .Split (input ,":" )
61
- rvalue := strings .TrimSpace (str [1 ])
62
- flt , _ := strconv .ParseFloat (rvalue ,64 )
63
- return flt
64
- }
65
-
66
57
// Extract the relevant metrics from the sdiag output
67
58
func ParseSchedulerMetrics (input []byte ) * SchedulerMetrics {
68
- lines := strings .Split (string (input ),"\n " )
69
59
var sm SchedulerMetrics
70
- sm .threads = SplitColonValueToFloat (lines [4 ])
71
- sm .queue_size = SplitColonValueToFloat (lines [5 ])
72
- sm .last_cycle = SplitColonValueToFloat (lines [14 ])
73
- sm .mean_cycle = SplitColonValueToFloat (lines [17 ])
74
- sm .cycle_per_minute = SplitColonValueToFloat (lines [19 ])
75
- sm .backfill_last_cycle = SplitColonValueToFloat (lines [27 ])
76
- sm .backfill_mean_cycle = SplitColonValueToFloat (lines [29 ])
77
- sm .backfill_depth_mean = SplitColonValueToFloat (lines [32 ])
60
+ lines := strings .Split (string (input ),"\n " )
61
+ // Guard variables to check for string repetitions in the output of sdiag
62
+ // (two 'Last cycle', two 'Mean cycle')
63
+ lc_count := 0
64
+ mc_count := 0
65
+ for _ , line := range lines {
66
+ if strings .Contains (line , ":" ) {
67
+ state := strings .Split (line , ":" )[0 ]
68
+ st := regexp .MustCompile (`^Server thread` )
69
+ qs := regexp .MustCompile (`^Agent queue` )
70
+ lc := regexp .MustCompile (`^[\s]+Last cycle$` )
71
+ mc := regexp .MustCompile (`^[\s]+Mean cycle$` )
72
+ cpm := regexp .MustCompile (`^[\s]+Cycles per` )
73
+ dpm := regexp .MustCompile (`^[\s]+Depth Mean$` )
74
+ switch {
75
+ case st .MatchString (state ) == true :
76
+ sm .threads , _ = strconv .ParseFloat (strings .TrimSpace (strings .Split (line , ":" )[1 ]), 64 )
77
+ case qs .MatchString (state ) == true :
78
+ sm .queue_size , _ = strconv .ParseFloat (strings .TrimSpace (strings .Split (line , ":" )[1 ]), 64 )
79
+ case lc .MatchString (state ) == true :
80
+ if lc_count == 0 {
81
+ sm .last_cycle , _ = strconv .ParseFloat (strings .TrimSpace (strings .Split (line , ":" )[1 ]), 64 )
82
+ lc_count = 1
83
+ }
84
+ if lc_count == 1 {
85
+ sm .backfill_last_cycle , _ = strconv .ParseFloat (strings .TrimSpace (strings .Split (line , ":" )[1 ]), 64 )
86
+ }
87
+ case mc .MatchString (state ) == true :
88
+ if mc_count == 0 {
89
+ sm .mean_cycle , _ = strconv .ParseFloat (strings .TrimSpace (strings .Split (line , ":" )[1 ]), 64 )
90
+ mc_count = 1
91
+ }
92
+ if mc_count == 1 {
93
+ sm .backfill_mean_cycle , _ = strconv .ParseFloat (strings .TrimSpace (strings .Split (line , ":" )[1 ]), 64 )
94
+ }
95
+ case cpm .MatchString (state ) == true :
96
+ sm .cycle_per_minute , _ = strconv .ParseFloat (strings .TrimSpace (strings .Split (line , ":" )[1 ]), 64 )
97
+ case dpm .MatchString (state ) == true :
98
+ sm .backfill_depth_mean , _ = strconv .ParseFloat (strings .TrimSpace (strings .Split (line , ":" )[1 ]), 64 )
99
+ }
100
+ }
101
+ }
78
102
return & sm
79
103
}
80
104
0 commit comments