Skip to content

Commit

Permalink
add metrics displaying whether replication is configured or not
Browse files Browse the repository at this point in the history
  • Loading branch information
mmiller1 committed Dec 3, 2021
1 parent 492c004 commit 5fea338
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion collector/slave_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ func (ScrapeSlaveStatus) Scrape(ctx context.Context, db *sql.DB, ch chan<- prome
slaveStatusRows *sql.Rows
err error
)
rowCount := 0
// Try the both syntax for MySQL/Percona and MariaDB
for _, query := range slaveStatusQueries {
slaveStatusRows, err = db.QueryContext(ctx, query)
Expand All @@ -98,8 +99,8 @@ func (ScrapeSlaveStatus) Scrape(ctx context.Context, db *sql.DB, ch chan<- prome
if err != nil {
return err
}

for slaveStatusRows.Next() {
rowCount++
// As the number of columns varies with mysqld versions,
// and sql.Scan requires []interface{}, we need to create a
// slice of pointers to the elements of slaveData.
Expand Down Expand Up @@ -133,6 +134,19 @@ func (ScrapeSlaveStatus) Scrape(ctx context.Context, db *sql.DB, ch chan<- prome
}
}
}
var isConfigured float64
if rowCount > 0 {
isConfigured = 1
} else {
isConfigured = 0
}
ch <- prometheus.MustNewConstMetric(
prometheus.NewDesc(
prometheus.BuildFQName(namespace, slaveStatus, "is_configured"),
"Returns 1 or 0 depending on whether replication is configured.",
nil, nil,
), prometheus.UntypedValue, isConfigured,
)
return nil
}

Expand Down

0 comments on commit 5fea338

Please sign in to comment.