@@ -74,6 +74,7 @@ func (ScrapeSlaveStatus) Scrape(ctx context.Context, db *sql.DB, ch chan<- prome
74
74
slaveStatusRows * sql.Rows
75
75
err error
76
76
)
77
+ rowCount := 0
77
78
// Try the both syntax for MySQL/Percona and MariaDB
78
79
for _ , query := range slaveStatusQueries {
79
80
slaveStatusRows , err = db .QueryContext (ctx , query )
@@ -98,8 +99,8 @@ func (ScrapeSlaveStatus) Scrape(ctx context.Context, db *sql.DB, ch chan<- prome
98
99
if err != nil {
99
100
return err
100
101
}
101
-
102
102
for slaveStatusRows .Next () {
103
+ rowCount ++
103
104
// As the number of columns varies with mysqld versions,
104
105
// and sql.Scan requires []interface{}, we need to create a
105
106
// slice of pointers to the elements of slaveData.
@@ -133,6 +134,19 @@ func (ScrapeSlaveStatus) Scrape(ctx context.Context, db *sql.DB, ch chan<- prome
133
134
}
134
135
}
135
136
}
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
+ )
136
150
return nil
137
151
}
138
152
0 commit comments