You've already forked mysqld_exporter
mirror of
https://github.com/prometheus/mysqld_exporter.git
synced 2025-07-28 19:21:58 +03:00
* determine column name for innodb_metrics before querying adds support more mariadb 10.4+, fixes 494 Signed-off-by: Mike <maemigh@gmail.com>
This commit is contained in:
@ -18,6 +18,8 @@ package collector
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
"regexp"
|
||||
|
||||
"github.com/go-kit/kit/log"
|
||||
@ -25,13 +27,20 @@ import (
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
const infoSchemaInnodbMetricsEnabledColumnQuery = `
|
||||
SELECT
|
||||
column_name
|
||||
FROM information_schema.columns
|
||||
WHERE table_name = 'INNODB_METRICS'
|
||||
AND column_name IN ('status', 'enabled')
|
||||
`
|
||||
|
||||
const infoSchemaInnodbMetricsQuery = `
|
||||
SELECT
|
||||
name, subsystem, type, comment,
|
||||
count
|
||||
FROM information_schema.innodb_metrics
|
||||
WHERE status = 'enabled'
|
||||
`
|
||||
WHERE ` + "`%s` = '%s'"
|
||||
|
||||
// Metrics descriptors.
|
||||
var (
|
||||
@ -83,7 +92,24 @@ func (ScrapeInnodbMetrics) Version() float64 {
|
||||
|
||||
// Scrape collects data from database connection and sends it over channel as prometheus metric.
|
||||
func (ScrapeInnodbMetrics) Scrape(ctx context.Context, db *sql.DB, ch chan<- prometheus.Metric, logger log.Logger) error {
|
||||
innodbMetricsRows, err := db.QueryContext(ctx, infoSchemaInnodbMetricsQuery)
|
||||
var enabledColumnName string
|
||||
var query string
|
||||
|
||||
err := db.QueryRowContext(ctx, infoSchemaInnodbMetricsEnabledColumnQuery).Scan(&enabledColumnName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
switch enabledColumnName {
|
||||
case "STATUS":
|
||||
query = fmt.Sprintf(infoSchemaInnodbMetricsQuery, "status", "enabled")
|
||||
case "ENABLED":
|
||||
query = fmt.Sprintf(infoSchemaInnodbMetricsQuery, "enabled", "1")
|
||||
default:
|
||||
return errors.New("Couldn't find column STATUS or ENABLED in innodb_metrics table.")
|
||||
}
|
||||
|
||||
innodbMetricsRows, err := db.QueryContext(ctx, query)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
Reference in New Issue
Block a user