1

使用coroot-pg-agent采集pg指标

 1 year ago
source link: https://blog.51cto.com/lee90/5695468
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

使用coroot-pg-agent采集pg指标

精选 原创

coroot-pg-agent 和 postgres_exporter 的不同之处在于, coroot-pg-agent 主要是根据 pg_stat_statements 这个extension来采集sql维度的指标。 而 postgres_exporter 更关注的是metrics维度的指标。

coroot-pg-agent 的部署也很简单,参考官方github即可。

说明: 我这里演示的pg14,运行在1921端口上

create role coroot_pg_agent with login password '123456';
grant pg_monitor to coroot_pg_agent;

编辑pg配置文件,添加如下
shared_preload_libraries = 'pg_stat_statements'

然后重启生效

登录pg,任一个database下执行:
create extension pg_stat_statements;

# 启动监控进程(这里用的docker版),将metrics的80端口映射为外面的9096端口
docker run -d --name coroot-pg-agent -p 9096:80 --env DSN="postgresql://coroot_pg_agent:[email protected]:1921/postgres?connect_timeout=1&statement_timeout=30000&sslmode=disable" ghcr.io/coroot/coroot-pg-agent

$ cat prometheus.yml 增加如下配置
- job_name: "coroot-pg-agent"
static_configs:
- targets: ["192.168.31.181:9096"]


reload prometheus即可
使用coroot-pg-agent采集pg指标_pg_stat_statements
使用coroot-pg-agent采集pg指标_pg_stat_statements_02
使用coroot-pg-agent采集pg指标_pg_stat_statements_03

指标不是很多,但是都是跟pg_stat_statements 相关联的,这些指标,在分析sql耗时和耗io排行时候还是有用的。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK