From f4bf817f2583c9ff7a340e3f56d47ea4abcbaad2 Mon Sep 17 00:00:00 2001 From: Will Rouesnel Date: Wed, 29 Nov 2017 23:08:45 +1100 Subject: [PATCH] Rename the last_scrape_connection_error metric to up. On advice from @SuperQ this is inline with the convention used in similar exporters (example being the mysqld exporter). The full metric name is thus `pg_up`. Closes #135 --- postgres_exporter.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) 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)