You've already forked mysqld_exporter
mirror of
https://github.com/prometheus/mysqld_exporter.git
synced 2025-07-30 06:43:05 +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:
@ -15,6 +15,7 @@
|
|||||||
* [FEATURE] Add collector for `performance_schema.memory_summary_global_by_event_name` (PR #515) #75
|
* [FEATURE] Add collector for `performance_schema.memory_summary_global_by_event_name` (PR #515) #75
|
||||||
* [BUGFIX] Fixed output value of wsrep_cluster_status #473
|
* [BUGFIX] Fixed output value of wsrep_cluster_status #473
|
||||||
* [BUGFIX] Fix collect.info_schema.innodb_tablespaces for new table names #516
|
* [BUGFIX] Fix collect.info_schema.innodb_tablespaces for new table names #516
|
||||||
|
* [BUGFIX] Fix collect.info_schema.innodb_metrics for new field names (mariadb 10.5+) #494
|
||||||
|
|
||||||
### BREAKING CHANGES:
|
### BREAKING CHANGES:
|
||||||
|
|
||||||
|
@ -18,6 +18,8 @@ package collector
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
|
||||||
"github.com/go-kit/kit/log"
|
"github.com/go-kit/kit/log"
|
||||||
@ -25,13 +27,20 @@ import (
|
|||||||
"github.com/prometheus/client_golang/prometheus"
|
"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 = `
|
const infoSchemaInnodbMetricsQuery = `
|
||||||
SELECT
|
SELECT
|
||||||
name, subsystem, type, comment,
|
name, subsystem, type, comment,
|
||||||
count
|
count
|
||||||
FROM information_schema.innodb_metrics
|
FROM information_schema.innodb_metrics
|
||||||
WHERE status = 'enabled'
|
WHERE ` + "`%s` = '%s'"
|
||||||
`
|
|
||||||
|
|
||||||
// Metrics descriptors.
|
// Metrics descriptors.
|
||||||
var (
|
var (
|
||||||
@ -83,7 +92,24 @@ func (ScrapeInnodbMetrics) Version() float64 {
|
|||||||
|
|
||||||
// Scrape collects data from database connection and sends it over channel as prometheus metric.
|
// 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 {
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@ package collector
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/DATA-DOG/go-sqlmock"
|
"github.com/DATA-DOG/go-sqlmock"
|
||||||
@ -31,8 +32,13 @@ func TestScrapeInnodbMetrics(t *testing.T) {
|
|||||||
}
|
}
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
|
enabledColumnName := []string{"COLUMN_NAME"}
|
||||||
|
rows := sqlmock.NewRows(enabledColumnName).
|
||||||
|
AddRow("STATUS")
|
||||||
|
mock.ExpectQuery(sanitizeQuery(infoSchemaInnodbMetricsEnabledColumnQuery)).WillReturnRows(rows)
|
||||||
|
|
||||||
columns := []string{"name", "subsystem", "type", "comment", "count"}
|
columns := []string{"name", "subsystem", "type", "comment", "count"}
|
||||||
rows := sqlmock.NewRows(columns).
|
rows = sqlmock.NewRows(columns).
|
||||||
AddRow("lock_timeouts", "lock", "counter", "Number of lock timeouts", 0).
|
AddRow("lock_timeouts", "lock", "counter", "Number of lock timeouts", 0).
|
||||||
AddRow("buffer_pool_reads", "buffer", "status_counter", "Number of reads directly from disk (innodb_buffer_pool_reads)", 1).
|
AddRow("buffer_pool_reads", "buffer", "status_counter", "Number of reads directly from disk (innodb_buffer_pool_reads)", 1).
|
||||||
AddRow("buffer_pool_size", "server", "value", "Server buffer pool size (all buffer pools) in bytes", 2).
|
AddRow("buffer_pool_size", "server", "value", "Server buffer pool size (all buffer pools) in bytes", 2).
|
||||||
@ -42,7 +48,8 @@ func TestScrapeInnodbMetrics(t *testing.T) {
|
|||||||
AddRow("buffer_pool_pages_data", "buffer", "gauge", "Number of data buffer pool pages", 6).
|
AddRow("buffer_pool_pages_data", "buffer", "gauge", "Number of data buffer pool pages", 6).
|
||||||
AddRow("buffer_pool_pages_total", "buffer", "gauge", "Number of total buffer pool pages", 7).
|
AddRow("buffer_pool_pages_total", "buffer", "gauge", "Number of total buffer pool pages", 7).
|
||||||
AddRow("NOPE", "buffer_page_io", "counter", "An invalid buffer_page_io metric", 999)
|
AddRow("NOPE", "buffer_page_io", "counter", "An invalid buffer_page_io metric", 999)
|
||||||
mock.ExpectQuery(sanitizeQuery(infoSchemaInnodbMetricsQuery)).WillReturnRows(rows)
|
query := fmt.Sprintf(infoSchemaInnodbMetricsQuery, "status", "enabled")
|
||||||
|
mock.ExpectQuery(sanitizeQuery(query)).WillReturnRows(rows)
|
||||||
|
|
||||||
ch := make(chan prometheus.Metric)
|
ch := make(chan prometheus.Metric)
|
||||||
go func() {
|
go func() {
|
||||||
|
Reference in New Issue
Block a user