mirror of
https://github.com/prometheus-community/postgres_exporter
synced 2025-02-02 03:21:45 +00:00
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
This commit is contained in:
parent
6802f4bbe3
commit
f4bf817f25
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user