Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add metric displaying whether replication is configured or not #604

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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