Orabbix 監控oracle表空間 Low Level Discovery
在被監控端創建腳本,此腳本用於獲取表空間及空間使用信息,此腳本由oracle用戶下創建
vim mornitor_tbs.sh
#!/bin/bash source /home/oracle/.bash_profile sqlplus -s zabbix/zabbix > /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", NVL(a.bytes, 0) "Size (M)", 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(bytes) bytes from dba_data_files group by tablespace_name) a, (select tablespace_name, sum(bytes) bytes from dba_data_files group by tablespace_name) a, (select tablespace_name, sum(bytes) 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", NVL(a.bytes, 0) "Size (M)", 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) bytes from dba_temp_files group by tablespace_name) a, (select tablespace_name, sum(bytes_cached) 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
2. 利用腳本(oracle_discovery.sh)對取出數據文件(tablespace.log)進行格式化(因為zabbix自動發現數據類型是jason類型),取出Name那一列,後面配置zabbix自動發現用於自定義宏獲取表空間名稱
vim ora_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 '{"{#TBSNAME}":"'$LINE'"}' INDEX=`expr $INDEX + 1` if [ $INDEX -lt $COUNT ]; then echo ',' fi done echo ']}
3. 利用腳本(oracle_check.sh)獲取數據文件(tablespace.log)後三列
vim 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
4. zabbixagent配置文件添加自定義監控key
vim /etc/zabbix/zabbix_agentd.d/userparameter_oracle.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
5. 配置計劃任務,重啟zabbix_agentd服務
*/10 * * * * /app/scripts/monitor_tbs.sh > /app/scripts/monitor_tbs.log
6. 在zabbix_server端添加discovery模板,之前安裝過orabbix,直接在Template_Oracle下添加discovery rule
Configuration-> Template->Template_Oracle->Discovery Rules-> Create Discovery Rule
創建Item prototypes
Name :{#TBSNAME} Autopercent
Key :tablespace[{#TBSNAME},autopercent]
Orabbix 監控oracle表空間 Low Level Discovery