@@ -34,6 +34,9 @@ const (
34
34
)
35
35
36
36
var (
37
+ promNameRe = regexp .MustCompile ("([^a-zA-Z0-9_])" )
38
+ wsrespGcacheSizeRe = regexp .MustCompile (`gcache.size = (\d+)([MG]?);` )
39
+
37
40
// Map known global variables to help strings. Unknown will be mapped to generic gauges.
38
41
globalVariablesHelp = map [string ]string {
39
42
// https://github.com/facebook/mysql-5.6/wiki/New-MySQL-RocksDB-Server-Variables
@@ -148,7 +151,7 @@ func (ScrapeGlobalVariables) Scrape(ctx context.Context, instance *instance, ch
148
151
149
152
var key string
150
153
var val sql.RawBytes
151
- var textItems = map [string ]string {
154
+ textItems : = map [string ]string {
152
155
"innodb_version" : "" ,
153
156
"version" : "" ,
154
157
"version_comment" : "" ,
@@ -226,13 +229,12 @@ func (ScrapeGlobalVariables) Scrape(ctx context.Context, instance *instance, ch
226
229
227
230
// parseWsrepProviderOptions parse wsrep_provider_options to get gcache.size in bytes.
228
231
func parseWsrepProviderOptions (opts string ) float64 {
229
- var val float64
230
- r , _ := regexp .Compile (`gcache.size = (\d+)([MG]?);` )
231
- data := r .FindStringSubmatch (opts )
232
+ data := wsrespGcacheSizeRe .FindStringSubmatch (opts )
232
233
if data == nil {
233
234
return 0
234
235
}
235
236
237
+ var val float64
236
238
val , _ = strconv .ParseFloat (data [1 ], 64 )
237
239
switch data [2 ] {
238
240
case "M" :
@@ -245,8 +247,7 @@ func parseWsrepProviderOptions(opts string) float64 {
245
247
}
246
248
247
249
func validPrometheusName (s string ) string {
248
- nameRe := regexp .MustCompile ("([^a-zA-Z0-9_])" )
249
- s = nameRe .ReplaceAllString (s , "_" )
250
+ s = promNameRe .ReplaceAllString (s , "_" )
250
251
s = strings .ToLower (s )
251
252
return s
252
253
}
0 commit comments