0.概述
zabbix是一款極其強大的開源監控工具,下面我分享下zabbix如何監控表空間,跟著這個思路,監控其他項都是類似操作。
前提條件是你已經有了zabbix server和zabbix agent,且zabbix agent與oracle數據庫運行在一臺機器上面。
1.在agent上面準備腳本
a.定義查表空間使用率的腳本
/home/oracle/get_tablespace_usage.sh
#!/bin/bash
# get tablespace usage
source ~/.bash_profile
function check {
sqlplus -S "/ as sysdba" << EOF
set linesize 200 pagesize 200
set feedback off heading off
spool /tmp/tablespace.log
select tablespace_name,round(used_percent) used_percent from dba_tablespace_usage_metrics;
spool off
quit
EOF
};
check &> /dev/null
errors=`grep ERROR /tmp/tablespace.log | wc -l`
if [ "$errors" -gt 0 ]; then
echo "" > /tmp/tablespace.log
fi
chown oracle: get_tablespace_usage.sh
chmod 755 get_tablespace_usage.sh
b.定義表空間自動發現的腳本
/etc/zabbix/scripts/discovery_tablespace.sh
#!/bin/bash
# zabbix auto discovery oracle tablespace
tablespaces=(`cat /tmp/tablespace.log | awk '{print $1}' | grep -v "^$"`)
length=${#tablespaces[@]}
printf "{\n"
printf '\t'"\"data\":["
for ((i=0;i<$length;i++))
do
printf "\n\t\t{"
printf "\"{#TABLESPACE_NAME}\":\"${tablespaces[$i]}\"}"
if [ $i -lt $[$length-1] ];then
printf ","
fi
done
printf "\n\t]\n"
printf "}\n"
chmod 755/etc/zabbix/scripts/discovery_tablespace.sh
c.定義表空間監控項腳本
/etc/zabbix/scripts/tablespace_check.sh
#!/bin/bash
# oracle tablespace check
TABLESPACE_NAME=$1
grep "\b$TABLESPACE_NAME\b" /tmp/tablespace.log | awk '{print $2}'
chmod 755/etc/zabbix/scripts/tablespace_check.sh
2.將腳本a放入crontab里面
su - oracle
crontab -e
*/5 * * * * /home/oracle/get_tablespace_usage.sh
執行的結果查看/tmp/tablespace.log,第一列是表空間的名字,第二列是對應的表空間使用率
EXAMPLE 2
SYSAUX 3
SYSTEM 5
TBS01 85
TEMP 0
UNDOTBS1 0
USERS 1
3.編輯agent參數
vi /etc/zabbix/zabbix_agentd.d/userparameter_oracle.conf
# tablespace usage
UserParameter=discovery.tablespace,/etc/zabbix/scripts/discovery_tablespace.sh
UserParameter=tablespace.check.[*],/etc/zabbix/scripts/tablespace_check.sh $1
4.在zabbix web界面中設置相關選項
a.創建模板,模板名字隨便起,這里我定義了一個宏

b.創建自動發現規則

c.創建監控項原型

d.創建觸發器類型

e.創建圖形原型

5.測試
我將一個表空間創建表,并插入數據,使其超過80%,看其是否報警


測試通過!
到此這篇關于使用zabbix監控oracle表空間的操作流程的文章就介紹到這了,更多相關zabbix監控oracle表空間內容請搜索腳本之家以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持腳本之家!