Zabbix实战-简易教程--DB类--Pgsql(pg_monz介绍)
作者:@skyflask
转载本文请注明出处:https://www.cnblogs.com/skyflask/articles/8004772.html
目录
一、pg_monz介绍
二、需求
三、数据流
四、安装部署
五、监控项介绍
六、效果图(部分)
七、文献参考
一、pg_monz介绍
1、介绍
pg_monz是一套用于专门监控pgsql的监控脚本,通过zabbix-sender将数据发送给server端。github上看软件介绍,是一个日本人写的。
github地址:https://github.com/pg-monz/pg_monz
2、适用场景
pg_monz适用多种场景,single PostgreSQL pattern, HA pattern with Streaming Replication and load balancing pattern with pgpool-II。
3、pg_monz组成:
(1) Templates
(2)后端脚本
Usr-local-bin目录
通过UserParameters调用定义在文件userparameter_pgsql.conf中的参数获取监控值。
(3) 配置文件
Usr-local-etc
- pgsql_funcs.conf :连接PostgreSQL server的配置信息
- pgpool_funcs.conf :连接 pgpool-II的配置信息
(4) UserParameter 配置文件
二、需求
软件需求:
重要:Agent上必须安装zabbix-sender
三、数据流
单实例模式
- (1) Zabbix agent type item(key: psql.get…) executes monitoring information in bulk regularly.
- (2) On the backend, scripts are executed to collect PostgreSQL statistics information according to UserParameter definitions.
- (3) In these scripts, psql commands are executed to collect data from Database.
- (4) The information which is collected at (3) is sent to Zabbix with zabbix_sender command.
- (5) The data which is sent by zabbix_sender is registered to some Zabbix trapper items.
复制模式
To execute monitoring for Streaming Replication, you should assign the template for Streaming Replicaion to hosts. Streaming Replication template is linked to the template for single PostgreSQL. The (1)-(5) processes is similar to single PostgreSQL pattern.
There is only one different point. In this pattern, you should register the host for the whole Streaming Replication cluster. And you should assign ‘Template App PostgreSQL SR Cluster’ template to this host. So, this template execute aggregating the data to show the whole cluster status.(6)
集群模式
To execute monitoring for pgpool-II, you should assign the template for pgpool-II to hosts. To assign this template, the following process is executed.
- (1) Zabbix agent type item(key: pgpool.get…) executes monitoring information in bulk regularly.
- (2) On the backend, scripts are executed to collect PostgreSQL statistics information according to UserParameter definitions.
- (3) In these scripts, psql commands are executed towards pgpool-II to collect data.
- (4) The information which is collected at (3) is sent to Zabbix with zabbix_sender command.
- (5) The data which is sent by zabbix_sender is registered to some Zabbix trapper items.
Like the Streaming Replication pattern, the whole status of pgpool-II cluster is monitored by assigning the template for pgpool-II cluster.(6)
四、安装部署
(1) Zabbix Agent配置
Agent必须对PostgreSQL logs and pgpool-II logs有执行权限。
(2) 安装 Zabbix-Sender
(3) 部署配置文件和脚本
文件:
cp usr-local-etc/* /usr/local/etc #拷贝配置文件夹到对应目录
[root@bgp-bjzw-zabbix-server02 usr-local-etc]# cat pgsql_funcs.conf PGHOST=127.0.0.1 PGPORT=5432 PGROLE=postgres PGDATABASE=postgres [root@bgp-bjzw-zabbix-server02 usr-local-etc]# cat pgpool_funcs.conf PGPOOLHOST=127.0.0.1 PGPOOLPORT=9999 PGPOOLROLE=postgres PGPOOLDATABASE=postgres PGPOOLCONF=/usr/local/etc/pgpool.conf
脚本:
cp usr-local-bin/* /usr/local/bin
chmod +x /usr/local/bin/*.sh
userparameter_pgsql.conf
cp
userparameter_pgsql.conf
/etc/zabbix/zabbix_agentd.conf.d/userparameter_pgsql.conf
(4) 导入模板
[root@bgp-bjzw-zabbix-server02 template]# ll total 276 -rw-r--r-- 1 root root 6216 May 26 2016 Template_App_pgpool-II_watchdog.xml -rw-r--r-- 1 root root 53618 May 26 2016 Template_App_pgpool-II.xml -rw-r--r-- 1 root root 7974 May 26 2016 Template_App_PostgreSQL_SR_Cluster.xml -rw-r--r-- 1 root root 39832 May 26 2016 Template_App_PostgreSQL_SR.xml -rw-r--r-- 1 root root 164024 May 26 2016 Template_App_PostgreSQL.xml [root@bgp-bjzw-zabbix-server02 template]#
(5) 配置模板宏(macro参数)
(6) 主机上套(套模板)
五、监控项介绍
六、效果图(部分)
因为监控项和图表太多,以下只是截取部分效果图进行展示。
七、文献参考
http://pg-monz.github.io/pg_monz/index-en.html
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 上周热点回顾(3.3-3.9)
· AI 智能体引爆开源社区「GitHub 热点速览」