Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions collector/engine_innodb.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ const (
engineInnodbStatusQuery = `SHOW ENGINE INNODB STATUS`
)

var (
// 0 queries inside InnoDB, 0 queries in queue
// 0 read views open inside InnoDB
queriesRe = regexp.MustCompile(`(\d+) queries inside InnoDB, (\d+) queries in queue`)
viewsRe = regexp.MustCompile(`(\d+) read views open inside InnoDB`)
)

// ScrapeEngineInnodbStatus scrapes from `SHOW ENGINE INNODB STATUS`.
type ScrapeEngineInnodbStatus struct{}

Expand Down Expand Up @@ -67,13 +74,8 @@ func (ScrapeEngineInnodbStatus) Scrape(ctx context.Context, instance *instance,
}
}

// 0 queries inside InnoDB, 0 queries in queue
// 0 read views open inside InnoDB
rQueries, _ := regexp.Compile(`(\d+) queries inside InnoDB, (\d+) queries in queue`)
rViews, _ := regexp.Compile(`(\d+) read views open inside InnoDB`)

for _, line := range strings.Split(statusCol, "\n") {
if data := rQueries.FindStringSubmatch(line); data != nil {
if data := queriesRe.FindStringSubmatch(line); data != nil {
value, _ := strconv.ParseFloat(data[1], 64)
ch <- prometheus.MustNewConstMetric(
newDesc(innodb, "queries_inside_innodb", "Queries inside InnoDB."),
Expand All @@ -86,7 +88,7 @@ func (ScrapeEngineInnodbStatus) Scrape(ctx context.Context, instance *instance,
prometheus.GaugeValue,
value,
)
} else if data := rViews.FindStringSubmatch(line); data != nil {
} else if data := viewsRe.FindStringSubmatch(line); data != nil {
value, _ := strconv.ParseFloat(data[1], 64)
ch <- prometheus.MustNewConstMetric(
newDesc(innodb, "read_views_open_inside_innodb", "Read views open inside InnoDB."),
Expand Down
13 changes: 7 additions & 6 deletions collector/global_variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ const (
)

var (
promNameRe = regexp.MustCompile("([^a-zA-Z0-9_])")
wsrespGcacheSizeRe = regexp.MustCompile(`gcache.size = (\d+)([MG]?);`)

// Map known global variables to help strings. Unknown will be mapped to generic gauges.
globalVariablesHelp = map[string]string{
// https://github.com/facebook/mysql-5.6/wiki/New-MySQL-RocksDB-Server-Variables
Expand Down Expand Up @@ -148,7 +151,7 @@ func (ScrapeGlobalVariables) Scrape(ctx context.Context, instance *instance, ch

var key string
var val sql.RawBytes
var textItems = map[string]string{
textItems := map[string]string{
"innodb_version": "",
"version": "",
"version_comment": "",
Expand Down Expand Up @@ -226,13 +229,12 @@ func (ScrapeGlobalVariables) Scrape(ctx context.Context, instance *instance, ch

// parseWsrepProviderOptions parse wsrep_provider_options to get gcache.size in bytes.
func parseWsrepProviderOptions(opts string) float64 {
var val float64
r, _ := regexp.Compile(`gcache.size = (\d+)([MG]?);`)
data := r.FindStringSubmatch(opts)
data := wsrespGcacheSizeRe.FindStringSubmatch(opts)
if data == nil {
return 0
}

var val float64
val, _ = strconv.ParseFloat(data[1], 64)
switch data[2] {
case "M":
Expand All @@ -245,8 +247,7 @@ func parseWsrepProviderOptions(opts string) float64 {
}

func validPrometheusName(s string) string {
nameRe := regexp.MustCompile("([^a-zA-Z0-9_])")
s = nameRe.ReplaceAllString(s, "_")
s = promNameRe.ReplaceAllString(s, "_")
s = strings.ToLower(s)
return s
}
Expand Down