You've already forked postgres_exporter
mirror of
https://github.com/prometheus-community/postgres_exporter.git
synced 2025-11-03 07:53:12 +03:00
Add connection limits metrics for pg_roles and pg_database (#997)
* Add database connection limits metrics Signed-off-by: Jocelyn Thode <jocelyn@thode.email> * Add roles connection limits metrics Signed-off-by: Jocelyn Thode <jocelyn@thode.email> * Fix copyright year Co-authored-by: Joe Adams <github@joeadams.io> Signed-off-by: Jocelyn Thode <jocelynthode@users.noreply.github.com> * Fix spacing in pgDatabaseQuery Co-authored-by: Joe Adams <github@joeadams.io> Signed-off-by: Jocelyn Thode <jocelynthode@users.noreply.github.com> * Fix case on pgRolesConnectionLimitsQuery Co-authored-by: Joe Adams <github@joeadams.io> Signed-off-by: Jocelyn Thode <jocelynthode@users.noreply.github.com> * Do not add roleMetrics when row is not valid Signed-off-by: Jocelyn Thode <jocelyn@thode.email> --------- Signed-off-by: Jocelyn Thode <jocelyn@thode.email> Signed-off-by: Jocelyn Thode <jocelynthode@users.noreply.github.com> Co-authored-by: Joe Adams <github@joeadams.io>
This commit is contained in:
@@ -31,8 +31,8 @@ func TestPGDatabaseCollector(t *testing.T) {
|
||||
|
||||
inst := &instance{db: db}
|
||||
|
||||
mock.ExpectQuery(sanitizeQuery(pgDatabaseQuery)).WillReturnRows(sqlmock.NewRows([]string{"datname"}).
|
||||
AddRow("postgres"))
|
||||
mock.ExpectQuery(sanitizeQuery(pgDatabaseQuery)).WillReturnRows(sqlmock.NewRows([]string{"datname", "datconnlimit"}).
|
||||
AddRow("postgres", 15))
|
||||
|
||||
mock.ExpectQuery(sanitizeQuery(pgDatabaseSizeQuery)).WithArgs("postgres").WillReturnRows(sqlmock.NewRows([]string{"pg_database_size"}).
|
||||
AddRow(1024))
|
||||
@@ -47,6 +47,7 @@ func TestPGDatabaseCollector(t *testing.T) {
|
||||
}()
|
||||
|
||||
expected := []MetricResult{
|
||||
{labels: labelMap{"datname": "postgres"}, value: 15, metricType: dto.MetricType_GAUGE},
|
||||
{labels: labelMap{"datname": "postgres"}, value: 1024, metricType: dto.MetricType_GAUGE},
|
||||
}
|
||||
convey.Convey("Metrics comparison", t, func() {
|
||||
@@ -71,8 +72,8 @@ func TestPGDatabaseCollectorNullMetric(t *testing.T) {
|
||||
|
||||
inst := &instance{db: db}
|
||||
|
||||
mock.ExpectQuery(sanitizeQuery(pgDatabaseQuery)).WillReturnRows(sqlmock.NewRows([]string{"datname"}).
|
||||
AddRow("postgres"))
|
||||
mock.ExpectQuery(sanitizeQuery(pgDatabaseQuery)).WillReturnRows(sqlmock.NewRows([]string{"datname", "datconnlimit"}).
|
||||
AddRow("postgres", nil))
|
||||
|
||||
mock.ExpectQuery(sanitizeQuery(pgDatabaseSizeQuery)).WithArgs("postgres").WillReturnRows(sqlmock.NewRows([]string{"pg_database_size"}).
|
||||
AddRow(nil))
|
||||
@@ -88,6 +89,7 @@ func TestPGDatabaseCollectorNullMetric(t *testing.T) {
|
||||
|
||||
expected := []MetricResult{
|
||||
{labels: labelMap{"datname": "postgres"}, value: 0, metricType: dto.MetricType_GAUGE},
|
||||
{labels: labelMap{"datname": "postgres"}, value: 0, metricType: dto.MetricType_GAUGE},
|
||||
}
|
||||
convey.Convey("Metrics comparison", t, func() {
|
||||
for _, expect := range expected {
|
||||
|
||||
Reference in New Issue
Block a user