1. 安装libzbxpgsql

下载地址https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-7.5-x86_64/

  1. 安装libzbxpgsql
wget https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-7.5-x86_64/pgdg-centos96-9.6-3.noarch.rpm
rpm -ivh pgdg-centos96-9.6-3.noarch.rpm#安装依赖
yum -y install postgresql95-libs  # 已经安装可忽略
yum -y install postgresql-libs
yum -y install libconfig
[root@localhost packages]# find / -name libzbxpgsql.so
[root@localhost packages]# rpm -ivh --force libzbxpgsql-1.1.0-1.el6.x86_64.rpm --nodeps
[root@localhost ~]# find / -name libzbxpgsql.so
/usr/lib64/zabbix/modules/libzbxpgsql.so
/usr/local/zabbix/lib/libzbxpgsql.so
[root@localhost ~]# ln -s /usr/lib64/zabbix/modules/libzbxpgsql.so /usr/local/zabbix/lib/
  1. 配置zabbix配置文件zabbix_agentd.conf
LoadModulePath=/usr/local/zabbix/lib/
LoadModule==libzbxpgsql.so

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

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

[postgres@localhost ~]$ psql  -U monitoring -p 5432 wiseucmsg
Password for user monitoring:
psql (9.6.15)
Type "help" for help.wiseucmsg=> \lList of databasesName    |   Owner   | Encoding |   Collate   |    Ctype    |    Access privileges
-----------+-----------+----------+-------------+-------------+-------------------------postdb1   | postuser1 | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =Tc/postuser1          +|           |          |             |             | postuser1=CTc/postuser1postgres  | 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/postgrestemplate1 | postgres  | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres            +|           |          |             |             | postgres=CTc/postgreswang      | wang      | UTF8     | en_US.UTF-8 | en_US.UTF-8 | wiseucmsg | postgres  | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =Tc/postgres           +|           |          |             |             | postgres=CTc/postgres  +|           |          |             |             | monitoring=c/postgreszabbix    | zabbix    | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
(7 rows)wiseucmsg=>

postgres模板下载地址 : http://pg-monz.github.io/pg_monz/index-en.html
4. 导入监控模板

wget https://codeload.github.com/pg-monz/pg_monz/tar.gz/2.2
[root@localhost ~]# cd pg_monz-2.2
[root@localhost ~/pg_monz-2.2]# ls
LICENSE  pg_monz  quick-install.txt  README-en.md  README.md
[root@localhost ~/pg_monz-2.2]# cd pg_monz
[root@localhost ~/pg_monz-2.2/pg_monz]# ls
template  usr-local-bin  usr-local-etc  zabbix_agentd.d
[root@localhost ~/pg_monz-2.2/pg_monz]# cd template
[root@localhost ~/pg_monz-2.2/pg_monz/template]# ls
Template_App_pgpool-II-36.xml        Template_App_pgpool-II.xml              Template_App_PostgreSQL_SR.xml
Template_App_pgpool-II_watchdog.xml  Template_App_PostgreSQL_SR_Cluster.xml  Template_App_PostgreSQL.xml
[root@localhost ~/pg_monz-2.2/pg_monz/template]# sz Template_App_PostgreSQL.xml

模板在Github上有:
https://github.com/cavaliercoder/libzbxpgsql/tree/master/templates
链接:https://pan.baidu.com/s/16226FZ4UZjsSWqoazrzdNQ
提取码:cyol



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

{$PG_DB} => wiseucmsg

创建postgres图形

Zabbix 通过shell脚本监控PostgreSQL

授权:

CREATE ROLE zabbix WITH LOGIN NOSUPERUSER NOCREATEDB NOCREATEROLE;GRANT CONNECT ON DATABASE test TO zabbix;alter user zabbix with password 'zabbix';

zabbix客户端配置文件,添加监控项

