Zabbix 6 监控 kingbase V8数据库(一) 完成元数据库的安装、数据导入以及zabbix server的配置。接下来我们使用zabbix 配置zabbix 监控项目。
链接: link
# egrep -v '$^|#' /etc/zabbix/zabbix_agentd.conf
PidFile=/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agentd.log
LogFileSize=0
Server=192.168.2.171 ##zabbix server ip
ServerActive=192.168.2.171 ##zabbix server ip
Hostname=kdb-192.168.2.152 ##zabbix host
Include=/etc/zabbix/zabbix_agentd.d/*.conf
# systemctl start zabbix-agent.service
创建Host groups
创建host,添加监控模板
添加监控模板Linux by Zabbix agent
监控模板下载地址:
https://git.zabbix.com/projects/ZBX/repos/zabbix/browse/templates/db/postgresql
Template DB KingbaseES 是导入下载的template_db_postgresql.xml
CREATE USER zbx_monitor WITH PASSWORD 'kingbase' INHERIT;
CREATE ROLE
GRANT pg_monitor TO zbx_monitor;
GRANT ROLE
-- To collect WAL metrics, the user must have a `superuser` role.
ALTER USER zbx_monitor WITH SUPERUSER;
修改数据库配置文件
# egrep -v "#|^$" /data/kingbase/data_R6/sys_hba.conf
local all all trust
host all zbx_monitor 127.0.0.1/32 trust
host all all 0.0.0.0/0 scram-sha-256
host all all ::1/128 scram-sha-256
host all all ::0/0 scram-sha-256
local replication all trust
host replication all 127.0.0.1/32 scram-sha-256
host replication all ::1/128 scram-sha-256
修改 /etc/zabbix/zabbix_agentd.d/template_db_postgresql.conf
注意 zabbix agent安装默认创建zabbix 用户,zabbix用户需要有ksql和sys_isready权限。
方法:复制1份数据库安装软件,授权zabbix用户权限,属主属组
# cat /etc/zabbix/zabbix_agentd.d/template_db_postgresql.conf
UserParameter=pgsql.bgwriter[*], /opt/Kingbase/ES/V8/R6/KESRealPro/V008R006C007B0012/Server/bin/ksql -qtAX -h "$1" -p "$2" -U "$3" -d "$4" -f "/var/lib/zabbix/postgresql/pgsql.bgwriter.sql"
UserParameter=pgsql.connections.sum[*], /opt/Kingbase/ES/V8/R6/KESRealPro/V008R006C007B0012/Server/bin/ksql -qtAX -h "$1" -p "$2" -U "$3" -d "$4" -f "/var/lib/zabbix/postgresql/pgsql.connections.sum.sql"
UserParameter=pgsql.connections[*], /opt/Kingbase/ES/V8/R6/KESRealPro/V008R006C007B0012/Server/bin/ksql -qtAX -h "$1" -p "$2" -U "$3" -d "$4" -f "/var/lib/zabbix/postgresql/pgsql.connections.sql"
UserParameter=pgsql.connections.prepared[*], /opt/Kingbase/ES/V8/R6/KESRealPro/V008R006C007B0012/Server/bin/ksql -qtAX -h "$1" -p "$2" -U "$3" -d "$4" -f "/var/lib/zabbix/postgresql/pgsql.connections.prepared.sql"
UserParameter=pgsql.dbstat.sum[*], /opt/Kingbase/ES/V8/R6/KESRealPro/V008R006C007B0012/Server/bin/ksql -qtAX -h "$1" -p "$2" -U "$3" -d "$4" -f "/var/lib/zabbix/postgresql/pgsql.dbstat.sum.sql"
UserParameter=pgsql.dbstat[*], /opt/Kingbase/ES/V8/R6/KESRealPro/V008R006C007B0012/Server/bin/ksql -qtAX -h "$1" -p "$2" -U "$3" -d "$4" -f "/var/lib/zabbix/postgresql/pgsql.dbstat.sql"
UserParameter=pgsql.transactions[*], /opt/Kingbase/ES/V8/R6/KESRealPro/V008R006C007B0012/Server/bin/ksql -qtAX -h "$1" -p "$2" -U "$3" -d "$4" -f "/var/lib/zabbix/postgresql/pgsql.transactions.sql"
UserParameter=pgsql.config.hash[*], /opt/Kingbase/ES/V8/R6/KESRealPro/V008R006C007B0012/Server/bin/ksql -qtAX -h "$1" -p "$2" -U "$3" -d "$4" -f "/var/lib/zabbix/postgresql/pgsql.config.hash.sql"
UserParameter=pgsql.wal.stat[*], /opt/Kingbase/ES/V8/R6/KESRealPro/V008R006C007B0012/Server/bin/ksql -qtAX -h "$1" -p "$2" -U "$3" -d "$4" -f "/var/lib/zabbix/postgresql/pgsql.wal.stat.sql"
UserParameter=pgsql.locks[*], /opt/Kingbase/ES/V8/R6/KESRealPro/V008R006C007B0012/Server/bin/ksql -qtAX -h "$1" -p "$2" -U "$3" -d "$4" -f "/var/lib/zabbix/postgresql/pgsql.locks.sql"
UserParameter=pgsql.queries[*], /opt/Kingbase/ES/V8/R6/KESRealPro/V008R006C007B0012/Server/bin/ksql -qtAX -h "$1" -p "$2" -U "$3" -d "$4" -v tmax=$5 -f "/var/lib/zabbix/postgresql/pgsql.query.time.sql"
UserParameter=pgsql.uptime[*], /opt/Kingbase/ES/V8/R6/KESRealPro/V008R006C007B0012/Server/bin/ksql -qtAX -h "$1" -p "$2" -U "$3" -d "$4" -f "/var/lib/zabbix/postgresql/pgsql.uptime.sql"
UserParameter=pgsql.cache.hit[*], /opt/Kingbase/ES/V8/R6/KESRealPro/V008R006C007B0012/Server/bin/ksql -qtAX -h "$1" -p "$2" -U "$3" -d "$4" -f "/var/lib/zabbix/postgresql/pgsql.cache.hit.sql"
UserParameter=pgsql.scans[*], /opt/Kingbase/ES/V8/R6/KESRealPro/V008R006C007B0012/Server/bin/ksql -qtAX -h "$1" -p "$2" -U "$3" -d "$4" -f "/var/lib/zabbix/postgresql/pgsql.scans.sql"
UserParameter=pgsql.frozenxid[*], /opt/Kingbase/ES/V8/R6/KESRealPro/V008R006C007B0012/Server/bin/ksql -qtAX -h "$1" -p "$2" -U "$3" -d "$4" -f "/var/lib/zabbix/postgresql/pgsql.frozenxid.sql"
UserParameter=pgsql.discovery.db[*], /opt/Kingbase/ES/V8/R6/KESRealPro/V008R006C007B0012/Server/bin/ksql -qtAX -h "$1" -p "$2" -U "$3" -d "$4" -f "/var/lib/zabbix/postgresql/pgsql.discovery.db.sql"
UserParameter=pgsql.db.size[*], /opt/Kingbase/ES/V8/R6/KESRealPro/V008R006C007B0012/Server/bin/ksql -qtAX -h "$1" -p "$2" -U "$3" -d "$4" -c "SELECT pg_database_size('$5')"
UserParameter=pgsql.ping[*], /opt/Kingbase/ES/V8/R6/KESRealPro/V008R006C007B0012/Server/bin/sys_isready -h "$1" -p "$2" -U "$3" -d "$4"
UserParameter=pgsql.ping.time[*], /opt/Kingbase/ES/V8/R6/KESRealPro/V008R006C007B0012/Server/bin/ksql -qtAX -h "$1" -p "$2" -U "$3" -d "$4" -f "/var/lib/zabbix/postgresql/pgsql.ping.time.sql"
UserParameter=pgsql.version[*], /opt/Kingbase/ES/V8/R6/KESRealPro/V008R006C007B0012/Server/bin/ksql -qtAX -h "$1" -p "$2" -U "$3" -d "$4" -c "SELECT version();"
UserParameter=pgsql.replication.count[*], /opt/Kingbase/ES/V8/R6/KESRealPro/V008R006C007B0012/Server/bin/ksql -qtAX -h "$1" -p "$2" -U "$3" -d "$4" -c "SELECT count(*) FROM pg_stat_replication"
UserParameter=pgsql.replication.recovery_role[*], /opt/Kingbase/ES/V8/R6/KESRealPro/V008R006C007B0012/Server/bin/ksql -qtAX -h "$1" -p "$2" -U "$3" -d "$4" -f "/var/lib/zabbix/postgresql/pgsql.replication.recovery_role.sql"
UserParameter=pgsql.replication.lag.sec[*], /opt/Kingbase/ES/V8/R6/KESRealPro/V008R006C007B0012/Server/bin/ksql -qtAX -h "$1" -p "$2" -U "$3" -d "$4" -f "/var/lib/zabbix/postgresql/pgsql.replication.lag.sql"
UserParameter=pgsql.replication.status[*], /opt/Kingbase/ES/V8/R6/KESRealPro/V008R006C007B0012/Server/bin/ksql -qtAX -h "$1" -p "$2" -U "$3" -d "$4" -f "/var/lib/zabbix/postgresql/pgsql.replication.status.sql"
# ls -l /var/lib/zabbix/postgresql/
total 80
-rwxr-xr-x. 1 zabbix zabbix 492 Dec 27 09:49 pgsql.bgwriter.sql
-rwxr-xr-x. 1 zabbix zabbix 81 Dec 27 09:49 pgsql.cache.hit.sql
-rwxr-xr-x. 1 zabbix zabbix 371 Dec 27 09:49 pgsql.config.hash.sql
-rwxr-xr-x. 1 zabbix zabbix 39 Dec 27 09:49 pgsql.connections.prepared.sql
-rwxr-xr-x. 1 zabbix zabbix 1367 Dec 27 09:49 pgsql.connections.sql
-rwxr-xr-x. 1 zabbix zabbix 1357 Dec 27 09:49 pgsql.connections.sum.sql
-rwxr-xr-x. 1 zabbix zabbix 340 Dec 27 14:24 pgsql.dbstat.sql
-rwxr-xr-x. 1 zabbix zabbix 549 Dec 27 09:49 pgsql.dbstat.sum.sql
-rwxr-xr-x. 1 zabbix zabbix 236 Dec 27 09:49 pgsql.discovery.db.sql
-rwxr-xr-x. 1 zabbix zabbix 510 Dec 27 09:49 pgsql.frozenxid.sql
-rwxr-xr-x. 1 zabbix zabbix 1297 Dec 27 09:49 pgsql.locks.sql
-rwxr-xr-x. 1 zabbix zabbix 18 Dec 27 09:49 pgsql.ping.time.sql
-rwxr-xr-x. 1 zabbix zabbix 3256 Dec 27 09:49 pgsql.query.time.sql
-rwxr-xr-x. 1 zabbix zabbix 735 Dec 27 09:49 pgsql.replication.lag.sql
-rwxr-xr-x. 1 zabbix zabbix 32 Dec 27 09:49 pgsql.replication.recovery_role.sql
-rwxr-xr-x. 1 zabbix zabbix 490 Dec 27 09:49 pgsql.replication.status.sql
-rwxr-xr-x. 1 zabbix zabbix 259 Dec 27 09:49 pgsql.scans.sql
-rwxr-xr-x. 1 zabbix zabbix 1425 Dec 27 09:49 pgsql.transactions.sql
-rwxr-xr-x. 1 zabbix zabbix 67 Dec 27 09:49 pgsql.uptime.sql
-rwxr-xr-x. 1 zabbix zabbix 702 Dec 27 09:49 pgsql.wal.stat.sql
注意 pgsql.dbstat.sql 监控信息获取脚本,加一下where条件 datname is not null
# cat pgsql.dbstat.sql
SELECT json_object_agg(datname, row_to_json(T)) FROM (
SELECT datname,
numbackends,
xact_commit,
xact_rollback,
blks_read,
blks_hit,
tup_returned,
tup_fetched,
tup_inserted,
tup_updated,
tup_deleted,
conflicts,
temp_files,
temp_bytes,
deadlocks
FROM pg_stat_database where datname is not null) T
重启zabbix agent
# systemctl restart zabbix-agent.service