diff --git a/postgres_exporter.go b/postgres_exporter.go index dcb2b8274..0142fba28 100644 --- a/postgres_exporter.go +++ b/postgres_exporter.go @@ -668,7 +668,7 @@ type Exporter struct { userQueriesPath string duration prometheus.Gauge error prometheus.Gauge - connectionError prometheus.Gauge + psqlUp prometheus.Gauge userQueriesError *prometheus.GaugeVec totalScrapes prometheus.Counter @@ -711,11 +711,10 @@ func NewExporter(dsn string, userQueriesPath string) *Exporter { Name: "last_scrape_error", Help: "Whether the last scrape of metrics from PostgreSQL resulted in an error (1 for error, 0 for success).", }), - connectionError: prometheus.NewGauge(prometheus.GaugeOpts{ + psqlUp: prometheus.NewGauge(prometheus.GaugeOpts{ Namespace: namespace, - Subsystem: exporter, - Name: "last_scrape_connection_error", - Help: "Whether the last scrape of metrics from PostgreSQL was able to connect to the server (1 for error, 0 for success).", + Name: "up", + Help: "Whether the last scrape of metrics from PostgreSQL was able to connect to the server (1 for yes, 0 for no).", }), userQueriesError: prometheus.NewGaugeVec(prometheus.GaugeOpts{ Namespace: namespace, @@ -763,6 +762,7 @@ func (e *Exporter) Collect(ch chan<- prometheus.Metric) { ch <- e.duration ch <- e.totalScrapes ch <- e.error + ch <- e.psqlUp e.userQueriesError.Collect(ch) } @@ -969,15 +969,15 @@ func (e *Exporter) getDB(conn string) (*sql.DB, error) { if e.dbConnection == nil { d, err := sql.Open("postgres", conn) if err != nil { - e.connectionError.Set(1) + e.psqlUp.Set(0) return nil, err } err = d.Ping() if err != nil { - e.connectionError.Set(1) + e.psqlUp.Set(0) return nil, err } - e.connectionError.Set(0) + e.psqlUp.Set(1) d.SetMaxOpenConns(1) d.SetMaxIdleConns(1)