Ensure pg_up is always set to 0 when the initial database connection fails.
This did in fact turn out to be an oversight in the error handling. Now, any error in the initial connection path will always trip pg_up to be 0. Fixes #160
This commit is contained in:
parent
989489096e
commit
4117fb2afc
|
@ -969,15 +969,12 @@ func (e *Exporter) getDB(conn string) (*sql.DB, error) {
|
||||||
if e.dbConnection == nil {
|
if e.dbConnection == nil {
|
||||||
d, err := sql.Open("postgres", conn)
|
d, err := sql.Open("postgres", conn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
e.psqlUp.Set(0)
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
err = d.Ping()
|
err = d.Ping()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
e.psqlUp.Set(0)
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
e.psqlUp.Set(1)
|
|
||||||
|
|
||||||
d.SetMaxOpenConns(1)
|
d.SetMaxOpenConns(1)
|
||||||
d.SetMaxIdleConns(1)
|
d.SetMaxIdleConns(1)
|
||||||
|
@ -1011,6 +1008,7 @@ func (e *Exporter) scrape(ch chan<- prometheus.Metric) {
|
||||||
}
|
}
|
||||||
log.Infof("Error opening connection to database (%s): %s", loggableDsn, err)
|
log.Infof("Error opening connection to database (%s): %s", loggableDsn, err)
|
||||||
e.error.Set(1)
|
e.error.Set(1)
|
||||||
|
e.psqlUp.Set(0) // Force "up" to 0 here.
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue