Skip to content
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions postgres/changelog.d/22999.added
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Adds logical database breakdown for connection metrics
15 changes: 11 additions & 4 deletions postgres/datadog_checks/postgres/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -589,16 +589,23 @@ def trim_leading_set_stmts(sql):
}

CONNECTION_METRICS = {
'descriptors': [],
'descriptors': [('database_name', 'db')],
'metrics': {
'MAX(setting) AS max_connections': ('max_connections', AgentCheck.gauge),
'SUM(numbackends)/MAX(setting) AS pct_connections': ('percent_usage_connections', AgentCheck.gauge),
},
'relation': False,
'query': """
WITH max_con AS (SELECT setting::float FROM pg_settings WHERE name = 'max_connections')
SELECT {metrics_columns}
FROM pg_stat_database, max_con
WITH max_con AS (
SELECT setting::float
FROM pg_settings
WHERE name = 'max_connections'
)
SELECT datname AS database_name
, MAX(max_con.setting) AS max_connections
, numbackends / MAX(max_con.setting) AS pct_connections
FROM pg_stat_database, max_con
GROUP BY datname, numbackends
""",
'name': 'connections_metrics',
}
Expand Down
4 changes: 2 additions & 2 deletions postgres/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@

COMMON_BGW_METRICS_PG_ABOVE_94 = ['postgresql.archiver.archived_count', 'postgresql.archiver.failed_count']
COMMON_BGW_METRICS_PG_BELOW_17 = ['postgresql.bgwriter.buffers_backend', 'postgresql.bgwriter.buffers_backend_fsync']
CONNECTION_METRICS = ['postgresql.max_connections', 'postgresql.percent_usage_connections']
CONNECTION_METRICS_DB = ['postgresql.connections']
CONNECTION_METRICS = []
CONNECTION_METRICS_DB = ['postgresql.connections', 'postgresql.max_connections', 'postgresql.percent_usage_connections']
COMMON_DBS = ['dogs', 'postgres', 'dogs_nofunc', 'dogs_noschema', DB_NAME]

CHECK_PERFORMANCE_METRICS = [
Expand Down
8 changes: 4 additions & 4 deletions postgres/tests/test_pg_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,10 +425,10 @@ def test_connections_metrics(aggregator, integration_check, pg_instance):
check.run()

expected_tags = _get_expected_tags(check, pg_instance)
expected_tags_with_db = expected_tags + ['db:datadog_test']
for name in CONNECTION_METRICS:
aggregator.assert_metric(name, count=1, tags=expected_tags)
expected_tags += ['db:datadog_test']
aggregator.assert_metric('postgresql.connections', count=1, tags=expected_tags)
aggregator.assert_metric(name, count=1, tags=expected_tags_with_db)
aggregator.assert_metric('postgresql.connections', count=1, tags=expected_tags_with_db)


@requires_over_10
Expand Down Expand Up @@ -809,7 +809,7 @@ def test_correct_hostname(
check_activity_metrics(aggregator, tags=expected_activity_tags, hostname=expected_hostname)

for name in CONNECTION_METRICS:
aggregator.assert_metric(name, count=1, tags=expected_tags_no_db, hostname=expected_hostname)
aggregator.assert_metric(name, count=1, tags=expected_tags_with_db, hostname=expected_hostname)

aggregator.assert_service_check(
'postgres.can_connect',
Expand Down
Loading