Thursday, April 21, 2016

Shell scritp to check space utilization for normal/high redundancy disk group

The space allocation, utilization as well as the space availability in a ASM diskgroup is completely dependent on the type of redundancy defined for a ASM diskgroup.
The free_mb from v$asm_diskgroup is valid only when we are using a external redundancy disk group . why it differ for disk group having redundancy NORMAL/HIGH ?  Its pretty clear from the following facts 

Normal Redundancy: In Normal redundancy, the disks are two way mirrored, therefore we need at least two disks of same size to create a diskgroup with normal redundancy.
High Redundancy: In High redundancy, the disks are three way mirrored, therefore we need at least three disks of same size to create a diskgroup with high redundancy.
External Redundancy: In External redundancy, the disks are not mirrored by ASM. In this case, we may want the disk mirroring to be maintained external to ASM by means of storage array or we may decide not to mirror the disks at all

So in a normal redundancy diskgroup, we should divide the TOTAL_MB/FREE_MB by two to get the actual space allocation and for a high redundancy diskgroup we have to devide by three.

However, this is a lengthy approach; as we need to first identify the diskgroup redundancy level and then adjust our query to get the actual result. There must be some simple method available to identify the actual diskgroup space availability. Yes, it is there……
We can query the USABLE_FILE_MB from V$ASM_DISKGROUP to know the actual free space available within a diskgroup.

I created a shell script to check the space utilization for normal/high redundancy disk group - as I am using exadata in my firm , by default  I can't find any external redundancy  disk group .

 #! /bin/bash
clear
export TERM=xterm
ccc='\033[0;33m'
NC='\033[0m'
green='\033[0;32m'

under='\033[4m\033[1;36m'
green2='\033[30;42m'

for database in $(ps -ef |grep pmon|grep +ASM|awk '{print$8}'| cut -d"_" -f3)
do
export ORACLE_SID=$database
#export ORACLE_SID=${database}1
export ORAENV_ASK=NO
. oraenv >/dev/null 2>&1
echo -e "${under}  ASM Disk Group Usage for - `hostname -f` (`hostname -i`) ${NC}"
echo -e " "
echo -e "Connected ASM instance is ${green2}$ORACLE_SID${NC}"
sqlplus -s " / as sysdba" <<\EOF
SET LINESIZE  145
SET PAGESIZE  9999
SET VERIFY    off
COLUMN group_name         FORMAT a20           HEAD 'Disk Group|Name'
COLUMN state                    FORMAT a11           HEAD 'State'
COLUMN type                     FORMAT a6            HEAD 'Type'
COLUMN total_gb               FORMAT 999,999,999   HEAD 'Total Size (GB)'
COLUMN used_gb                FORMAT 999,999,999   HEAD 'Used Size (GB)'
COLUMN free_gb                FORMAT 999,999,999   HEAD 'Free Size (GB)'
COLUMN pct_free               FORMAT 999.99        HEAD '%Free'
SELECT
    name                                         group_name
  , state                                        state
  , type                                         type
  , Round((TOTAL_MB/1024),2)                     total_gb
  , Round(((TOTAL_MB - USABLE_FILE_MB)/1024),2)  used_gb
  , Round((USABLE_FILE_MB/1024),2)               free_gb
  , Round((USABLE_FILE_MB/TOTAL_MB)*100,2)       pct_free
FROM
    v$asm_diskgroup
ORDER BY pct_free desc;
exit;
EOF
done


Sample output :- 



 Enjoy :)


No comments:

Post a Comment