码迷,mamicode.com
首页 > 其他好文 > 详细

zabbix监控表空间使用率

时间:2019-01-29 20:37:17      阅读:215      评论:0      收藏:0      [点我收藏+]

标签:display   sel   data   表空间   span   code   sage   ase   技术   

[oracle@ip-10-10-40-2 oraclescripts]$ cat check_tablespace.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
quit
EOF
};check &>/dev/null

 

技术分享图片
[oracle@ip-10-10-40-2 oraclescripts]$ cat /tmp/tablespace.log 

TABLESPACE_NAME                     TOTAL       FREE      USAGE                                                                                                                                         
------------------------------ ---------- ---------- ----------                                                                                                                                         
ACTIVITY_TBS                           50         49          1                                                                                                                                         
SYSAUX                              15168   10794.25    4373.75                                                                                                                                         
UNDOTBS1                            98078  4421.1875 93656.8125                                                                                                                                         
UCEX_ACTIVITY_USER                     50    48.0625     1.9375                                                                                                                                         
UCEX_SERVICE_TBS                    10290 10172.6875   117.3125                                                                                                                                         
USERS                                   5     2.1875     2.8125                                                                                                                                         
SYSTEM                              11090  10236.625    853.375                                                                                                                                         
SLUCEX_TBS                             50         49          1                                                                                                                                         
SLUCEXTWO                      135135.563  38541.875 96593.6875                                                                                                                                         

9 rows selected.
View Code

 

[oracle@ip-10-10-40-2 oraclescripts]$ cat discovery_oracle_tablespace.sh 
#!/bin/bash
#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"

 

技术分享图片
[oracle@ip-10-10-40-2 oraclescripts]$ bash discovery_oracle_tablespace.sh 
{
    "data":[
        {"{#TABLESPACE_NAME}":"ACTIVITY_TBS"},
        {"{#TABLESPACE_NAME}":"SYSAUX"},
        {"{#TABLESPACE_NAME}":"UNDOTBS1"},
        {"{#TABLESPACE_NAME}":"UCEX_ACTIVITY_USER"},
        {"{#TABLESPACE_NAME}":"UCEX_SERVICE_TBS"},
        {"{#TABLESPACE_NAME}":"USERS"},
        {"{#TABLESPACE_NAME}":"SYSTEM"},
        {"{#TABLESPACE_NAME}":"SLUCEX_TBS"},
        {"{#TABLESPACE_NAME}":"SLUCEXTWO"}
    ]
}
View Code

 

[oracle@ip-10-10-40-2 oraclescripts]$ cat 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/tablespace.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

 

技术分享图片
[oracle@ip-10-10-40-2 oraclescripts]$ bash tablespace_check.sh pre SLUCEXTWO
71
View Code

 

zabbix监控表空间使用率

标签:display   sel   data   表空间   span   code   sage   ase   技术   

原文地址:https://www.cnblogs.com/penny-pan/p/10335385.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!