Skip to content

Commit 34ab91f

Browse files
committed
add metrics displaying whether replication is configured or not
Signed-off-by: mamiller <[email protected]>
1 parent 492c004 commit 34ab91f

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

collector/slave_status.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ func (ScrapeSlaveStatus) Scrape(ctx context.Context, db *sql.DB, ch chan<- prome
7474
slaveStatusRows *sql.Rows
7575
err error
7676
)
77+
rowCount := 0
7778
// Try the both syntax for MySQL/Percona and MariaDB
7879
for _, query := range slaveStatusQueries {
7980
slaveStatusRows, err = db.QueryContext(ctx, query)
@@ -98,8 +99,8 @@ func (ScrapeSlaveStatus) Scrape(ctx context.Context, db *sql.DB, ch chan<- prome
9899
if err != nil {
99100
return err
100101
}
101-
102102
for slaveStatusRows.Next() {
103+
rowCount++
103104
// As the number of columns varies with mysqld versions,
104105
// and sql.Scan requires []interface{}, we need to create a
105106
// slice of pointers to the elements of slaveData.
@@ -133,6 +134,19 @@ func (ScrapeSlaveStatus) Scrape(ctx context.Context, db *sql.DB, ch chan<- prome
133134
}
134135
}
135136
}
137+
var isConfigured float64
138+
if rowCount > 0 {
139+
isConfigured = 1
140+
} else {
141+
isConfigured = 0
142+
}
143+
ch <- prometheus.MustNewConstMetric(
144+
prometheus.NewDesc(
145+
prometheus.BuildFQName(namespace, slaveStatus, "is_configured"),
146+
"Returns 1 or 0 depending on whether replication is configured.",
147+
nil, nil,
148+
), prometheus.UntypedValue, isConfigured,
149+
)
136150
return nil
137151
}
138152

0 commit comments

Comments
 (0)