[Script] ASM Diskgroup Space Usage Alert
Hi Again,
Another important task that a DBA should do is to monitor the ASM diskgroup usage. We do not just add space to tablespaces, create more tablespaces or resize datafiles to increase storage without checking if there is space to our ASM diskgroup. Also, when we perform RMAN backups stored in ASM or Datapump Exports stored in ASM, we have to monitor and get alerts if we are running out of space.
This is a simple monitoring script. I hope this could help you.
Let's share and make others love Oracle, too.
ASM Diskgroup Space Monitoring
######--- Start of Script -----######
#!/bin/bash
# Report ASM Diskgroup space usage
#NOTES:
# 1. There is really a slash on the v$asm_diskgroup so Unix interpreter will treat dollar sign as a literal $
# 2. Set your tablespace threshold by changing the value of the AND clause ">= 80"
sqlplus "/ as sysdba" << EOF
SET LINES 700
SET FEEDBACK OFF
SET TRIMSPOOL ON
SET ECHO OFF
SPOOL /tmp/ASMspace.in
SELECT
name "Diskgroup Name"
, sector_size "SectorSize"
, block_size "Block Size"
, allocation_unit_size "AU Size"
, state "State"
, type "Type"
, ROUND((total_mb/1024),2) "Total Size(GB)"
, ROUND(((total_mb/1024) - (free_mb/1024)),0) "Used Size(GB)"
, ROUND((1- (free_mb / total_mb))*100, 0) "Pct. Used"
FROM
v\$asm_diskgroup
where state <> 'DISMOUNTED'
and (ROUND((1- (free_mb / total_mb))*100, 0)) >= 80
ORDER BY
name;
SPOOL OFF
SET ECHO ON
SET FEEDBACK ON
exit;
EOF
# The text output of the tablespace report will be processed below.
# It will cat (read) the file /tmp/ASMspace.in
# Remove the lines 1 to 20 (sed) as the tablespace report will include the SELECT query and other strings.
# Just adjust these values depending on your text file output. But I think it should be the same
# if you use the script provided above.
cat /tmp/ASMspace.in | sed '1,20d' | sed '$d' | sed '$d' > /tmp/ASMspace.out
# Your /tmp/ASMspace.out file should now only contain the disk group information data
# You can run the cat command above to doublecheck the output.
# Now, we will process this text file
# Here $9 in the awk is the column location of the percent usage of each diskgroup
# $9 will be tested for values if it is equal or greater than the threshold, 80.
# $1 in awk is the ASM Diskgroup name
threshold="80"
i=1
asmresult=`cat /tmp/ASMspace.out | awk '{ print $9 }' | sed 's/%//g'`
for percent in $asmresult; do
if ((percent >= threshold))
then
asmdisk=`cat /tmp/ASMspace.out | head -$i | tail -1| awk '{print $1}'`
echo "Warning: +${asmdisk} is ${percent}% used."
fi
let i=$i+1
done
######--- End of Script -----######
Again, what if you would like to get notified if your ASM Diskgroup reached the threshold.
We will just do the same process as what we did in Monitoring Disk Space article.
######--- Start of Script -----######
#!/bin/bash
# Report ASM Diskgroup space usage
sqlplus "/ as sysdba" << EOF
SET LINES 700
SET FEEDBACK OFF
SET TRIMSPOOL ON
SET ECHO OFF
SPOOL /tmp/ASMspace.in
SELECT
name "Diskgroup Name"
, sector_size "SectorSize"
, block_size "Block Size"
, allocation_unit_size "AU Size"
, state "State"
, type "Type"
, ROUND((total_mb/1024),2) "Total Size(GB)"
, ROUND(((total_mb/1024) - (free_mb/1024)),0) "Used Size(GB)"
, ROUND((1- (free_mb / total_mb))*100, 0) "Pct. Used"
FROM
v\$asm_diskgroup
where state <> 'DISMOUNTED'
-- and (ROUND((1- (free_mb / total_mb))*100, 0)) >= 80
--You can also set the tablespace threshold value here
ORDER BY
name;
SPOOL OFF
SET ECHO ON
SET FEEDBACK ON
exit;
EOF
#sed -n '21,23p' /tmp/ASMspace.in > /tmp/ASMspace.out
cat /tmp/ASMspace.in | sed '1,20d' | sed '$d' | sed '$d' > /tmp/ASMspace.out
threshold="80"
i=1
asmresult=`cat /tmp/ASMspace.out | awk '{ print $9 }' | sed 's/%//g'`
for percent in $asmresult; do
if ((percent >= threshold))
then
asmdisk=`cat /tmp/ASMspace.out | head -$i | tail -1| awk '{print $1}'`
echo "Warning: +${asmdisk} is ${percent}% used."
fi
let i=$i+1
done > /tmp/ASMspace.warning
iFile=/tmp/ASMspace.warning
if [[ -s $iFile ]] ; then
mailx -s ": Tablespace Warning: $ORACLE_SID on ${hostname}" gab@lovesoracle.com < /tmp/ASMspace.warning
else
echo "$iFile is empty." > /tmp/asmnoreport
fi ;
######--- End of Script -----######
My other related monitoring scripts can be accessed through the links below:
[Script] Simple Disk Space Monitoring Alert
[Script] Tablespace Usage Alert
Another important task that a DBA should do is to monitor the ASM diskgroup usage. We do not just add space to tablespaces, create more tablespaces or resize datafiles to increase storage without checking if there is space to our ASM diskgroup. Also, when we perform RMAN backups stored in ASM or Datapump Exports stored in ASM, we have to monitor and get alerts if we are running out of space.
This is a simple monitoring script. I hope this could help you.
Let's share and make others love Oracle, too.
ASM Diskgroup Space Monitoring
######--- Start of Script -----######
#!/bin/bash
# Report ASM Diskgroup space usage
#NOTES:
# 1. There is really a slash on the v$asm_diskgroup so Unix interpreter will treat dollar sign as a literal $
# 2. Set your tablespace threshold by changing the value of the AND clause ">= 80"
sqlplus "/ as sysdba" << EOF
SET LINES 700
SET FEEDBACK OFF
SET TRIMSPOOL ON
SET ECHO OFF
SPOOL /tmp/ASMspace.in
SELECT
name "Diskgroup Name"
, sector_size "SectorSize"
, block_size "Block Size"
, allocation_unit_size "AU Size"
, state "State"
, type "Type"
, ROUND((total_mb/1024),2) "Total Size(GB)"
, ROUND(((total_mb/1024) - (free_mb/1024)),0) "Used Size(GB)"
, ROUND((1- (free_mb / total_mb))*100, 0) "Pct. Used"
FROM
v\$asm_diskgroup
where state <> 'DISMOUNTED'
and (ROUND((1- (free_mb / total_mb))*100, 0)) >= 80
ORDER BY
name;
SPOOL OFF
SET ECHO ON
SET FEEDBACK ON
exit;
EOF
# The text output of the tablespace report will be processed below.
# It will cat (read) the file /tmp/ASMspace.in
# Remove the lines 1 to 20 (sed) as the tablespace report will include the SELECT query and other strings.
# Just adjust these values depending on your text file output. But I think it should be the same
# if you use the script provided above.
cat /tmp/ASMspace.in | sed '1,20d' | sed '$d' | sed '$d' > /tmp/ASMspace.out
# Your /tmp/ASMspace.out file should now only contain the disk group information data
# You can run the cat command above to doublecheck the output.
# Now, we will process this text file
# Here $9 in the awk is the column location of the percent usage of each diskgroup
# $9 will be tested for values if it is equal or greater than the threshold, 80.
# $1 in awk is the ASM Diskgroup name
threshold="80"
i=1
asmresult=`cat /tmp/ASMspace.out | awk '{ print $9 }' | sed 's/%//g'`
for percent in $asmresult; do
if ((percent >= threshold))
then
asmdisk=`cat /tmp/ASMspace.out | head -$i | tail -1| awk '{print $1}'`
echo "Warning: +${asmdisk} is ${percent}% used."
fi
let i=$i+1
done
######--- End of Script -----######
Again, what if you would like to get notified if your ASM Diskgroup reached the threshold.
We will just do the same process as what we did in Monitoring Disk Space article.
######--- Start of Script -----######
#!/bin/bash
# Report ASM Diskgroup space usage
sqlplus "/ as sysdba" << EOF
SET LINES 700
SET FEEDBACK OFF
SET TRIMSPOOL ON
SET ECHO OFF
SPOOL /tmp/ASMspace.in
SELECT
name "Diskgroup Name"
, sector_size "SectorSize"
, block_size "Block Size"
, allocation_unit_size "AU Size"
, state "State"
, type "Type"
, ROUND((total_mb/1024),2) "Total Size(GB)"
, ROUND(((total_mb/1024) - (free_mb/1024)),0) "Used Size(GB)"
, ROUND((1- (free_mb / total_mb))*100, 0) "Pct. Used"
FROM
v\$asm_diskgroup
where state <> 'DISMOUNTED'
-- and (ROUND((1- (free_mb / total_mb))*100, 0)) >= 80
--You can also set the tablespace threshold value here
ORDER BY
name;
SPOOL OFF
SET ECHO ON
SET FEEDBACK ON
exit;
EOF
#sed -n '21,23p' /tmp/ASMspace.in > /tmp/ASMspace.out
cat /tmp/ASMspace.in | sed '1,20d' | sed '$d' | sed '$d' > /tmp/ASMspace.out
threshold="80"
i=1
asmresult=`cat /tmp/ASMspace.out | awk '{ print $9 }' | sed 's/%//g'`
for percent in $asmresult; do
if ((percent >= threshold))
then
asmdisk=`cat /tmp/ASMspace.out | head -$i | tail -1| awk '{print $1}'`
echo "Warning: +${asmdisk} is ${percent}% used."
fi
let i=$i+1
done > /tmp/ASMspace.warning
iFile=/tmp/ASMspace.warning
if [[ -s $iFile ]] ; then
mailx -s ": Tablespace Warning: $ORACLE_SID on ${hostname}" gab@lovesoracle.com < /tmp/ASMspace.warning
else
echo "$iFile is empty." > /tmp/asmnoreport
fi ;
######--- End of Script -----######
My other related monitoring scripts can be accessed through the links below:
[Script] Simple Disk Space Monitoring Alert
[Script] Tablespace Usage Alert
Set up an ASM alert to monitor fluent bit disk group space usage and trigger notifications when usage exceeds a defined threshold.
ReplyDelete