@@ -53,12 +53,22 @@ var (
53
53
"Disk space used by the database" ,
54
54
[]string {"datname" }, nil ,
55
55
)
56
+ pgDatabaseConnectionLimitsDesc = prometheus .NewDesc (
57
+ prometheus .BuildFQName (
58
+ namespace ,
59
+ databaseSubsystem ,
60
+ "connection_limit" ,
61
+ ),
62
+ "Connection limit set for the database" ,
63
+ []string {"datname" }, nil ,
64
+ )
56
65
57
- pgDatabaseQuery = "SELECT pg_database.datname FROM pg_database;"
58
- pgDatabaseSizeQuery = "SELECT pg_database_size($1)"
66
+ pgDatabaseQuery = "SELECT pg_database.datname FROM pg_database;"
67
+ pgDatabaseSizeQuery = "SELECT pg_database_size($1)"
68
+ pgDatabaseConnectionLimitsQuery = "select pg_database.datconnlimit FROM pg_database WHERE pg_database.datname = $1"
59
69
)
60
70
61
- // Update implements Collector and exposes database size.
71
+ // Update implements Collector and exposes database size and connection limits .
62
72
// It is called by the Prometheus registry when collecting metrics.
63
73
// The list of databases is retrieved from pg_database and filtered
64
74
// by the excludeDatabase config parameter. The tradeoff here is that
@@ -114,6 +124,20 @@ func (c PGDatabaseCollector) Update(ctx context.Context, instance *instance, ch
114
124
pgDatabaseSizeDesc ,
115
125
prometheus .GaugeValue , sizeMetric , datname ,
116
126
)
127
+
128
+ var connLimit sql.NullInt64
129
+ err = db .QueryRowContext (ctx , pgDatabaseConnectionLimitsQuery , datname ).Scan (& connLimit )
130
+ if err != nil {
131
+ return err
132
+ }
133
+ connLimitMetric := 0.0
134
+ if connLimit .Valid {
135
+ connLimitMetric = float64 (connLimit .Int64 )
136
+ }
137
+ ch <- prometheus .MustNewConstMetric (
138
+ pgDatabaseConnectionLimitsDesc ,
139
+ prometheus .GaugeValue , connLimitMetric , datname ,
140
+ )
117
141
}
118
142
return rows .Err ()
119
143
}
0 commit comments