zabbix监控oracl表空间
SRMDEV:~#vim /oracle/tablespace_check.sh
#!/bin/bash
# tablespace usagep check
#source ~/.bash_profile
function check {
sqlplus -S "/ as sysdba" << EOF
set linesize 200
set pagesize 200
spool /tmp/tablespace.log
select a.tablespace_name, total, free,(total-free) as usage from
(select tablespace_name, sum(bytes)/1024/1024 as total from dba_data_files group by tablespace_name) a,
(select tablespace_name, sum(bytes)/1024/1024 as free from dba_free_space group by tablespace_name) b
where a.tablespace_name = b.tablespace_name;
spool off
set linesize 100
set pagesize 100
spool /tmp/autex.log
select tablespace_name,autoextensible from dba_data_files;
spool off
quit
EOF
};check &>/dev/null
SRMDEV:~ # cd /usr/local/zabbix/scripts
SRMDEV:/usr/local/zabbix/scripts # vim tablespace_check.sh
#!/bin/bash
# oracle tablespace check
CEHCK_TYPE=$1
TABLESPACE_NAME=$2
function usagepre {
grep "\b$TABLESPACE_NAME\b" /tmp/tablespace.log | awk '{printf "%.f\n",($2-$3)/$2*100}'
}
function available {
grep "\b$TABLESPACE_NAME\b" /tmp/tablespace.log | awk '{printf $3*1024*1024}'
}
function check {
if grep "\b$TABLESPACE_NAME\b" /tmp/autex.log | awk '{print $2}' | uniq | grep "YES" &>/dev/null;then
echo 1
else
echo 0
fi
}
case $CEHCK_TYPE in
pre)
usagepre ;;
fre)
available ;;
check)
check ;;
*)
echo -e "Usage: $0 [pre|fre|check] [TABLESPACE_NAME]"
esac
SRMDEV:/usr/local/zabbix/scripts # vim discovery_oracle_tablespace.sh
#!/bin/bash
#name wangxuejin
#date 2018-12-27
#zabbix discovery oracle tablespace
table_spaces=(`cat /tmp/tablespace.log | sed -e "1,3d" -e "/^$/d" -e "/selected/d" | awk '{print $1}'`)
length=${#table_spaces[@]}
printf "{\n"
printf '\t'"\"data\":["
for ((i=0;i<$length;i++))
do
printf "\n\t\t{"
printf "\"{#TABLESPACE_NAME}\":\"${table_spaces[$i]}\"}"
if [ $i -lt $[$length-1] ];then
printf ","
fi
done
printf "\n\t]\n"
printf "}\n"
~
SRMDEV:/usr/local/zabbix # cd etc/zabbix_agentd.conf.d/
SRMDEV:/usr/local/zabbix/etc/zabbix_agentd.conf.d # vim oracle_tablespace.conf
UserParameter=discovery.oracle.tablespace,/usr/local/zabbix/scripts/discovery_oracle_tablespace.sh UserParameter=tablespace.check[*],/usr/local/zabbix/scripts/tablespace_check.sh $1 $2
SRMDEV:~# vim /usr/local/zabbix/etc/zabbix_agentd.conf
Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/*.conf #去掉注释
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。






