Skip to content

Commit

Permalink
Rename the last_scrape_connection_error metric to up.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
wrouesnel committed Nov 29, 2017
1 parent 6802f4b commit f4bf817
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions postgres_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit f4bf817

Please sign in to comment.