k8s 下通过Prometheus监控postgresql数据库

  • Post author:
  • Post category:其他


k8s 下通过Prometheus监控postgresql数据库,通过grafan展现



1. postgresql创建一个监控账号


postgres_exporter插件官网

非超级用户身份从视图收集指标,>= 10,您可以向用户授予或内置角色

-- To use IF statements, hence to be able to check if the user exists before
-- attempting creation, we need to switch to procedural SQL (PL/pgSQL)
-- instead of standard SQL.
-- More: https://www.postgresql.org/docs/9.3/plpgsql-overview.html
-- To preserve compatibility with <9.0, DO blocks are not used; instead,
-- a function is created and dropped.
CREATE OR REPLACE FUNCTION __tmp_create_user() returns void as $$
BEGIN
  IF NOT EXISTS (
          SELECT                       -- SELECT list can stay empty for this
          FROM   pg_catalog.pg_user
          WHERE  usename = 'postgres_exporter') THEN
    CREATE USER postgres_exporter;
  END IF;
END;
$$ language plpgsql;

SELECT __tmp_create_user();
DROP FUNCTION __tmp_create_user();

ALTER USER postgres_exporter WITH PASSWORD 'XXXXX';
ALTER USER postgres_exporter SET SEARCH_PATH TO postgres_exporter,pg_catalog;

-- If deploying as non-superuser (for example in AWS RDS), uncomment the GRANT
-- line below and replace <MASTER_USER> with your root user.
-- GRANT postgres_exporter TO <MASTER_USER>;

GRANT CONNECT ON DATABASE postgres TO postgres_exporter;



2. k8s下yaml文件



1). postgres_exporter.yaml

创建一个Prometheus的 exporter




版权声明:本文为liu9403原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。