标签:Oracle 表空间监控
在被监控端创建脚本,此脚本用于获取表空间及空间使用信息,此脚本由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
标签:Oracle 表空间监控
原文地址:http://blog.51cto.com/12146351/2088569