Monitor ASM Diskgroup Usage
This shell script monitors the space utilization of ASM diskgroups and sends an email alert when usage exceeds 90%. It’s essential for Oracle DBAs to stay ahead of potential storage issues in both standalone and RAC environments.
📜 Script: asm_dg.sh
################################################################################
# Title : Monitoring ASM Diskgroup Usage
# Script : asm_dg.sh
# Purpose : Checks ASM diskgroup space usage and sends email alerts
# if utilization exceeds 90%.
#
# Features:
# - Checks all diskgroups via v$asm_diskgroup
# - Sends a detailed usage report if threshold is breached
# - Easy integration into cron for automated monitoring
#
# Author : W3Buddy
# Version : 1.0
################################################################################
#!/bin/bash
# --- Environment Variables ---
export ORACLE_HOME=/oracle/app/oracle/product/12.1.0.2/dbhome_1
export ORACLE_SID=PRODDB1
export PATH=$ORACLE_HOME/bin:$PATH
# --- Log File Location ---
logfile=/export/home/oracle/asm_dg.log
# --- Run SQL and generate report ---
sqlplus -s "/as sysdba" > /dev/null <<EOF
spool $logfile
SET LINESIZE 150
SET PAGESIZE 9999
SET VERIFY OFF
COLUMN group_name FORMAT a25 HEAD 'DISKGROUP_NAME'
COLUMN state FORMAT a11 HEAD 'STATE'
COLUMN type FORMAT a6 HEAD 'TYPE'
COLUMN total_mb FORMAT 999,999,999 HEAD 'TOTAL SIZE (GB)'
COLUMN free_mb FORMAT 999,999,999 HEAD 'FREE SIZE (GB)'
COLUMN used_mb FORMAT 999,999,999 HEAD 'USED SIZE (GB)'
COLUMN pct_used FORMAT 999.99 HEAD 'PERCENTAGE USED'
SELECT DISTINCT
name AS group_name,
state,
type,
ROUND(total_mb/1024) AS total_mb,
ROUND(free_mb/1024) AS free_mb,
ROUND((total_mb - free_mb)/1024) AS used_mb,
ROUND((1 - (free_mb / total_mb)) * 100, 2) AS pct_used
FROM
v\$asm_diskgroup
WHERE
ROUND((1 - (free_mb / total_mb)) * 100, 2) > 90
ORDER BY name;
spool off
exit
EOF
# --- Check and send alert if usage is above threshold ---
if [ $(grep -c "DISKGROUP_NAME" $logfile) -gt 0 ]; then
mailx -s "🚨 ASM DISKGROUP UTILIZATION ABOVE 90%" info.w3buddy@gmail.com < $logfile
fi
⚙️ Setup Instructions
# ----------------------------------------------
# 1. Create the script file
# ----------------------------------------------
cd /export/home/oracle
vi asm_dg.sh
# (Paste the full script above into the file and save)
# ----------------------------------------------
# 2. Make the script executable
# ----------------------------------------------
chmod +x asm_dg.sh
# ----------------------------------------------
# 3. Test the script manually
# ----------------------------------------------
./asm_dg.sh
# Check the output log for diskgroup usage:
cat /export/home/oracle/asm_dg.log
# ----------------------------------------------
# 4. Schedule with cron (every 15 minutes)
# ----------------------------------------------
crontab -e
# Add this line:
0,15,30,45 * * * * /export/home/oracle/asm_dg.sh >> /tmp/asm_dg_cron.log 2>&1
# ----------------------------------------------
# 5. Confirm the cron entry
# ----------------------------------------------
crontab -l