You've already forked mysqld_exporter
mirror of
https://github.com/prometheus/mysqld_exporter.git
synced 2025-08-06 14:22:37 +03:00
fix collect.info_schema.innodb_tablespaces for mariadb 10.3+ and mysql 8.0+
Signed-off-by: Mike <maemigh@Mikes-MacBook-Pro.local>
This commit is contained in:
@@ -18,22 +18,34 @@ package collector
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/go-kit/kit/log"
|
"github.com/go-kit/kit/log"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const innodbTablespacesTablenameQuery = `
|
||||||
|
SELECT
|
||||||
|
table_name
|
||||||
|
FROM information_schema.tables
|
||||||
|
WHERE table_name = 'INNODB_SYS_TABLESPACES'
|
||||||
|
OR table_name = 'INNODB_TABLESPACES'
|
||||||
|
`
|
||||||
const innodbTablespacesQuery = `
|
const innodbTablespacesQuery = `
|
||||||
SELECT
|
SELECT
|
||||||
SPACE,
|
SPACE,
|
||||||
NAME,
|
NAME,
|
||||||
ifnull(FILE_FORMAT, 'NONE') as FILE_FORMAT,
|
ifnull((SELECT column_name
|
||||||
|
FROM information_schema.COLUMNS
|
||||||
|
WHERE TABLE_SCHEMA = 'information_schema'
|
||||||
|
AND TABLE_NAME = ` + "'%s'" + `
|
||||||
|
AND COLUMN_NAME = 'FILE_FORMAT' LIMIT 1), 'NONE') as FILE_FORMAT,
|
||||||
ifnull(ROW_FORMAT, 'NONE') as ROW_FORMAT,
|
ifnull(ROW_FORMAT, 'NONE') as ROW_FORMAT,
|
||||||
ifnull(SPACE_TYPE, 'NONE') as SPACE_TYPE,
|
ifnull(SPACE_TYPE, 'NONE') as SPACE_TYPE,
|
||||||
FILE_SIZE,
|
FILE_SIZE,
|
||||||
ALLOCATED_SIZE
|
ALLOCATED_SIZE
|
||||||
FROM information_schema.innodb_sys_tablespaces
|
FROM information_schema.` + "`%s`"
|
||||||
`
|
|
||||||
|
|
||||||
// Metric descriptors.
|
// Metric descriptors.
|
||||||
var (
|
var (
|
||||||
@@ -74,7 +86,21 @@ func (ScrapeInfoSchemaInnodbTablespaces) 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 (ScrapeInfoSchemaInnodbTablespaces) Scrape(ctx context.Context, db *sql.DB, ch chan<- prometheus.Metric, logger log.Logger) error {
|
func (ScrapeInfoSchemaInnodbTablespaces) Scrape(ctx context.Context, db *sql.DB, ch chan<- prometheus.Metric, logger log.Logger) error {
|
||||||
tablespacesRows, err := db.QueryContext(ctx, innodbTablespacesQuery)
|
var tablespacesTablename string
|
||||||
|
var query string
|
||||||
|
err := db.QueryRowContext(ctx, innodbTablespacesTablenameQuery).Scan(&tablespacesTablename)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
switch tablespacesTablename {
|
||||||
|
case "INNODB_SYS_TABLESPACES", "INNODB_TABLESPACES":
|
||||||
|
query = fmt.Sprintf(innodbTablespacesQuery, tablespacesTablename, tablespacesTablename)
|
||||||
|
default:
|
||||||
|
return errors.New("Couldn't find INNODB_SYS_TABLESPACES or INNODB_TABLESPACES in information_schema.")
|
||||||
|
}
|
||||||
|
|
||||||
|
tablespacesRows, err := db.QueryContext(ctx, query)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user