[root@localhost zabbix]# vim /etc/zabbix/zabbix_agentd.conf
[root@localhost zabbix]# systemctl restart zabbix-agentUserParameter=pg_chk[*],/etc/zabbix/chk_pg.sh $1 $2[root@localhost zabbix]# more chk_pg.sh

#shell 参数说明:

$1—>‘totalsize’)
$2—>数据库名

#!/bin/bash
# by dwh 2018.6.21
case $1 in
'totalsize')
psql -h localhost -U zabbix -p 5432 test -t -c "select sum(pg_database_size(datid)) as total_size from pg_stat_database"
;;'db_cache')
db_ca=`psql -h localhost -U zabbix -p 5432 test -t -c "select cast(blks_hit/(blks_read+blks_hit+0.000001)*100.0 as numeric(5,2)) as cache from pg_stat_database where datname
= '$2'"`
if [[ "$db_ca" == 0 ]];then
echo 0
else
echo $db_ca
fi
;;'db_success')
db_su=`psql -h localhost -U zabbix -p 5432 test -t -c "select cast(xact_commit/(xact_rollback+xact_commit+0.000001)*100.0 as numeric(5,2)) as success from pg_stat_database w
here datname = '$2'"`
if [[ "$db_su" == 0 ]];then
echo 0
else
echo $db_su
fi
;;'server_processes')
server_p=`psql -h localhost -U zabbix -p 5432 test -t -c "select sum(numbackends) from pg_stat_database"`
if [[ $server_p -eq 0 ]];then
echo 0
else
echo $server_p
fi
;;'tx_commited')
tx_c=`psql -h localhost -U zabbix -p 5432 test -t -c "select sum(xact_commit) from pg_stat_database"`
if [[ $tx_c -eq 0 ]];then
echo 0
else
echo $tx_c
fi
;;'tx_rolledback')
tx_r=`psql -h localhost -U zabbix -p 5432 test -t -c "select sum(xact_rollback) from pg_stat_database"`
if [[ $tx_r -eq 0 ]];then
echo 0
else
echo $tx_r
fi
;;'db_size')
db_s=`psql -h localhost -U zabbix -p 5432 test -t -c "select pg_database_size('$2')"` #as size"
if [[ $db_s -eq 0 ]];then
echo 0
else
echo $db_s
fi
;;'db_connections')
db_c=`psql -h localhost -U zabbix -p 5432 test -t -c "select numbackends from pg_stat_database where datname = '$2'"`
if [[ $db_c -eq 0 ]];then
echo 0
else
echo $db_c
fi
;;'db_returned')
db_r=`psql -h localhost -U zabbix -p 5432 test -t -c "select tup_returned from pg_stat_database where datname = '$2'"`
if [[ $db_r -eq 0 ]];then
echo 0
else
echo $db_r
fi
;;'db_fetched')
db_f=`psql -h localhost -U zabbix -p 5432 test -t -c "select tup_fetched from pg_stat_database where datname = '$2'"`
if [[ $db_f -eq 0 ]];then
echo 0
else
echo $db_f
fi
;;'db_inserted')
db_i=`psql -h localhost -U zabbix -p 5432 test -t -c "select tup_inserted from pg_stat_database where datname = '$2'"`
if [[ $db_i -eq 0 ]];then
echo 0
else
echo $db_i
fi
;;'db_updated')
db_u=`psql -h localhost -U zabbix -p 5432 test -t -c "select tup_updated from pg_stat_database where datname = '$2'"`
if [[ $db_u -eq 0 ]];then
echo 0
else
echo $db_u
fi
;;'db_deleted')
db_d=`psql -h localhost -U zabbix -p 5432 test -t -c "select tup_deleted from pg_stat_database where datname = '$2'"`
if [[ $db_d -eq 0 ]];then
echo 0
else
echo $db_d
fi
;;'db_commited')
db_co=`psql -h localhost -U zabbix -p 5432 test -t -c "select xact_commit from pg_stat_database where datname = '$2'"`
if [[ $db_co -eq 0 ]];then
echo 0
else
echo $db_co
fi
;;'db_rolled')
db_ro=`psql -h localhost -U zabbix -p 5432 test -t -c "select xact_rollback from pg_stat_database where datname = '$2'"`
if [[ $db_ro -eq 0 ]];then
echo 0
else
echo $db_ro
fi
;;'version')
# psql -h localhost -U zabbix -p 5432 test -t -c "select version()"
psql --version|head -n1 |awk -F " " '{print $3}'
;;
esac

