From 1465a0b0e023f93c74b649afe70a5883131010ba Mon Sep 17 00:00:00 2001 From: Alexey Palazhchenko Date: Mon, 29 Oct 2018 18:35:38 +0300 Subject: [PATCH] Add minimal MySQL version to Scraper interface (#328) * Add Version method to Scraper interface. * Skip scrapers for unsupported MySQL versions. Signed-off-by: Alexey Palazhchenko --- collector/binlog.go | 8 +++++ collector/engine_innodb.go | 8 +++++ collector/engine_tokudb.go | 8 +++++ collector/exporter.go | 30 +++++++++++++++++-- collector/exporter_test.go | 15 ++++++++++ collector/global_status.go | 8 +++++ collector/global_variables.go | 8 +++++ collector/heartbeat.go | 8 +++++ collector/info_schema_auto_increment.go | 8 +++++ collector/info_schema_clientstats.go | 8 +++++ collector/info_schema_innodb_cmp.go | 14 ++++++--- collector/info_schema_innodb_cmpmem.go | 11 +++++-- collector/info_schema_innodb_metrics.go | 8 +++++ .../info_schema_innodb_sys_tablespaces.go | 8 +++++ collector/info_schema_processlist.go | 8 +++++ collector/info_schema_query_response_time.go | 8 +++++ collector/info_schema_tables.go | 8 +++++ collector/info_schema_tablestats.go | 8 +++++ collector/info_schema_userstats.go | 8 +++++ collector/perf_schema_events_statements.go | 8 +++++ collector/perf_schema_events_waits.go | 8 +++++ collector/perf_schema_file_events.go | 8 +++++ collector/perf_schema_file_instances.go | 8 +++++ collector/perf_schema_index_io_waits.go | 8 +++++ ...f_schema_replication_group_member_stats.go | 8 +++++ collector/perf_schema_table_io_waits.go | 8 +++++ collector/perf_schema_table_lock_waits.go | 8 +++++ collector/scraper.go | 5 ++++ collector/slave_hosts.go | 8 +++++ collector/slave_status.go | 8 +++++ 30 files changed, 267 insertions(+), 8 deletions(-) diff --git a/collector/binlog.go b/collector/binlog.go index 1f915c9..705b1c7 100644 --- a/collector/binlog.go +++ b/collector/binlog.go @@ -64,6 +64,11 @@ func (ScrapeBinlogSize) Help() string { return "Collect the current size of all registered binlog files" } +// Version of MySQL from which scraper is available. +func (ScrapeBinlogSize) Version() float64 { + return 5.1 +} + // Scrape collects data from database connection and sends it over channel as prometheus metric. func (ScrapeBinlogSize) Scrape(ctx context.Context, db *sql.DB, ch chan<- prometheus.Metric) error { var logBin uint8 @@ -113,3 +118,6 @@ func (ScrapeBinlogSize) Scrape(ctx context.Context, db *sql.DB, ch chan<- promet return nil } + +// check interface +var _ Scraper = ScrapeBinlogSize{} diff --git a/collector/engine_innodb.go b/collector/engine_innodb.go index cd783d4..8d75c9c 100644 --- a/collector/engine_innodb.go +++ b/collector/engine_innodb.go @@ -45,6 +45,11 @@ func (ScrapeEngineInnodbStatus) Help() string { return "Collect from SHOW ENGINE INNODB STATUS" } +// Version of MySQL from which scraper is available. +func (ScrapeEngineInnodbStatus) Version() float64 { + return 5.1 +} + // Scrape collects data from database connection and sends it over channel as prometheus metric. func (ScrapeEngineInnodbStatus) Scrape(ctx context.Context, db *sql.DB, ch chan<- prometheus.Metric) error { rows, err := db.QueryContext(ctx, engineInnodbStatusQuery) @@ -92,3 +97,6 @@ func (ScrapeEngineInnodbStatus) Scrape(ctx context.Context, db *sql.DB, ch chan< return nil } + +// check interface +var _ Scraper = ScrapeEngineInnodbStatus{} diff --git a/collector/engine_tokudb.go b/collector/engine_tokudb.go index d5fc919..1c9bd38 100644 --- a/collector/engine_tokudb.go +++ b/collector/engine_tokudb.go @@ -43,6 +43,11 @@ func (ScrapeEngineTokudbStatus) Help() string { return "Collect from SHOW ENGINE TOKUDB STATUS" } +// Version of MySQL from which scraper is available. +func (ScrapeEngineTokudbStatus) Version() float64 { + return 5.6 +} + // Scrape collects data from database connection and sends it over channel as prometheus metric. func (ScrapeEngineTokudbStatus) Scrape(ctx context.Context, db *sql.DB, ch chan<- prometheus.Metric) error { tokudbRows, err := db.QueryContext(ctx, engineTokudbStatusQuery) @@ -87,3 +92,6 @@ func sanitizeTokudbMetric(metricName string) string { } return metricName } + +// check interface +var _ Scraper = ScrapeEngineTokudbStatus{} diff --git a/collector/exporter.go b/collector/exporter.go index 690be8b..ddf0cee 100644 --- a/collector/exporter.go +++ b/collector/exporter.go @@ -17,6 +17,8 @@ import ( "context" "database/sql" "fmt" + "regexp" + "strconv" "strings" "sync" "time" @@ -33,14 +35,20 @@ const ( exporter = "exporter" ) -// SQL Queries. +// SQL queries and parameters. const ( + versionQuery = `SELECT @@version` + // System variable params formatting. // See: https://github.com/go-sql-driver/mysql#system-variables sessionSettingsParam = `log_slow_filter=%27tmp_table_on_disk,filesort_on_disk%27` timeoutParam = `lock_wait_timeout=%d` ) +var ( + versionRE = regexp.MustCompile(`^\d+\.\d+`) +) + // Tunable flags. var ( exporterLockTimeout = kingpin.Flag( @@ -145,9 +153,14 @@ func (e *Exporter) scrape(ctx context.Context, ch chan<- prometheus.Metric) { ch <- prometheus.MustNewConstMetric(scrapeDurationDesc, prometheus.GaugeValue, time.Since(scrapeTime).Seconds(), "connection") - wg := &sync.WaitGroup{} + version := getMySQLVersion(db) + var wg sync.WaitGroup defer wg.Wait() for _, scraper := range e.scrapers { + if version < scraper.Version() { + continue + } + wg.Add(1) go func(scraper Scraper) { defer wg.Done() @@ -163,6 +176,19 @@ func (e *Exporter) scrape(ctx context.Context, ch chan<- prometheus.Metric) { } } +func getMySQLVersion(db *sql.DB) float64 { + var versionStr string + var versionNum float64 + if err := db.QueryRow(versionQuery).Scan(&versionStr); err == nil { + versionNum, _ = strconv.ParseFloat(versionRE.FindString(versionStr), 64) + } + // If we can't match/parse the version, set it some big value that matches all versions. + if versionNum == 0 { + versionNum = 999 + } + return versionNum +} + // Metrics represents exporter metrics which values can be carried between http requests. type Metrics struct { TotalScrapes prometheus.Counter diff --git a/collector/exporter_test.go b/collector/exporter_test.go index 3e0ead7..3bf4413 100644 --- a/collector/exporter_test.go +++ b/collector/exporter_test.go @@ -15,6 +15,7 @@ package collector import ( "context" + "database/sql" "testing" "github.com/prometheus/client_golang/prometheus" @@ -63,3 +64,17 @@ func TestExporter(t *testing.T) { } }) } + +func TestGetMySQLVersion(t *testing.T) { + if testing.Short() { + t.Skip("-short is passed, skipping test") + } + + convey.Convey("Version parsing", t, func() { + db, err := sql.Open("mysql", dsn) + convey.So(err, convey.ShouldBeNil) + defer db.Close() + + convey.So(getMySQLVersion(db), convey.ShouldBeBetweenOrEqual, 5.5, 10.3) + }) +} diff --git a/collector/global_status.go b/collector/global_status.go index 6303ed4..6812206 100644 --- a/collector/global_status.go +++ b/collector/global_status.go @@ -87,6 +87,11 @@ func (ScrapeGlobalStatus) Help() string { return "Collect from SHOW GLOBAL STATUS" } +// Version of MySQL from which scraper is available. +func (ScrapeGlobalStatus) Version() float64 { + return 5.1 +} + // Scrape collects data from database connection and sends it over channel as prometheus metric. func (ScrapeGlobalStatus) Scrape(ctx context.Context, db *sql.DB, ch chan<- prometheus.Metric) error { globalStatusRows, err := db.QueryContext(ctx, globalStatusQuery) @@ -207,3 +212,6 @@ func (ScrapeGlobalStatus) Scrape(ctx context.Context, db *sql.DB, ch chan<- prom return nil } + +// check interface +var _ Scraper = ScrapeGlobalStatus{} diff --git a/collector/global_variables.go b/collector/global_variables.go index 64eb883..e9ad69b 100644 --- a/collector/global_variables.go +++ b/collector/global_variables.go @@ -131,6 +131,11 @@ func (ScrapeGlobalVariables) Help() string { return "Collect from SHOW GLOBAL VARIABLES" } +// Version of MySQL from which scraper is available. +func (ScrapeGlobalVariables) Version() float64 { + return 5.1 +} + // Scrape collects data from database connection and sends it over channel as prometheus metric. func (ScrapeGlobalVariables) Scrape(ctx context.Context, db *sql.DB, ch chan<- prometheus.Metric) error { globalVariablesRows, err := db.QueryContext(ctx, globalVariablesQuery) @@ -227,3 +232,6 @@ func validPrometheusName(s string) string { s = strings.ToLower(s) return s } + +// check interface +var _ Scraper = ScrapeGlobalVariables{} diff --git a/collector/heartbeat.go b/collector/heartbeat.go index 6fe6a7d..8ec8e93 100644 --- a/collector/heartbeat.go +++ b/collector/heartbeat.go @@ -79,6 +79,11 @@ func (ScrapeHeartbeat) Help() string { return "Collect from heartbeat" } +// Version of MySQL from which scraper is available. +func (ScrapeHeartbeat) Version() float64 { + return 5.1 +} + // Scrape collects data from database connection and sends it over channel as prometheus metric. func (ScrapeHeartbeat) Scrape(ctx context.Context, db *sql.DB, ch chan<- prometheus.Metric) error { query := fmt.Sprintf(heartbeatQuery, *collectHeartbeatDatabase, *collectHeartbeatTable) @@ -126,3 +131,6 @@ func (ScrapeHeartbeat) Scrape(ctx context.Context, db *sql.DB, ch chan<- prometh return nil } + +// check interface +var _ Scraper = ScrapeHeartbeat{} diff --git a/collector/info_schema_auto_increment.go b/collector/info_schema_auto_increment.go index 129a52d..aaac918 100644 --- a/collector/info_schema_auto_increment.go +++ b/collector/info_schema_auto_increment.go @@ -63,6 +63,11 @@ func (ScrapeAutoIncrementColumns) Help() string { return "Collect auto_increment columns and max values from information_schema" } +// Version of MySQL from which scraper is available. +func (ScrapeAutoIncrementColumns) Version() float64 { + return 5.1 +} + // Scrape collects data from database connection and sends it over channel as prometheus metric. func (ScrapeAutoIncrementColumns) Scrape(ctx context.Context, db *sql.DB, ch chan<- prometheus.Metric) error { autoIncrementRows, err := db.QueryContext(ctx, infoSchemaAutoIncrementQuery) @@ -93,3 +98,6 @@ func (ScrapeAutoIncrementColumns) Scrape(ctx context.Context, db *sql.DB, ch cha } return nil } + +// check interface +var _ Scraper = ScrapeAutoIncrementColumns{} diff --git a/collector/info_schema_clientstats.go b/collector/info_schema_clientstats.go index 968cc2e..792296c 100644 --- a/collector/info_schema_clientstats.go +++ b/collector/info_schema_clientstats.go @@ -154,6 +154,11 @@ func (ScrapeClientStat) Help() string { return "If running with userstat=1, set to true to collect client statistics" } +// Version of MySQL from which scraper is available. +func (ScrapeClientStat) Version() float64 { + return 5.5 +} + // Scrape collects data from database connection and sends it over channel as prometheus metric. func (ScrapeClientStat) Scrape(ctx context.Context, db *sql.DB, ch chan<- prometheus.Metric) error { var varName, varVal string @@ -213,3 +218,6 @@ func (ScrapeClientStat) Scrape(ctx context.Context, db *sql.DB, ch chan<- promet } return nil } + +// check interface +var _ Scraper = ScrapeClientStat{} diff --git a/collector/info_schema_innodb_cmp.go b/collector/info_schema_innodb_cmp.go index 03047fb..4f960b3 100644 --- a/collector/info_schema_innodb_cmp.go +++ b/collector/info_schema_innodb_cmp.go @@ -23,8 +23,8 @@ import ( ) const innodbCmpQuery = ` - SELECT - page_size, compress_ops, compress_ops_ok, compress_time, uncompress_ops, uncompress_time + SELECT + page_size, compress_ops, compress_ops_ok, compress_time, uncompress_ops, uncompress_time FROM information_schema.innodb_cmp ` @@ -70,6 +70,11 @@ func (ScrapeInnodbCmp) Help() string { return "Collect metrics from information_schema.innodb_cmp" } +// Version of MySQL from which scraper is available. +func (ScrapeInnodbCmp) Version() float64 { + return 5.5 +} + // Scrape collects data from database connection and sends it over channel as prometheus metric. func (ScrapeInnodbCmp) Scrape(ctx context.Context, db *sql.DB, ch chan<- prometheus.Metric) error { informationSchemaInnodbCmpRows, err := db.QueryContext(ctx, innodbCmpQuery) @@ -84,7 +89,6 @@ func (ScrapeInnodbCmp) Scrape(ctx context.Context, db *sql.DB, ch chan<- prometh ) for informationSchemaInnodbCmpRows.Next() { - if err := informationSchemaInnodbCmpRows.Scan( &page_size, &compress_ops, &compress_ops_ok, &compress_time, &uncompress_ops, &uncompress_time, ); err != nil { @@ -96,8 +100,10 @@ func (ScrapeInnodbCmp) Scrape(ctx context.Context, db *sql.DB, ch chan<- prometh ch <- prometheus.MustNewConstMetric(infoSchemaInnodbCmpCompressTime, prometheus.CounterValue, compress_time, page_size) ch <- prometheus.MustNewConstMetric(infoSchemaInnodbCmpUncompressOps, prometheus.CounterValue, uncompress_ops, page_size) ch <- prometheus.MustNewConstMetric(infoSchemaInnodbCmpUncompressTime, prometheus.CounterValue, uncompress_time, page_size) - } return nil } + +// check interface +var _ Scraper = ScrapeInnodbCmp{} diff --git a/collector/info_schema_innodb_cmpmem.go b/collector/info_schema_innodb_cmpmem.go index cfe56d7..72583b8 100644 --- a/collector/info_schema_innodb_cmpmem.go +++ b/collector/info_schema_innodb_cmpmem.go @@ -24,7 +24,7 @@ import ( const innodbCmpMemQuery = ` SELECT - page_size, buffer_pool_instance, pages_used, pages_free, relocation_ops, relocation_time + page_size, buffer_pool_instance, pages_used, pages_free, relocation_ops, relocation_time FROM information_schema.innodb_cmpmem ` @@ -65,6 +65,11 @@ func (ScrapeInnodbCmpMem) Help() string { return "Collect metrics from information_schema.innodb_cmpmem" } +// Version of MySQL from which scraper is available. +func (ScrapeInnodbCmpMem) Version() float64 { + return 5.5 +} + // Scrape collects data from database connection and sends it over channel as prometheus metric. func (ScrapeInnodbCmpMem) Scrape(ctx context.Context, db *sql.DB, ch chan<- prometheus.Metric) error { informationSchemaInnodbCmpMemRows, err := db.QueryContext(ctx, innodbCmpMemQuery) @@ -89,7 +94,9 @@ func (ScrapeInnodbCmpMem) Scrape(ctx context.Context, db *sql.DB, ch chan<- prom ch <- prometheus.MustNewConstMetric(infoSchemaInnodbCmpMemPagesFree, prometheus.CounterValue, pages_free, page_size, buffer_pool) ch <- prometheus.MustNewConstMetric(infoSchemaInnodbCmpMemRelocationOps, prometheus.CounterValue, relocation_ops, page_size, buffer_pool) ch <- prometheus.MustNewConstMetric(infoSchemaInnodbCmpMemRelocationTime, prometheus.CounterValue, (relocation_time / 1000), page_size, buffer_pool) - } return nil } + +// check interface +var _ Scraper = ScrapeInnodbCmpMem{} diff --git a/collector/info_schema_innodb_metrics.go b/collector/info_schema_innodb_metrics.go index ae510a7..e88471b 100644 --- a/collector/info_schema_innodb_metrics.go +++ b/collector/info_schema_innodb_metrics.go @@ -75,6 +75,11 @@ func (ScrapeInnodbMetrics) Help() string { return "Collect metrics from information_schema.innodb_metrics" } +// Version of MySQL from which scraper is available. +func (ScrapeInnodbMetrics) Version() float64 { + return 5.6 +} + // 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) error { innodbMetricsRows, err := db.QueryContext(ctx, infoSchemaInnodbMetricsQuery) @@ -164,3 +169,6 @@ func (ScrapeInnodbMetrics) Scrape(ctx context.Context, db *sql.DB, ch chan<- pro } return nil } + +// check interface +var _ Scraper = ScrapeInnodbMetrics{} diff --git a/collector/info_schema_innodb_sys_tablespaces.go b/collector/info_schema_innodb_sys_tablespaces.go index 4eaad60..5d0473d 100644 --- a/collector/info_schema_innodb_sys_tablespaces.go +++ b/collector/info_schema_innodb_sys_tablespaces.go @@ -66,6 +66,11 @@ func (ScrapeInfoSchemaInnodbTablespaces) Help() string { return "Collect metrics from information_schema.innodb_sys_tablespaces" } +// Version of MySQL from which scraper is available. +func (ScrapeInfoSchemaInnodbTablespaces) Version() float64 { + return 5.7 +} + // Scrape collects data from database connection and sends it over channel as prometheus metric. func (ScrapeInfoSchemaInnodbTablespaces) Scrape(ctx context.Context, db *sql.DB, ch chan<- prometheus.Metric) error { tablespacesRows, err := db.QueryContext(ctx, innodbTablespacesQuery) @@ -113,3 +118,6 @@ func (ScrapeInfoSchemaInnodbTablespaces) Scrape(ctx context.Context, db *sql.DB, return nil } + +// check interface +var _ Scraper = ScrapeInfoSchemaInnodbTablespaces{} diff --git a/collector/info_schema_processlist.go b/collector/info_schema_processlist.go index 448fdd8..180e3af 100644 --- a/collector/info_schema_processlist.go +++ b/collector/info_schema_processlist.go @@ -170,6 +170,11 @@ func (ScrapeProcesslist) Help() string { return "Collect current thread state counts from the information_schema.processlist" } +// Version of MySQL from which scraper is available. +func (ScrapeProcesslist) Version() float64 { + return 5.1 +} + // Scrape collects data from database connection and sends it over channel as prometheus metric. func (ScrapeProcesslist) Scrape(ctx context.Context, db *sql.DB, ch chan<- prometheus.Metric) error { processQuery := fmt.Sprintf( @@ -261,3 +266,6 @@ func deriveThreadState(command string, state string) string { } return "other" } + +// check interface +var _ Scraper = ScrapeProcesslist{} diff --git a/collector/info_schema_query_response_time.go b/collector/info_schema_query_response_time.go index f90da39..9f47a1d 100644 --- a/collector/info_schema_query_response_time.go +++ b/collector/info_schema_query_response_time.go @@ -112,6 +112,11 @@ func (ScrapeQueryResponseTime) Help() string { return "Collect query response time distribution if query_response_time_stats is ON." } +// Version of MySQL from which scraper is available. +func (ScrapeQueryResponseTime) Version() float64 { + return 5.5 +} + // Scrape collects data from database connection and sends it over channel as prometheus metric. func (ScrapeQueryResponseTime) Scrape(ctx context.Context, db *sql.DB, ch chan<- prometheus.Metric) error { var queryStats uint8 @@ -135,3 +140,6 @@ func (ScrapeQueryResponseTime) Scrape(ctx context.Context, db *sql.DB, ch chan<- } return nil } + +// check interface +var _ Scraper = ScrapeQueryResponseTime{} diff --git a/collector/info_schema_tables.go b/collector/info_schema_tables.go index 5597ad6..5ff7751 100644 --- a/collector/info_schema_tables.go +++ b/collector/info_schema_tables.go @@ -90,6 +90,11 @@ func (ScrapeTableSchema) Help() string { return "Collect metrics from information_schema.tables" } +// Version of MySQL from which scraper is available. +func (ScrapeTableSchema) Version() float64 { + return 5.1 +} + // Scrape collects data from database connection and sends it over channel as prometheus metric. func (ScrapeTableSchema) Scrape(ctx context.Context, db *sql.DB, ch chan<- prometheus.Metric) error { var dbList []string @@ -177,3 +182,6 @@ func (ScrapeTableSchema) Scrape(ctx context.Context, db *sql.DB, ch chan<- prome return nil } + +// check interface +var _ Scraper = ScrapeTableSchema{} diff --git a/collector/info_schema_tablestats.go b/collector/info_schema_tablestats.go index f0bf8b5..2d28004 100644 --- a/collector/info_schema_tablestats.go +++ b/collector/info_schema_tablestats.go @@ -65,6 +65,11 @@ func (ScrapeTableStat) Help() string { return "If running with userstat=1, set to true to collect table statistics" } +// Version of MySQL from which scraper is available. +func (ScrapeTableStat) Version() float64 { + return 5.1 +} + // Scrape collects data from database connection and sends it over channel as prometheus metric. func (ScrapeTableStat) Scrape(ctx context.Context, db *sql.DB, ch chan<- prometheus.Metric) error { var varName, varVal string @@ -118,3 +123,6 @@ func (ScrapeTableStat) Scrape(ctx context.Context, db *sql.DB, ch chan<- prometh } return nil } + +// check interface +var _ Scraper = ScrapeTableStat{} diff --git a/collector/info_schema_userstats.go b/collector/info_schema_userstats.go index 671cf15..bd336f7 100644 --- a/collector/info_schema_userstats.go +++ b/collector/info_schema_userstats.go @@ -150,6 +150,11 @@ func (ScrapeUserStat) Help() string { return "If running with userstat=1, set to true to collect user statistics" } +// Version of MySQL from which scraper is available. +func (ScrapeUserStat) Version() float64 { + return 5.1 +} + // Scrape collects data from database connection and sends it over channel as prometheus metric. func (ScrapeUserStat) Scrape(ctx context.Context, db *sql.DB, ch chan<- prometheus.Metric) error { var varName, varVal string @@ -208,3 +213,6 @@ func (ScrapeUserStat) Scrape(ctx context.Context, db *sql.DB, ch chan<- promethe } return nil } + +// check interface +var _ Scraper = ScrapeUserStat{} diff --git a/collector/perf_schema_events_statements.go b/collector/perf_schema_events_statements.go index 9b811ab..015a2c2 100644 --- a/collector/perf_schema_events_statements.go +++ b/collector/perf_schema_events_statements.go @@ -161,6 +161,11 @@ func (ScrapePerfEventsStatements) Help() string { return "Collect metrics from performance_schema.events_statements_summary_by_digest" } +// Version of MySQL from which scraper is available. +func (ScrapePerfEventsStatements) Version() float64 { + return 5.6 +} + // Scrape collects data from database connection and sends it over channel as prometheus metric. func (ScrapePerfEventsStatements) Scrape(ctx context.Context, db *sql.DB, ch chan<- prometheus.Metric) error { perfQuery := fmt.Sprintf( @@ -241,3 +246,6 @@ func (ScrapePerfEventsStatements) Scrape(ctx context.Context, db *sql.DB, ch cha } return nil } + +// check interface +var _ Scraper = ScrapePerfEventsStatements{} diff --git a/collector/perf_schema_events_waits.go b/collector/perf_schema_events_waits.go index 5a7e3a2..da5fbcb 100644 --- a/collector/perf_schema_events_waits.go +++ b/collector/perf_schema_events_waits.go @@ -54,6 +54,11 @@ func (ScrapePerfEventsWaits) Help() string { return "Collect metrics from performance_schema.events_waits_summary_global_by_event_name" } +// Version of MySQL from which scraper is available. +func (ScrapePerfEventsWaits) Version() float64 { + return 5.5 +} + // Scrape collects data from database connection and sends it over channel as prometheus metric. func (ScrapePerfEventsWaits) Scrape(ctx context.Context, db *sql.DB, ch chan<- prometheus.Metric) error { // Timers here are returned in picoseconds. @@ -85,3 +90,6 @@ func (ScrapePerfEventsWaits) Scrape(ctx context.Context, db *sql.DB, ch chan<- p } return nil } + +// check interface +var _ Scraper = ScrapePerfEventsWaits{} diff --git a/collector/perf_schema_file_events.go b/collector/perf_schema_file_events.go index 33ce3b8..edf4d56 100644 --- a/collector/perf_schema_file_events.go +++ b/collector/perf_schema_file_events.go @@ -63,6 +63,11 @@ func (ScrapePerfFileEvents) Help() string { return "Collect metrics from performance_schema.file_summary_by_event_name" } +// Version of MySQL from which scraper is available. +func (ScrapePerfFileEvents) Version() float64 { + return 5.6 +} + // Scrape collects data from database connection and sends it over channel as prometheus metric. func (ScrapePerfFileEvents) Scrape(ctx context.Context, db *sql.DB, ch chan<- prometheus.Metric) error { // Timers here are returned in picoseconds. @@ -122,3 +127,6 @@ func (ScrapePerfFileEvents) Scrape(ctx context.Context, db *sql.DB, ch chan<- pr } return nil } + +// check interface +var _ Scraper = ScrapePerfFileEvents{} diff --git a/collector/perf_schema_file_instances.go b/collector/perf_schema_file_instances.go index 5b4c295..9e6810e 100644 --- a/collector/perf_schema_file_instances.go +++ b/collector/perf_schema_file_instances.go @@ -73,6 +73,11 @@ func (ScrapePerfFileInstances) Help() string { return "Collect metrics from performance_schema.file_summary_by_instance" } +// Version of MySQL from which scraper is available. +func (ScrapePerfFileInstances) Version() float64 { + return 5.5 +} + // Scrape collects data from database connection and sends it over channel as prometheus metric. func (ScrapePerfFileInstances) Scrape(ctx context.Context, db *sql.DB, ch chan<- prometheus.Metric) error { // Timers here are returned in picoseconds. @@ -118,3 +123,6 @@ func (ScrapePerfFileInstances) Scrape(ctx context.Context, db *sql.DB, ch chan<- } return nil } + +// check interface +var _ Scraper = ScrapePerfFileInstances{} diff --git a/collector/perf_schema_index_io_waits.go b/collector/perf_schema_index_io_waits.go index 2fb1dbd..badc7a8 100644 --- a/collector/perf_schema_index_io_waits.go +++ b/collector/perf_schema_index_io_waits.go @@ -57,6 +57,11 @@ func (ScrapePerfIndexIOWaits) Help() string { return "Collect metrics from performance_schema.table_io_waits_summary_by_index_usage" } +// Version of MySQL from which scraper is available. +func (ScrapePerfIndexIOWaits) Version() float64 { + return 5.6 +} + // Scrape collects data from database connection and sends it over channel as prometheus metric. func (ScrapePerfIndexIOWaits) Scrape(ctx context.Context, db *sql.DB, ch chan<- prometheus.Metric) error { perfSchemaIndexWaitsRows, err := db.QueryContext(ctx, perfIndexIOWaitsQuery) @@ -120,3 +125,6 @@ func (ScrapePerfIndexIOWaits) Scrape(ctx context.Context, db *sql.DB, ch chan<- } return nil } + +// check interface +var _ Scraper = ScrapePerfIndexIOWaits{} diff --git a/collector/perf_schema_replication_group_member_stats.go b/collector/perf_schema_replication_group_member_stats.go index 123fe5a..3e7cf92 100644 --- a/collector/perf_schema_replication_group_member_stats.go +++ b/collector/perf_schema_replication_group_member_stats.go @@ -63,6 +63,11 @@ func (ScrapePerfReplicationGroupMemberStats) Help() string { return "Collect metrics from performance_schema.replication_group_member_stats" } +// Version of MySQL from which scraper is available. +func (ScrapePerfReplicationGroupMemberStats) Version() float64 { + return 5.7 +} + // Scrape collects data from database connection and sends it over channel as prometheus metric. func (ScrapePerfReplicationGroupMemberStats) Scrape(ctx context.Context, db *sql.DB, ch chan<- prometheus.Metric) error { perfReplicationGroupMemeberStatsRows, err := db.QueryContext(ctx, perfReplicationGroupMemeberStatsQuery) @@ -103,3 +108,6 @@ func (ScrapePerfReplicationGroupMemberStats) Scrape(ctx context.Context, db *sql } return nil } + +// check interface +var _ Scraper = ScrapePerfReplicationGroupMemberStats{} diff --git a/collector/perf_schema_table_io_waits.go b/collector/perf_schema_table_io_waits.go index 347c2a5..0617b60 100644 --- a/collector/perf_schema_table_io_waits.go +++ b/collector/perf_schema_table_io_waits.go @@ -58,6 +58,11 @@ func (ScrapePerfTableIOWaits) Help() string { return "Collect metrics from performance_schema.table_io_waits_summary_by_table" } +// Version of MySQL from which scraper is available. +func (ScrapePerfTableIOWaits) Version() float64 { + return 5.6 +} + // Scrape collects data from database connection and sends it over channel as prometheus metric. func (ScrapePerfTableIOWaits) Scrape(ctx context.Context, db *sql.DB, ch chan<- prometheus.Metric) error { perfSchemaTableWaitsRows, err := db.QueryContext(ctx, perfTableIOWaitsQuery) @@ -114,3 +119,6 @@ func (ScrapePerfTableIOWaits) Scrape(ctx context.Context, db *sql.DB, ch chan<- } return nil } + +// check interface +var _ Scraper = ScrapePerfTableIOWaits{} diff --git a/collector/perf_schema_table_lock_waits.go b/collector/perf_schema_table_lock_waits.go index 406d988..9f6ecad 100644 --- a/collector/perf_schema_table_lock_waits.go +++ b/collector/perf_schema_table_lock_waits.go @@ -87,6 +87,11 @@ func (ScrapePerfTableLockWaits) Help() string { return "Collect metrics from performance_schema.table_lock_waits_summary_by_table" } +// Version of MySQL from which scraper is available. +func (ScrapePerfTableLockWaits) Version() float64 { + return 5.6 +} + // Scrape collects data from database connection and sends it over channel as prometheus metric. func (ScrapePerfTableLockWaits) Scrape(ctx context.Context, db *sql.DB, ch chan<- prometheus.Metric) error { perfSchemaTableLockWaitsRows, err := db.QueryContext(ctx, perfTableLockWaitsQuery) @@ -230,3 +235,6 @@ func (ScrapePerfTableLockWaits) Scrape(ctx context.Context, db *sql.DB, ch chan< } return nil } + +// check interface +var _ Scraper = ScrapePerfTableLockWaits{} diff --git a/collector/scraper.go b/collector/scraper.go index a7d29cc..64ef094 100644 --- a/collector/scraper.go +++ b/collector/scraper.go @@ -25,9 +25,14 @@ import ( type Scraper interface { // Name of the Scraper. Should be unique. Name() string + // Help describes the role of the Scraper. // Example: "Collect from SHOW ENGINE INNODB STATUS" Help() string + + // Version of MySQL from which scraper is available. + Version() float64 + // Scrape collects data from database connection and sends it over channel as prometheus metric. Scrape(ctx context.Context, db *sql.DB, ch chan<- prometheus.Metric) error } diff --git a/collector/slave_hosts.go b/collector/slave_hosts.go index 13d6062..0ad1155 100644 --- a/collector/slave_hosts.go +++ b/collector/slave_hosts.go @@ -55,6 +55,11 @@ func (ScrapeSlaveHosts) Help() string { return "Scrape information from 'SHOW SLAVE HOSTS'" } +// Version of MySQL from which scraper is available. +func (ScrapeSlaveHosts) Version() float64 { + return 5.1 +} + // Scrape collects data from database connection and sends it over channel as prometheus metric. func (ScrapeSlaveHosts) Scrape(ctx context.Context, db *sql.DB, ch chan<- prometheus.Metric) error { slaveHostsRows, err := db.QueryContext(ctx, slaveHostsQuery) @@ -110,3 +115,6 @@ func (ScrapeSlaveHosts) Scrape(ctx context.Context, db *sql.DB, ch chan<- promet return nil } + +// check interface +var _ Scraper = ScrapeSlaveHosts{} diff --git a/collector/slave_status.go b/collector/slave_status.go index 8ce74e7..9b83e2b 100644 --- a/collector/slave_status.go +++ b/collector/slave_status.go @@ -62,6 +62,11 @@ func (ScrapeSlaveStatus) Help() string { return "Collect from SHOW SLAVE STATUS" } +// Version of MySQL from which scraper is available. +func (ScrapeSlaveStatus) Version() float64 { + return 5.1 +} + // Scrape collects data from database connection and sends it over channel as prometheus metric. func (ScrapeSlaveStatus) Scrape(ctx context.Context, db *sql.DB, ch chan<- prometheus.Metric) error { var ( @@ -129,3 +134,6 @@ func (ScrapeSlaveStatus) Scrape(ctx context.Context, db *sql.DB, ch chan<- prome } return nil } + +// check interface +var _ Scraper = ScrapeSlaveStatus{}