作者:跑车世界Y | 来源:互联网 | 2023-08-26 20:37
Grafana监控PG数据库的操作过程容器化运行postgres-exporter进行处理1.镜像运行exporterdockerrun-p9187:9187-eDATA_SOUR
Grafana 监控 PG数据库的操作过程
- 容器化运行 postgres-exporter 进行处理
1. 镜像运行 exporter
docker run -p 9187:9187 -e DATA_SOURCE_NAME="postgresql://postgres:password@myip:5432/postgres?sslmode=disable" quay.io/prometheuscommunity/postgres-exporter
1. 注意他会暴露一个 9187 的端口.
2. 我是通过外网单独拉取的容器镜像.
3. 我用的特权账户, 所以不需要单独建用户和权限, 如果用非特权账户,需要进行sql的创建, 这里选择部分论坛里面一直说明的一些
CREATE USER postgres_exporter PASSWORD 'password';
ALTER USER postgres_exporter SET SEARCH_PATH TO postgres_exporter,pg_catalog;
CREATE SCHEMA postgres_exporter AUTHORIZATION postgres_exporter;
CREATE FUNCTION postgres_exporter.f_select_pg_stat_activity()
RETURNS setof pg_catalog.pg_stat_activity
LANGUAGE sql
SECURITY DEFINER
AS $$
SELECT * from pg_catalog.pg_stat_activity;
$$;
CREATE FUNCTION postgres_exporter.f_select_pg_stat_replication()
RETURNS setof pg_catalog.pg_stat_replication
LANGUAGE sql
SECURITY DEFINER
AS $$
SELECT * from pg_catalog.pg_stat_replication;
$$;
CREATE VIEW postgres_exporter.pg_stat_replication
AS
SELECT * FROM postgres_exporter.f_select_pg_stat_replication();
CREATE VIEW postgres_exporter.pg_stat_activity
AS
SELECT * FROM postgres_exporter.f_select_pg_stat_activity();
GRANT SELECT ON postgres_exporter.pg_stat_replication TO postgres_exporter;
GRANT SELECT ON postgres_exporter.pg_stat_activity TO postgres_exporter;
2.Prometheus添加PG的pull配置节
- job_name: 'OpenPowerPG243'
static_configs:
- targets: ['10.110.80.19:9187']
3. Grafana pull 一个配置节
https://grafana.com/grafana/dashboards/9628
# 备注 很多帖子用 455, 但是我这边使用 455 会报错 搞不定 我就换了.
- 效果为: