Commit 79020cb5 authored by Roi Ezra's avatar Roi Ezra Committed by Ben Kochie

added GR metrics (#271)

Signed-off-by: 's avatarRoi Ezra <ezraroi@gmail.com>
parent 0b4c7775
......@@ -75,6 +75,7 @@ collect.perf_schema.file_instances | 5.5 | Collect
collect.perf_schema.indexiowaits | 5.6 | Collect metrics from performance_schema.table_io_waits_summary_by_index_usage.
collect.perf_schema.tableiowaits | 5.6 | Collect metrics from performance_schema.table_io_waits_summary_by_table.
collect.perf_schema.tablelocks | 5.6 | Collect metrics from performance_schema.table_lock_waits_summary_by_table.
collect.perf_schema.replication_group_member_stats | 5.7 | Collect metrics from performance_schema.replication_group_member_stats.
collect.slave_status | 5.1 | Collect from SHOW SLAVE STATUS (Enabled by default)
collect.heartbeat | 5.1 | Collect from [heartbeat](#heartbeat).
collect.heartbeat.database | 5.1 | Database from where to collect heartbeat data. (default: heartbeat)
......
......@@ -48,31 +48,32 @@ var (
// Collect defines which metrics we should collect
type Collect struct {
Processlist bool
TableSchema bool
InnodbTablespaces bool
InnodbMetrics bool
GlobalStatus bool
GlobalVariables bool
SlaveStatus bool
AutoIncrementColumns bool
BinlogSize bool
PerfTableIOWaits bool
PerfIndexIOWaits bool
PerfTableLockWaits bool
PerfEventsStatements bool
PerfEventsWaits bool
PerfFileEvents bool
PerfFileInstances bool
UserStat bool
ClientStat bool
TableStat bool
QueryResponseTime bool
EngineTokudbStatus bool
EngineInnodbStatus bool
Heartbeat bool
HeartbeatDatabase string
HeartbeatTable string
Processlist bool
TableSchema bool
InnodbTablespaces bool
InnodbMetrics bool
GlobalStatus bool
GlobalVariables bool
SlaveStatus bool
AutoIncrementColumns bool
BinlogSize bool
PerfTableIOWaits bool
PerfIndexIOWaits bool
PerfTableLockWaits bool
PerfEventsStatements bool
PerfEventsWaits bool
PerfFileEvents bool
PerfFileInstances bool
PerfRepGroupMemberStats bool
UserStat bool
ClientStat bool
TableStat bool
QueryResponseTime bool
EngineTokudbStatus bool
EngineInnodbStatus bool
Heartbeat bool
HeartbeatDatabase string
HeartbeatTable string
}
// Exporter collects MySQL metrics. It implements prometheus.Collector.
......@@ -343,6 +344,15 @@ func (e *Exporter) scrape(ch chan<- prometheus.Metric) {
}
ch <- prometheus.MustNewConstMetric(scrapeDurationDesc, prometheus.GaugeValue, time.Since(scrapeTime).Seconds(), "collect.perf_schema.file_instances")
}
if e.collect.PerfRepGroupMemberStats {
scrapeTime = time.Now()
if err = ScrapeReplicationGroupMemberStats(db, ch); err != nil {
log.Errorln("Error scraping for collect.replication_group_member_stats:", err)
e.scrapeErrors.WithLabelValues("collect.replication_group_member_stats").Inc()
e.error.Set(1)
}
ch <- prometheus.MustNewConstMetric(scrapeDurationDesc, prometheus.GaugeValue, time.Since(scrapeTime).Seconds(), "collect.replication_group_member_stats")
}
if e.collect.UserStat {
scrapeTime = time.Now()
if err = ScrapeUserStat(db, ch); err != nil {
......
package collector
import (
"database/sql"
"github.com/prometheus/client_golang/prometheus"
)
const perfReplicationGroupMemeberStatsQuery = `
SELECT MEMBER_ID,COUNT_TRANSACTIONS_IN_QUEUE,COUNT_TRANSACTIONS_CHECKED,COUNT_CONFLICTS_DETECTED,COUNT_TRANSACTIONS_ROWS_VALIDATING
FROM performance_schema.replication_group_member_stats
`
// Metric descriptors.
var (
performanceSchemaReplicationGroupMemberStatsTransInQueueDesc = prometheus.NewDesc(
prometheus.BuildFQName(namespace, performanceSchema, "transaction_in_queue"),
"The number of transactions in the queue pending conflict detection checks. Once the "+
"transactions have been checked for conflicts, if they pass the check, they are queued to be applied as well.",
[]string{"member_id"}, nil,
)
performanceSchemaReplicationGroupMemberStatsTransCheckedDesc = prometheus.NewDesc(
prometheus.BuildFQName(namespace, performanceSchema, "transaction_checked"),
"The number of transactions that have been checked for conflicts.",
[]string{"member_id"}, nil,
)
performanceSchemaReplicationGroupMemberStatsConflictsDetectedDesc = prometheus.NewDesc(
prometheus.BuildFQName(namespace, performanceSchema, "conflicts_detected"),
"The number of transactions that did not pass the conflict detection check.",
[]string{"member_id"}, nil,
)
performanceSchemaReplicationGroupMemberStatsTransRowValidatingDesc = prometheus.NewDesc(
prometheus.BuildFQName(namespace, performanceSchema, "transaction_rows_validating"),
"The current size of the conflict detection database (against which each transaction is certified).",
[]string{"member_id"}, nil,
)
)
// ScrapeReplicationGroupMemberStats collects from `performance_schema.replication_group_member_stats`.
func ScrapeReplicationGroupMemberStats(db *sql.DB, ch chan<- prometheus.Metric) error {
perfReplicationGroupMemeberStatsRows, err := db.Query(perfReplicationGroupMemeberStatsQuery)
if err != nil {
return err
}
defer perfReplicationGroupMemeberStatsRows.Close()
var (
memberId string
countTransactionsInQueue, countTransactionsChecked uint64
countConflictsDetected, countTransactionsRowsValidating uint64
)
for perfReplicationGroupMemeberStatsRows.Next() {
if err := perfReplicationGroupMemeberStatsRows.Scan(
&memberId, &countTransactionsInQueue, &countTransactionsChecked,
&countConflictsDetected, &countTransactionsRowsValidating,
); err != nil {
return err
}
ch <- prometheus.MustNewConstMetric(
performanceSchemaTableWaitsDesc, prometheus.CounterValue, float64(countTransactionsInQueue),
memberId,
)
ch <- prometheus.MustNewConstMetric(
performanceSchemaTableWaitsDesc, prometheus.CounterValue, float64(countTransactionsChecked),
memberId,
)
ch <- prometheus.MustNewConstMetric(
performanceSchemaTableWaitsDesc, prometheus.CounterValue, float64(countConflictsDetected),
memberId,
)
ch <- prometheus.MustNewConstMetric(
performanceSchemaTableWaitsDesc, prometheus.CounterValue, float64(countTransactionsRowsValidating),
memberId,
)
}
return nil
}
......@@ -93,6 +93,10 @@ var (
"collect.perf_schema.file_instances",
"Collect metrics from performance_schema.file_summary_by_instance",
).Default("false").Bool()
collectPerfRepGroupMemberStats = kingpin.Flag(
"collect.replication_group_member_stats",
"Collect metrics from performance_schema.replication_group_member_stats",
).Default("false").Bool()
collectUserStat = kingpin.Flag(
"collect.info_schema.userstats",
"If running with userstat=1, set to true to collect user statistics",
......@@ -179,31 +183,32 @@ func handler(w http.ResponseWriter, r *http.Request) {
}
collect := collector.Collect{
Processlist: filter(filters, "info_schema.processlist", *collectProcesslist),
TableSchema: filter(filters, "info_schema.tables", *collectTableSchema),
InnodbTablespaces: filter(filters, "info_schema.innodb_tablespaces", *collectInnodbTablespaces),
InnodbMetrics: filter(filters, "info_schema.innodb_metrics", *collectInnodbMetrics),
GlobalStatus: filter(filters, "global_status", *collectGlobalStatus),
GlobalVariables: filter(filters, "global_variables", *collectGlobalVariables),
SlaveStatus: filter(filters, "slave_status", *collectSlaveStatus),
AutoIncrementColumns: filter(filters, "auto_increment.columns", *collectAutoIncrementColumns),
BinlogSize: filter(filters, "binlog_size", *collectBinlogSize),
PerfTableIOWaits: filter(filters, "perf_schema.tableiowaits", *collectPerfTableIOWaits),
PerfIndexIOWaits: filter(filters, "perf_schema.indexiowaits", *collectPerfIndexIOWaits),
PerfTableLockWaits: filter(filters, "perf_schema.tablelocks", *collectPerfTableLockWaits),
PerfEventsStatements: filter(filters, "perf_schema.eventsstatements", *collectPerfEventsStatements),
PerfEventsWaits: filter(filters, "perf_schema.eventswaits", *collectPerfEventsWaits),
PerfFileEvents: filter(filters, "perf_schema.file_events", *collectPerfFileEvents),
PerfFileInstances: filter(filters, "perf_schema.file_instances", *collectPerfFileInstances),
UserStat: filter(filters, "info_schema.userstats", *collectUserStat),
ClientStat: filter(filters, "info_schema.clientstats", *collectClientStat),
TableStat: filter(filters, "info_schema.tablestats", *collectTableStat),
QueryResponseTime: filter(filters, "info_schema.query_response_time", *collectQueryResponseTime),
EngineTokudbStatus: filter(filters, "engine_tokudb_status", *collectEngineTokudbStatus),
EngineInnodbStatus: filter(filters, "engine_innodb_status", *collectEngineInnodbStatus),
Heartbeat: filter(filters, "heartbeat", *collectHeartbeat),
HeartbeatDatabase: *collectHeartbeatDatabase,
HeartbeatTable: *collectHeartbeatTable,
Processlist: filter(filters, "info_schema.processlist", *collectProcesslist),
TableSchema: filter(filters, "info_schema.tables", *collectTableSchema),
InnodbTablespaces: filter(filters, "info_schema.innodb_tablespaces", *collectInnodbTablespaces),
InnodbMetrics: filter(filters, "info_schema.innodb_metrics", *collectInnodbMetrics),
GlobalStatus: filter(filters, "global_status", *collectGlobalStatus),
GlobalVariables: filter(filters, "global_variables", *collectGlobalVariables),
SlaveStatus: filter(filters, "slave_status", *collectSlaveStatus),
AutoIncrementColumns: filter(filters, "auto_increment.columns", *collectAutoIncrementColumns),
BinlogSize: filter(filters, "binlog_size", *collectBinlogSize),
PerfTableIOWaits: filter(filters, "perf_schema.tableiowaits", *collectPerfTableIOWaits),
PerfIndexIOWaits: filter(filters, "perf_schema.indexiowaits", *collectPerfIndexIOWaits),
PerfTableLockWaits: filter(filters, "perf_schema.tablelocks", *collectPerfTableLockWaits),
PerfEventsStatements: filter(filters, "perf_schema.eventsstatements", *collectPerfEventsStatements),
PerfEventsWaits: filter(filters, "perf_schema.eventswaits", *collectPerfEventsWaits),
PerfFileEvents: filter(filters, "perf_schema.file_events", *collectPerfFileEvents),
PerfFileInstances: filter(filters, "perf_schema.file_instances", *collectPerfFileInstances),
PerfRepGroupMemberStats: filter(filters, "perf_schema.replication_group_member_stats", *collectPerfRepGroupMemberStats),
UserStat: filter(filters, "info_schema.userstats", *collectUserStat),
ClientStat: filter(filters, "info_schema.clientstats", *collectClientStat),
TableStat: filter(filters, "info_schema.tablestats", *collectTableStat),
QueryResponseTime: filter(filters, "info_schema.query_response_time", *collectQueryResponseTime),
EngineTokudbStatus: filter(filters, "engine_tokudb_status", *collectEngineTokudbStatus),
EngineInnodbStatus: filter(filters, "engine_innodb_status", *collectEngineInnodbStatus),
Heartbeat: filter(filters, "heartbeat", *collectHeartbeat),
HeartbeatDatabase: *collectHeartbeatDatabase,
HeartbeatTable: *collectHeartbeatTable,
}
registry := prometheus.NewRegistry()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment