数据库
首页 > 数据库> > Grafana 监控 PG数据库的操作过程

Grafana 监控 PG数据库的操作过程

作者:互联网

Grafana 监控 PG数据库的操作过程



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 会报错 搞不定 我就换了.

标签:stat,exporter,postgres,操作过程,Grafana,replication,pg,activity,PG
来源: https://www.cnblogs.com/jinanxiaolaohu/p/15137209.html