gpt4 book ai didi

postgresql - Datadog:PostgreSQL custom_metrics 返回单行

转载 作者:行者123 更新时间:2023-11-29 13:14:04 25 4
gpt4 key购买 nike

我想在 Datadog 中创建一个图表来显示每个用户的空闲连接。

以下示例:http://www.miketheman.net/tag/postgres/我将 postgres.yaml 配置更改为:

init_config:
instances:
- host: 127.0.0.1
port: 5432
username: datadog
password: '**************'
tags:
- environment:qa
- role:db
custom_metrics:
- # Postgres Connection state
descriptors:
- [datname, database]
- [usename, user]
- [state, state]
metrics:
COUNT(state): [postgresql.connection_state, GAUGE]
query: >
SELECT datname, usename, state, %s FROM pg_stat_activity
GROUP BY datname, usename, state HAVING COUNT(state) > 0;
relation: false

我可以看到指标出现在 Datadog 中,但我只能看到应该出现的行之一(我的 PostgreSQL 中是否有多个数据库)。

Here is the datadog connection graph我错过了任何一步吗? postgres.yaml 是否缺少任何配置?

在 psql 中运行该查询,我得到这个(修改名称但不修改数据):

    postgres=# SELECT datname, usename, state, COUNT(state) FROM pg_stat_activity GROUP BY datname, usename, state HAVING COUNT(state) > 0;
datname | usename | state | count
---------------------+-------------+---------------------+-------
compan_strawberr_qa | compan | idle in transaction | 1
compan_qa | compan | idle | 130
pineappplee_qa | compan | idle | 10
compan_strawberr_qa | compan | idle | 29
compan_qa | watermel | active | 1
pineappplee_qa | pineappplee | idle | 10
pear_qa | pear | idle | 6
postgres | postgres | active | 1
postgres | datadog | idle | 1
apple_qa | apple_qa | idle | 1
bblluebberrriiess | compan | idle | 3
compan_ser_qa | ser_qa | idle | 4
compan_service_qa | compan | idle | 26
(13 rows)

最佳答案

我找到了解决方案:用户 datadog 没有权限读取不是来自他的连接。所以它只是得到一行。

我授予该用户阅读 pg_stat_activity 的权限

关于postgresql - Datadog:PostgreSQL custom_metrics 返回单行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51323878/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com