@@ -661,7 +661,9 @@ func dbToString(t interface{}) (string, bool) {
661661type Exporter struct {
662662 dsn string
663663 userQueriesPath string
664- duration , error prometheus.Gauge
664+ duration prometheus.Gauge
665+ error prometheus.Gauge
666+ connectionError prometheus.Gauge
665667 userQueriesError * prometheus.GaugeVec
666668 totalScrapes prometheus.Counter
667669
@@ -703,6 +705,12 @@ func NewExporter(dsn string, userQueriesPath string) *Exporter {
703705 Name : "last_scrape_error" ,
704706 Help : "Whether the last scrape of metrics from PostgreSQL resulted in an error (1 for error, 0 for success)." ,
705707 }),
708+ connectionError : prometheus .NewGauge (prometheus.GaugeOpts {
709+ Namespace : namespace ,
710+ Subsystem : exporter ,
711+ Name : "last_scrape_connection_error" ,
712+ Help : "Whether the last scrape of metrics from PostgreSQL was able to connect to the server (1 for error, 0 for success)." ,
713+ }),
706714 userQueriesError : prometheus .NewGaugeVec (prometheus.GaugeOpts {
707715 Namespace : namespace ,
708716 Subsystem : exporter ,
@@ -955,12 +963,16 @@ func (e *Exporter) getDB(conn string) (*sql.DB, error) {
955963 if e .dbConnection == nil {
956964 d , err := sql .Open ("postgres" , conn )
957965 if err != nil {
966+ e .connectionError .Set (1 )
958967 return nil , err
959968 }
960969 err = d .Ping ()
961970 if err != nil {
971+ e .connectionError .Set (1 )
962972 return nil , err
963973 }
974+ e .connectionError .Set (0 )
975+
964976 d .SetMaxOpenConns (1 )
965977 d .SetMaxIdleConns (1 )
966978 e .dbConnection = d
0 commit comments