1
0
mirror of https://github.com/prometheus/mysqld_exporter.git synced 2025-07-30 06:43:05 +03:00

PMM-2576: Fix prometheus metric names for SHOW GLOBAL VARIABLES. (#307)

* Use regexp to replace invalid characters.

Signed-off-by: Kamil Dziedzic <arvenil@klecza.pl>
This commit is contained in:
Kamil Dziedzic
2018-08-30 16:49:24 +02:00
committed by Ben Kochie
parent bf41e39d5f
commit c8e3120d1f

View File

@ -53,7 +53,7 @@ func (ScrapeGlobalVariables) Scrape(db *sql.DB, ch chan<- prometheus.Metric) err
if err := globalVariablesRows.Scan(&key, &val); err != nil {
return err
}
key = strings.ToLower(key)
key = validPrometheusName(key)
if floatVal, ok := parseStatus(val); ok {
ch <- prometheus.MustNewConstMetric(
newDesc(globalVariables, key, "Generic gauge metric from SHOW GLOBAL VARIABLES."),
@ -113,3 +113,10 @@ func parseWsrepProviderOptions(opts string) float64 {
return val
}
func validPrometheusName(s string) string {
nameRe := regexp.MustCompile("([^a-zA-Z0-9_])")
s = nameRe.ReplaceAllString(s, "_")
s = strings.ToLower(s)
return s
}