mirror of
https://github.com/prometheus-community/postgres_exporter
synced 2025-04-23 07:25:28 +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
|
userQueriesPath string
|
||||||
duration prometheus.Gauge
|
duration prometheus.Gauge
|
||||||
error prometheus.Gauge
|
error prometheus.Gauge
|
||||||
connectionError prometheus.Gauge
|
psqlUp prometheus.Gauge
|
||||||
userQueriesError *prometheus.GaugeVec
|
userQueriesError *prometheus.GaugeVec
|
||||||
totalScrapes prometheus.Counter
|
totalScrapes prometheus.Counter
|
||||||
|
|
||||||
@ -711,11 +711,10 @@ func NewExporter(dsn string, userQueriesPath string) *Exporter {
|
|||||||
Name: "last_scrape_error",
|
Name: "last_scrape_error",
|
||||||
Help: "Whether the last scrape of metrics from PostgreSQL resulted in an error (1 for error, 0 for success).",
|
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,
|
Namespace: namespace,
|
||||||
Subsystem: exporter,
|
Name: "up",
|
||||||
Name: "last_scrape_connection_error",
|
Help: "Whether the last scrape of metrics from PostgreSQL was able to connect to the server (1 for yes, 0 for no).",
|
||||||
Help: "Whether the last scrape of metrics from PostgreSQL was able to connect to the server (1 for error, 0 for success).",
|
|
||||||
}),
|
}),
|
||||||
userQueriesError: prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
userQueriesError: prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
||||||
Namespace: namespace,
|
Namespace: namespace,
|
||||||
@ -763,6 +762,7 @@ func (e *Exporter) Collect(ch chan<- prometheus.Metric) {
|
|||||||
ch <- e.duration
|
ch <- e.duration
|
||||||
ch <- e.totalScrapes
|
ch <- e.totalScrapes
|
||||||
ch <- e.error
|
ch <- e.error
|
||||||
|
ch <- e.psqlUp
|
||||||
e.userQueriesError.Collect(ch)
|
e.userQueriesError.Collect(ch)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -969,15 +969,15 @@ 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.connectionError.Set(1)
|
e.psqlUp.Set(0)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
err = d.Ping()
|
err = d.Ping()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
e.connectionError.Set(1)
|
e.psqlUp.Set(0)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
e.connectionError.Set(0)
|
e.psqlUp.Set(1)
|
||||||
|
|
||||||
d.SetMaxOpenConns(1)
|
d.SetMaxOpenConns(1)
|
||||||
d.SetMaxIdleConns(1)
|
d.SetMaxIdleConns(1)
|
||||||
|
Loading…
Reference in New Issue
Block a user