一、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