The official Zabbix solution provides the use of zabbix-agent2 and ODBC to monitor the Oracle database, but the supported version is 12.2 and above. After analysis, the source code of zabbix-agent2 is an Oracle plug-in part that uses a built-in new function json_table of Oralce 12.2. json_object, use sql to find out that versions below 12.2 do not integrate this function, so the official solution can only monitor higher versions, and orabbix can be used to monitor versions below 12.2.
Basic components - Zabbix server installation
MySQL8.0 installation
Use yum source installation, refer to the official document
https://dev.mysql.com/doc/refman/8.0/en/linux-installation-yum-repo.html
Among them, the 8.0 security mechanism has been upgraded. In order to avoid front-end configuration errors when configuring zabbix, a parameter that allows local login needs to be added to the configuration file.
vi /etc/my.cnf
default_authentication_plugin=mysql_native_password
#重启数据库
systemctl restart mysqld.service
Zabbix installation
Due to the limitation of the Linux operating system version: CentOS7, only Zabbix version 5.0 can be installed. For the installation steps, refer to the official documentation:
https://www.zabbix.com/download?zabbix=5.0&os_distribution=centos&os_version=7&db=mysql&ws=apache
When executing the following command
# yum install zabbix-server-mysql zabbix-agent
Change zabbix-agent to zabbix-agent2 as follows:
# yum install zabbix-server-mysql zabbix-agent2
Because zabbix-agent2 not only includes the original functions of zabbix-agent but also integrates the database monitoring plug-in.
Also note that after creating the database monitoring user, you need to modify the password with the parameter mysql_native_password:
ALTER USER 'zabbix'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
Oracle version monitoring instructions
For different versions of the Oracle database, two agents are used: the official zabbix-agent2 and the third-party orabbix.
The official zabbix-agent2 Oralce data acquisition plug-in uses a built-in new function json_table and json_object of 12C. This function has only been integrated since version 12.1, and directly encapsulates the data detected by sql into json format and sends it to the zabbix-server server.
Versions below 12.1 do not integrate this function, so the official zabbix solution can only monitor higher versions (12.1 and above), and orabbix can be used to monitor versions below 12.1.
Which configure /usr/lib/systemd/system/zabbix-agent2.service
12.1 and above
Use zabbix-agent2 to monitor Oracle high version database
Configure zabbix-agent2
Determine the configuration file used by ps -ef | grep zabbix_agent2
[root@test75v234 ~]# ps -ef | grep zabbix_agent2
zabbix 2166 1 0 Oct28 ? 01:46:47 /usr/sbin/zabbix_agent2 -c /etc/zabbix/zabbix_agent2.conf
root 19423 19352 0 16:06 pts/0 00:00:00 grep --color=auto zabbix_agent2
[root@test75v234 ~]#
Modify /etc/zabbix/zabbix_agent2.conf
sed -i 's/Server=127.0.0.1/Server=【改成zabbix server实际IP】/' /etc/zabbix/zabbix_agentd.conf
sed -i 's/ServerActive=127.0.0.1/ServerActive=【改成zabbix server实际IP】/' /etc/zabbix/zabbix_agentd.conf
sed -i 's/Hostname=Zabbix server/Hostname=【改成zabbix agent2所在的机器的hostname】/' /etc/zabbix/zabbix_agentd.conf
sed -i 's/^# Plugins.Oracle.CallTimeout.*/Plugins.Oracle.CallTimeout=10/' /etc/zabbix/zabbix_agent2.conf
sed -i 's/^# Plugins.Oracle.ConnectTimeout.*/Plugins.Oracle.ConnectTimeout=1/' /etc/zabbix/zabbix_agent2.conf
sed -i 's/^# Plugins.Oracle.KeepAlive=300.*/Plugins.Oracle.KeepAlive=300/' /etc/zabbix/zabbix_agent2.conf
View parameter settings
grep -Ev '^#|^$' /etc/zabbix/zabbix_agent2.conf
Configure the Oracle client
Operate under the root user
Just download the latest version of the client, refer to the document:
https://docs.oracle.com/en/database/oracle/oracle-database/21/lacli/install-instant-client-using-zip.html#GUID-D3DCB4FB -D3CA-4C25-BE48-3A1FB5A22E84
Configuring LD_LIBRARY_PATH requires writing the configuration directly to the configuration file
echo "LD_LIBRARY_PATH=/apps/oracle/instantclient:\$LD_LIBRARY_PATH" > /etc/sysconfig/zabbix-agent2
For non-systemd systems,
add environment variables under the line ### END INIT INFO in the /etc/init.d/zabbix-agent2 file
# export ORACLE_HOME=/apps/oracle
export LD_LIBRARY_PATH=/apps/oracle/instantclient:$LD_LIBRARY_PATH
# export NLS_LANG="AMERICAN_AMERICA.AL32UTF8"
# export TNS_ADMIN=/apps/oracle/instantclient/network/admin
Restart zabbix-agent2
systemctl daemon-reload
source /etc/profile
systemctl restart zabbix-agent2.service
ps -ef|grep zabbix
Create a dedicated database user
alter session set container=orapdb1;--切换到PDB
CREATE USER zabbix_mon IDENTIFIED BY zabbix_mon;
GRANT CONNECT, CREATE SESSION TO zabbix_mon;
GRANT SELECT ON DBA_TABLESPACE_USAGE_METRICS TO zabbix_mon;
GRANT SELECT ON DBA_TABLESPACES TO zabbix_mon;
GRANT SELECT ON DBA_USERS TO zabbix_mon;
GRANT SELECT ON SYS.DBA_DATA_FILES TO zabbix_mon;
GRANT SELECT ON V_$ACTIVE_SESSION_HISTORY TO zabbix_mon;
GRANT SELECT ON V_$ARCHIVE_DEST TO zabbix_mon;
GRANT SELECT ON V_$ASM_DISKGROUP TO zabbix_mon;
GRANT SELECT ON V_$DATABASE TO zabbix_mon;
GRANT SELECT ON V_$DATAFILE TO zabbix_mon;
GRANT SELECT ON V_$INSTANCE TO zabbix_mon;
GRANT SELECT ON V_$LOG TO zabbix_mon;
GRANT SELECT ON V_$OSSTAT TO zabbix_mon;
GRANT SELECT ON V_$PGASTAT TO zabbix_mon;
GRANT SELECT ON V_$PROCESS TO zabbix_mon;
GRANT SELECT ON V_$RECOVERY_FILE_DEST TO zabbix_mon;
GRANT SELECT ON V_$RESTORE_POINT TO zabbix_mon;
GRANT SELECT ON V_$SESSION TO zabbix_mon;
GRANT SELECT ON V_$SGASTAT TO zabbix_mon;
GRANT SELECT ON V_$SYSMETRIC TO zabbix_mon;
GRANT SELECT ON V_$SYSTEM_PARAMETER TO zabbix_mon;
Configure zabbix template
Zabbix5.0 already has its own Oracle monitoring module. When adding a host, select the Template DB Oracle by Zabbix Agent 2 template.
Then configure the values of the following four macros
Then it's done as shown below:
12.1 and below database monitoring
Using orabbix monitoring, the orabbix architecture is shown in the figure
[the transfer of the external link image failed, the source site may have an anti-leeching mechanism, it is recommended to save the image and upload it directly (img-Q8x2AaYD-1637231332263) (http://www.smartmarmot.com/wiki /images/1/1f/Orabbix_architecture.png)]
Installation steps see: http://www.smartmarmot.com/wiki/index.php?title=Orabbix
The existing version on the official website is not compatible with zabbix 5.0. An older brother re-developed it and put it on github. Replace the official existing jar package with orabbix-1.2.4w.jar and it will work.
https://github.com/wanghy8166/orabbix/blob/master/orabbix-1.2.4w.jar
Configure tablespace auto-discovery rules
When we add a table space, we hope that zabbix can automatically recognize the table space we added, instead of adding a piece of sql to the sql query template of orabbix, and then add monitoring items to zabbix, configure advanced, etc. But there is a problem in this place, that is, the automatic discovery rule orabbix has not been implemented, and it is necessary to use zabbix-agent to perform secondary configuration to send json data to the zabbix serve server. The steps are as follows:
- Export the tablespace file through sqlplus spool and store it in text form (mornitor_tbs.sh).
- Write a shell to process text files into json format (oracle_discovery.sh)
- Configure the zabbix-agent client and add customized automatic discovery rules (oracle_check.sh)
The three scripts are as follows:
mornitor_tbs.sh
#此脚本需要放到crontab中调用 */10 * * * * /home/orasit/orabbix/monitor_tbs.sh > /home/orasit/orabbix/monitor_tbs.log
#!/bin/bash
source /home/orasit/.bash_profile
sqlplus -s apps/apps > /tmp/tablespace.log<<\EOF
set linesize 140 pagesize 10000
col "Status" for a10
col "Name" for a25
col "Type" for a10
col "Extent" for a15
SELECT d.status "Status",
d.tablespace_name "Name",
d.contents "Type",
d.extent_management "Extent",
ROUND(NVL(a.bytes, 0)) "Size (M)",
ROUND(NVL(a.bytes - NVL(f.bytes, 0), 0)) "Used (M)",
round(NVL((a.bytes - NVL(f.bytes, 0)) / a.bytes * 100, 0), 2) "Used %"
FROM sys.dba_tablespaces d,
(SELECT tablespace_name, SUM(DECODE(autoextensible, 'YES', maxbytes, 'NO', bytes))/1024/1024 bytes
FROM dba_data_files
GROUP BY tablespace_name) a,
(SELECT tablespace_name, SUM(bytes)/1024/1024 bytes
FROM dba_free_space
GROUP BY tablespace_name) f
WHERE d.tablespace_name = a.tablespace_name(+)
AND d.tablespace_name = f.tablespace_name(+)
--AND d.tablespace_name NOT IN ('SYSAUX', 'SYSTEM')
AND NOT (d.extent_management LIKE 'LOCAL' AND d.contents LIKE 'TEMPORARY')
UNION ALL
SELECT d.status "Status",
d.tablespace_name "Name",
d.contents "Type",
d.extent_management "Extent",
ROUND(NVL(a.bytes, 0)) "Size (M)",
ROUND(NVL(t.bytes, 0)) "Used (M)",
round(NVL(t.bytes / a.bytes * 100, 0), 2) "Used %"
FROM sys.dba_tablespaces d,
(SELECT tablespace_name, SUM(bytes)/1024/1024 bytes
FROM dba_temp_files
GROUP BY tablespace_name) a,
(SELECT tablespace_name, SUM(bytes_cached)/1024/1024 bytes
FROM v$temp_extent_pool
GROUP BY tablespace_name) t
WHERE d.tablespace_name = a.tablespace_name(+)
AND d.tablespace_name = t.tablespace_name(+)
AND d.extent_management LIKE 'LOCAL'
AND d.contents LIKE 'TEMPORARY'
ORDER BY 7;
EOF
sed -i '$d' /tmp/tablespace.log
sed -i '$d' /tmp/tablespace.log
sed -i 's/,//g' /tmp/tablespace.log
Put these two scripts in the zabbix-agent configuration file (/etc/zabbix/zabbix_agentd.conf)
#在/etc/zabbix/zabbix_agentd.conf最后加入
#表空间自动发现及告警
UserParameter=ora.tbs.discovery,/etc/zabbix/zabbix_agentd.d/oracle_discovery.sh
UserParameter=tablespace[*],/etc/zabbix/zabbix_agentd.d/oracle_check.sh $1 $2
oracle_discovery.sh
#!/bin/bash
TABLESPACE=`cat /tmp/tablespace.log |awk '{print$2}'|awk 'NR>3{print}'`
COUNT=`echo "$TABLESPACE" |wc -l`
INDEX=0
echo '{"data":['
echo "$TABLESPACE" | while read LINE; do
echo -n '{"{#TABLESPACE}":"'$LINE'"}'
INDEX=`expr $INDEX + 1`
if [ $INDEX -lt $COUNT ]; then
echo ','
fi
done
echo ']}'
oracle_check.sh
#!/bin/bash
EQ_DATA="$2"
ZBX_REQ_DATA_TAB="$1"
SOURCE_DATA=/tmp/tablespace.log
case $2 in
maxmb) grep -Ew "$ZBX_REQ_DATA_TAB" $SOURCE_DATA |awk '{print $5}';;
used) grep -Ew "$ZBX_REQ_DATA_TAB" $SOURCE_DATA |awk '{print $6}';;
autopercent) grep -Ew "$ZBX_REQ_DATA_TAB" $SOURCE_DATA |awk '{print $7}';;
*) echo $ERROR_WRONG_PARAM; exit 1;;
esac
exit 0
Configure zabbix automatic discovery rules, monitoring items, and alarms
Configure automatic discovery rules
Configure 3 monitoring items, and click the prototype of the monitoring item in the automatic discovery rule:
Tablespace {#TABLESPACE} Utilization
tablespace[{#TABLESPACE},autopercent]
Maximum capacity of table space {#TABLESPACE}/M
tablespace[{#TABLESPACE},maxmb]
Tablespace {#TABLESPACE} already used /M
tablespace[{#TABLESPACE},used]
Configure trigger alerts
TableSpace {#TABLESPACE} alarm
{Template_Oracle-orabbix:tablespace[{#TABLESPACE},autopercent].last()}>95
Configure Graphics
Configure the graphics aggregation effect:
To configure EBS monitoring, you can refer to the following SQL:
https://github.com/ikzelf/zbxdb/blob/master/etc/zbxdb_checks/oracle/ebs.cfg
https://github.com/ikzelf/zbxdb/blob/master/etc/zbxdb_checks/oracle/primary.11.cfg
Additional references:
https://oracle-base.com/articles/misc/an-introduction-to-json-support-in-the-oracle-database#json-support-in-12c
https://seeyon.ren/blog/index.php/archives/223/
https://blog.51cto.com/u_5646435/3170513
https://blog.cactifans.com/2020/05/19/Zabbix5.0%E7%89%88%E6%9C%ACAgent2%E5%AE%89%E8%A3%85/
https://bbs.huaweicloud.com/blogs/249319
https://blog.csdn.net/qq_22894935/article/details/115544995
https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/
https://git.zabbix.com/projects/ZBX/repos/zabbix/browse/templates/db/oracle_agent2?at=release/5.4
https://git.zabbix.com/projects/ZBX/repos/zabbix/browse/src/go/plugins/oracle/README.md
https://git.zabbix.com/projects/ZBX/repos/zabbix/browse/src/go/plugins/oracle
https://www.cnblogs.com/kerrycode/p/13368640.html