Skip to content

Commit

Permalink
Use native DB.Ping() instead of self-written implementation. (#210)
Browse files Browse the repository at this point in the history
Signed-off-by: Kamil Dziedzic <arvenil@klecza.pl>
  • Loading branch information
arvenil authored and SuperQ committed Jun 28, 2018
1 parent 4d7577b commit 6b4e3df
Showing 1 changed file with 1 addition and 5 deletions.
6 changes: 1 addition & 5 deletions collector/exporter.go
Expand Up @@ -25,8 +25,6 @@ const (
// See: https://github.com/go-sql-driver/mysql#system-variables
sessionSettingsParam = `log_slow_filter=%27tmp_table_on_disk,filesort_on_disk%27`
timeoutParam = `lock_wait_timeout=%d`

upQuery = `SELECT 1`
)

// Tunable flags.
Expand Down Expand Up @@ -117,14 +115,12 @@ func (e *Exporter) scrape(ch chan<- prometheus.Metric) {
// Set max lifetime for a connection.
db.SetConnMaxLifetime(1 * time.Minute)

isUpRows, err := db.Query(upQuery)
if err != nil {
if err := db.Ping(); err != nil {
log.Errorln("Error pinging mysqld:", err)
e.metrics.MySQLUp.Set(0)
e.metrics.Error.Set(1)
return
}
isUpRows.Close()

e.metrics.MySQLUp.Set(1)

Expand Down

0 comments on commit 6b4e3df

Please sign in to comment.