Zabbix监控TCP连接状态

获取tcp连接数的两种方法:

netstat -n | awk '/^tcp/ {++state[$NF]} END {for(key in state) print key,state[key]}'
ss -ant | awk 'NR>1 {++s[$1]} END {for(k in s) print k,s[k]}'

规范脚本存放目录:

mkdir /etc/zabbix/scripts

1.编写监控tcp连接数的shell脚本,并添加执行权限

# cat /etc/zabbix/scripts/tcp_status.sh
#!/bin/bash
#
[ $# -ne 1 ] && echo "Usage:CLOSE-WAIT|CLOSED|CLOSING|ESTAB|FIN-WAIT-1|FIN-WAIT-2|LAST-ACK|LISTEN|SYN-RECV SYN-SENT|TIME-WAIT" && exit 1
tcp_status_fun(){TCP_STAT=$1#netstat -n | awk '/^tcp/ {++state[$NF]} END {for(key in state) print key,state[key]}' > /tmp/netstat.tmpss -ant | awk 'NR>1 {++s[$1]} END {for(k in s) print k,s[k]}' > /tmp/ss.tmpTCP_STAT_VALUE=$(grep "$TCP_STAT" /tmp/ss.tmp | cut -d ' ' -f2)if [ -z $TCP_STAT_VALUE ];thenTCP_STAT_VALUE=0fiecho $TCP_STAT_VALUE
}
tcp_status_fun $1添加执行权限:
chmod +x tcp_status.sh

2.创建一个自定义的key:

# cat /etc/zabbix/zabbix_agentd.d/tcp.conf
UserParameter=tcp_status[*],/bin/bash /etc/zabbix/scripts/tcp_status.sh "$1"

3.重启zabbix-agent,修改配置文件必须重启

systemctl restart  zabbix-agent

4.服务端使用Zabbix_get测试是否能正常获取值

zabbix_get -s 127.0.0.1 -k tcp_status[ESTAB]

5.web界面,导入tcp模板,创建主机并关联tcp模板


参考链接 :
https://www.baidu.com/link?url=Io9LLb-Fveobb7aWkvES-Tm3eY-rc9V5TxJ3zdn0qZMnwt6V7l2d_C3AbJTnizMFSIQuulwQWyaLpUNSfLYtEa&wd=&eqid=856621ed000502de000000065ddc9c7c
zabbix监控nginx :https://www.cnblogs.com/lovelinux199075/p/8990538.html

阿里云centos7监控postgres9.6.6相关推荐

  1. linux (阿里云 CentOS7) 中安装配置 RocketMQ

    前些天发现了一个巨牛的人工智能学习网站,通俗易懂,风趣幽默,忍不住分享一下给大家.点击跳转到教程. JDK1.8的安装: 1.检查系统的JDK版本 根目录下操作:cd java -version 2. ...

  2. 阿里云CentOS7安装Oracle11GR2

    http://blog.csdn.net/lee353086/article/details/51622309 Title: 阿里云CentOS7 Silent Mode安装Oracle11GR2 D ...

  3. 阿里云自定义监控tomcat进程数

    阿里云提供自定义监控SDK,这有助于我们定制化的根据自身业务来做监控,下面我就根据业务需求来介绍一个简单的自定义监控配置. 阿里提供了2个版本的自定义监控接口: 自定义监控SDK(python版) : ...

  4. 安全看得见,阿里云性能监控 ARMS 全真3D拓扑实现一“屏”了然

    微服务架构下,各类服务之间存在着错综复杂的依赖关系.一旦业务出现问题,追查问题源头就好比大海捞针,没有头绪.但业务不等人,此时,在最短的时间内定位问题根源是开发和运维人员对微服务监控产品的核心诉求. ...

  5. 阿里云 centos7 配置SSH 从无到有

    阿里云 Centos7 Linux服务器配置SSH: 注意:centOS 6和centOS7的重启ssh指令不一样. 首先,我们搜索一下CentOS的软件库里面有没有已经定义好的SSH服务器包. 重要 ...

  6. 阿里云安装git_Jenkins准备篇04阿里云Centos7服务器安装git

    前面2篇文章已经完成Jenkins相关配置且成功登录Jenkins.那么基于"Git + Maven + Jenkins 实现自动化部署"之前,还需事先安装好必备的工具.本篇主要针 ...

  7. 【mysql安装】阿里云centos7环境mysql安装

    阿里云centos7环境mysql安装 正文开始@Assassin 目录: 阿里云centos7环境mysql安装 一. 环境说明: 1.1 操作系统: 1.2 MySQL版本: 1.3 安装方式: ...

  8. 阿里云apache配置php mysql_阿里云CentOS7搭建Apache+PHP+MySQL环境

    最近要搭建一个阿里云的LMAP环境,选了CentOS7来做搭建. 1.Apache Centos7默认已经安装httpd服务,只是没有启动. 如果你需要全新安装,可以yum install -y ht ...

  9. 使用阿里云容器监控服务与第三方监控框架集成搭建自己的容器看板

    一.概述 阿里云容器监控服务日前正式上线,容器监控服务提供了非常简单快速地与第三方开源监控方案集成的能力.本篇文章就带领大家一起试用阿里云容器监控服务,并使用目前比较流行的第三方开源监控框架做集成,搭 ...

最新文章

  1. fiddler抓包_Fiddler抓包详解
  2. I.MX6 ar1020 SPI device driver hacking
  3. 计算机系统结构广义定义,《计算机系统结构》电子教案(清华版).ppt.ppt
  4. jquery智能提示
  5. Redis高可用分布式内部交流(九)
  6. Chapter 1 Securing Your Server and Network(6):为SQL Server访问配置防火墙
  7. java 单向链表 双向链表_java 单向链表与双向链表的实现
  8. android sdkversion
  9. 简单总结下8.25技术大会感受
  10. c++ 读取html,C++ 使用MSHTML分析html 转发
  11. LaTeX详细教程+技巧总结
  12. tbase安全和脱敏
  13. 观测云产品更新|新增阿里云账户结算方式;新增 DQL 查询查看器;新增基础设施网络模块等
  14. MySQL5.7 配置优化
  15. **旅行-interveiw
  16. 谷歌翻译插件突然不可用提示Tkk更新失败的解决办法
  17. 如何导出一篇英文文献的全部参考文献
  18. heic格式图片转为jpg格式 安装pyheif
  19. 我学习从事项目经理第三课
  20. 基于slurm框架的GPU服务器集群搭建方法

热门文章

  1. gitblit如何迁移入gitlab合并迁移_gitlab和gitlab项目迁移
  2. html 正方形代码,SVG rect
  3. macos 运行linux,MacOS 上运行shell
  4. linux 系统lv扩展_Filecoin 运维(1) 几个常用的系统配置
  5. java 集合数组 例子_Java数组元素去重(不使用集合)(示例代码)
  6. JBoss + EJB3 + MySql : 开发第一个EJB
  7. android 浏览器开技术
  8. MySQL常用命令_vortex_新浪博客
  9. python3.6.5安装pip_无法在Python3.6中pip安装pickle
  10. pandas读取Excel文件