Zabbix监控PostgreSQL
admin
2023-05-27 11:01:24
0

Zabbix监控PostgreSQL

学习 PostgreSQL zabbix


  • Zabbix监控PostgreSQL

    • 1. 安装libzbxpgsql

    • 2. 配置zabbix配置文件zabbix_agentd.conf

    • 3. 创建监控用户

    • 4. 导入监控模板

    • 5. 主机链接模板,设置宏变量


因上次用到了PostgreSQL,而所使用的监控又是Zabbix,所以找到了此插件用于Zabbix监控PostgreSQL。

插件网站:PostgreSQL monitoring for Zabbix 
Github地址:https://github.com/cavaliercoder/libzbxpgsql

环境: 
CentOS6.8 
Zabbix3.2.1 
PostgreSQL9.5.6

1. 安装libzbxpgsql

根据官方文档进行安装即可。 
http://cavaliercoder.com/libzbxpgsql/documentation/module-installation/

rpm -ivh https://download.postgresql.org/pub/repos/yum/9.5/redhat/rhel-6-x86_64/pgdg-centos95-9.5-3.noarch.rpm
yum -y install postgresql95-libs  # 已经安装可忽略
yum -y install libconfig
wget http://cdn.cavaliercoder.com/libzbxpgsql/yum/zabbix32/rhel/6/x86_64/libzbxpgsql-1.1.0-1.el6.x86_64.rpm
[root@im109 packages]# find / -name libzbxpgsql.so
[root@im109 packages]# rpm -ivh --force libzbxpgsql-1.1.0-1.el6.x86_64.rpm
error: Failed dependencies:
       libconfig.so.8()(64bit) is needed by libzbxpgsql-1.1.0-1.x86_64
       zabbix-agent >= 3.0.0 is needed by libzbxpgsql-1.1.0-1.x86_64
[root@im109 packages]# rpm -ivh --force libzbxpgsql-1.1.0-1.el6.x86_64.rpm --nodeps
Preparing...                ########################################### [100%]
  1:libzbxpgsql            ########################################### [100%]
[root@im109 packages]# find / -name libzbxpgsql.so                        
/usr/lib64/zabbix/modules/libzbxpgsql.so
[root@im109 packages]# ln -s /usr/lib64/zabbix/modules/libzbxpgsql.so /usr/local/zabbix/lib/

2. 配置zabbix配置文件zabbix_agentd.conf

Zabbix监控PostgreSQL

[root@im109 log]# /usr/local/zabbix/sbin/zabbix_agentd -t pg.modver
zabbix_agentd [21910]: starting agent module libzbxpgsql 1.1.0
zabbix_agentd [21910]: using module configuration file: /etc/zabbix/libzbxpgsql.conf
pg.modver                                     [s|libzbxpgsql 1.1.0, compiled for Zabbix 3.2.3]
[root@im109 log]# /etc/init.d/zabbix-agentd restart
Shutting down Zabbix agent:                                [  OK  ]
Starting Zabbix agent:                                     [  OK  ]

3. 创建监控用户

创建一个用户,开放你所要监控的数据库只读权限给它,为了安全,把权限做到最小化。 
我用的pgpool-II

psql -h 10.1.0.115 -U postgres -p9999         
Password for user postgres:
psql (9.5.6)
Type "help" for help.

postgres=# CREATE ROLE monitoring WITH LOGIN NOSUPERUSER NOCREATEDB NOCREATEROLE;
CREATE ROLE
postgres=# GRANT CONNECT ON DATABASE wiseucmsg TO monitoring;        
GRANT
postgres=# alter user monitoring with password 'password';
ALTER ROLE

使用创建的用户能登录查看相应数据库,则可进行下一步。

[root@im109 pgpool-II]# psql -h localhost -U monitoring -p 54321 wiseucmsg
psql (9.5.6)
Type "help" for help.

wiseucmsg=> \l
                                 List of databases
  Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges  
-----------+----------+----------+-------------+-------------+-----------------------
postgres  
| postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
template0
| postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
         
|          |          |             |             | postgres=CTc/postgres
template1
| postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
         
|          |          |             |             | postgres=CTc/postgres
wiseucmsg
| postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =Tc/postgres         +
         
|          |          |             |             | postgres=CTc/postgres+
         
|          |          |             |             | monitoring=c/postgres
(4 rows)

wiseucmsg=>

4. 导入监控模板

模板在Github上有: 
https://github.com/cavaliercoder/libzbxpgsql/tree/master/templates

5. 主机链接模板,设置宏变量

Zabbix监控PostgreSQL

Zabbix监控PostgreSQL

{$PG_CONN} => host=localhost port=54321 user=monitoring connect_timeout=10 
{$PG_DB} => wiseucmsg

Zabbix监控PostgreSQL

有图形出现,则监控成功。


附件:http://down.51cto.com/data/2366485

相关内容

热门资讯

国务院被掏空,美国外交陷入“空... ◆在美国国务卿鲁比奥的主导下,国务院正全面围绕特朗普的核心议程进行改革。(图源:美联社)文/方晨宇编...
美军“尼米兹”号航母进入加勒比... 新华社华盛顿5月20日电(记者黄强 徐剑梅)美军南方司令部20日在社交媒体发布消息说,美军“尼米兹”...
28个暴雨红色预警信号生效中,... 20日晚,粤西到珠三角南部一带强降水仍在持续,暖湿气流源源不断补充,导致新生成的强降雨云团不断在同一...
中构建筑取得钢结构厂房用可伸缩... 国家知识产权局信息显示,中构建筑有限公司取得一项名为“一种钢结构厂房用可伸缩式抗风支撑杆”的专利,授...
西安光机所破解传统光纤在中长波... 中新网西安5月20日电 (记者 阿琳娜)记者20日从西安光机所获悉,该所郭海涛研究员团队成功研制出国...
北约秘书长“和稀泥”:美国在欧... 【文/观察者网 张菁娟】美国五角大楼日前“取消4000名美军驻波部署”的消息触动了波兰的神经,波兰官...
联想面向广大开发者与用户提供1... 5月19日晚,联想集团执行副总裁兼中国区总裁刘军开启天禧AI Skills(技能集)共创“苍穹计划”...
从“卡脖子”到“掰手腕”:中俄... 人民网记者 张齐 第十届中俄博览会上,人流穿梭。有的展台前载歌载舞,有的展台前分发美食,在几家黑龙江...
原创 一... 本文来源于海潮天下(Marine Biodiversity) 欢迎微信搜索“海潮天下”,关注全球环...
太阳“发脾气”地球会怎样?中欧... “微笑”卫星 据中国科学院消息,中欧联合研制的太阳风-磁层相互作用全景成像卫星(英文缩写SMILE,...