Professional Documents
Culture Documents
ASMIOSTAT Script To Collect Iostats For ASM Disks (ID 437996.1)
ASMIOSTAT Script To Collect Iostats For ASM Disks (ID 437996.1)
In this Document
Purpose
Software Requirements/Prerequisites
Configuring the Script
Running the Script
Caution
Script
Script Output
Applies to:
Oracle Server - Enterprise Edition - Version: 10.1.0.3 to 11.1.0.7 - Release: 10.1 to 11.1
Information in this document applies to any platform.
***Checked for relevance on 27-Feb-2011***
Purpose
The OS command iostat is normally used to monitoring system input/output device load. This script will provide similar information like iostat but specific for the ASM
disks.
For details about iostat (ie cumulative or not, and so on) please refer to the man of iostat.
Software Requirements/Prerequisites
We use v$asm_disk_stat instead of v$asm_disk because the information is exactly the same.
The only difference is v$asm_disk_stat is the information available in memory while v$asm_disk access the disks to re-collect some information. Since the information
required doesn't require to "re-collect" it from the disks, v$asm_disk_stat is more appropriated here.
In such case, retry using another Shell (ie: Bash instead of Ksh)
1 of 9 12.4.2011 18:14
https://support.oracle.com/CSP/main/article?cmd=show&type=NOT&doctype=SCRIPT&id=43...
We do not guarantee that it will work for you, so be sure to test it in your environment before relying on it. This script is provided as an example. If it
doesn't work, you must adapt it by yourself for your platform
Not required.
Not required
Caution
This script is provided for educational purposes only and not supported by Oracle Support Services. It has been tested internally, however, and works as
documented. We do not guarantee that it will work for you, so be sure to test it in your environment before relying on it.
Proofread this script before using it! Due to the differences in the way text editors, e-mail packages and operating systems handle text formatting (spaces, tabs and
carriage returns), this script may not be in an executable state when you first receive it. Check over the script to ensure that errors of this type are corrected.
Script
#!/bin/ksh
#
# NAME
# asmiostat.sh
#
# DESCRIPTION
# iostat-like output for ASM
# $ asmiostat.sh [-s ASM ORACLE_SID] [-h ASM ORACLE_HOME] [-g Diskgroup]
# [-f disk path filter] [<interval>] [<count>]
#
# NOTES
# Creates persistent SQL*Plus connection to the +ASM instance implemented
# as a ksh co-process
#
# AUTHOR
# Doug Utzig
#
# MODIFIED
# dutzig 08/18/05 - original version
#
2 of 9 12.4.2011 18:14
https://support.oracle.com/CSP/main/article?cmd=show&type=NOT&doctype=SCRIPT&id=43...
ORACLE_SID=+ASM
NLS_LANG=AMERICAN_AMERICA.WE8ISO8859P1
NLS_DATE_FORMAT='DD-MON-YYYY HH24:MI:SS'
endOfOutput="_EOP$$"
typeset -u diskgroup
typeset diskgroup_string="Disk Group: All diskgroups"
typeset usage="
$0 [-s ASM ORACLE_SID] [-h ASM ORACLE_HOME] [-g diskgroup] [<interval>] [<count>]
Output:
DiskPath - Path to ASM disk
DiskName - ASM disk name
Gr - ASM disk group number
Dsk - ASM disk number
Reads - Reads
Writes - Writes
AvRdTm - Average read time (in msec)
AvWrTm - Average write time (in msec)
KBRd - Kilobytes read
KBWr - Kilobytes written
AvRdSz - Average read size (in bytes)
AvWrSz - Average write size (in bytes)
RdEr - Read errors
WrEr - Write errors
"
3 of 9 12.4.2011 18:14
https://support.oracle.com/CSP/main/article?cmd=show&type=NOT&doctype=SCRIPT&id=43...
shift OPTIND-1
#
# Verify interval and count arguments are valid
#
(( interval <=0 || count<0 )) && {
print 'Invalid parameter: <interval> must be > 0; <count> must be >= 0'
print "$usage"
exit 1
}
#
# Query to run against v$asm_disk_stat
#
if [[ -z $diskgroup ]]; then
query="select group_number, disk_number, name, path, reads, writes, read_errs, write_errs, read_time, write_time, bytes_read, bytes_written from v\$asm_disk_stat
where group_number>0 order by group_number, disk_number;"
else
query="select group_number, disk_number, name, path, reads, writes, read_errs, write_errs, read_time, write_time, bytes_read, bytes_written from v\$asm_disk_stat
where group_number=(select group_number from v\$asm_diskgroup_stat where name=regexp_replace('$diskgroup','^\+','')) order by group_number, disk_number;"
fi
#
# Check for version 10.2 or later
#
typeset version minversion=10.2
version=$($ORACLE_HOME/bin/exp </dev/null 2>&1 | grep "Export: " | sed -e 's/^Export: Release \([0-9][0-9]*\.[0-9][0-9]*\).*/\1/')
if ! (print "$version<$minversion" | bc >/dev/null 2>&1); then
print "$0 requires Oracle Database Release $minversion or later"
exit 1
fi
#############################################################################
#
# Fatal error
#----------------------------------------------------------------------------
function fatalError {
print -u2 -- "Error: $1"
exit 1
}
#############################################################################
#
# Drain all of the sqlplus output - stop when we see our well known string
4 of 9 12.4.2011 18:14
https://support.oracle.com/CSP/main/article?cmd=show&type=NOT&doctype=SCRIPT&id=43...
#----------------------------------------------------------------------------
function drainOutput {
typeset dispose=${1:-'dispose'} output
while :; do
read -p output || fatalError 'Read from co-process failed [$0]'
if [[ $QUERYDEBUG == ON ]]; then print $output; fi
if [[ $output == $endOfOutput* ]]; then break; fi
[[ $dispose != 'dispose' ]] && print -- $output
done
}
#############################################################################
#
# Ensure the instance is running and it is of type ASM
#----------------------------------------------------------------------------
function verifyASMinstance {
typeset asmcmdPath=$ORACLE_HOME/bin/asmcmd
[[ ! -x $asmcmdPath ]] && fatalError "Invalid ORACLE_HOME $ORACLE_HOME: $asmcmdPath does not exist"
$asmcmdPath pwd 2>/dev/null | grep -q '^\+$' || fatalError "$ORACLE_SID is not an ASM instance"
}
#############################################################################
#
# Start the sqlplus coprocess
#----------------------------------------------------------------------------
function startSqlplus {
# start sqlplus, setup the env
$ORACLE_HOME/bin/sqlplus -s '/ as sysdba' |&
#############################################################################
#############################################################################
# MAIN
#----------------------------------------------------------------------------
verifyASMinstance
startSqlplus
#
# Loop as many times as requested or forever
5 of 9 12.4.2011 18:14
https://support.oracle.com/CSP/main/article?cmd=show&type=NOT&doctype=SCRIPT&id=43...
#
while :; do
print -p "$query" \
&& print -p "prompt $endOfOutput" \
|| fatalError 'Write to co-process failed (collectData)'
stats=$(drainOutput keep)
print -- "$stats\nEOL"
index=index+1
(( count<index && count>0 )) && break
sleep $interval
done | \
awk '
BEGIN { firstSample=1
}
/^EOL$/ {
firstSample=0; firstLine=1
next
}
{
path=$4
if (path ~ /^ *$/) next
group[path]=$1; disk[path]=$2; name[path]=$3
reads[path]=$5; writes[path]=$6
readErrors[path]=$7; writeErrors[path]=$8
readTime[path]=$9; writeTime[path]=$10
readBytes[path]=$11; writeBytes[path]=$12
# average read time and average write time in msec (data provided in csec)
avgReadTime[path]=0; avgWriteTime[path]=0
if ( readsDiff[path] ) avgReadTime[path]=(readTimeDiff[path]/readsDiff[path])*1000
6 of 9 12.4.2011 18:14
https://support.oracle.com/CSP/main/article?cmd=show&type=NOT&doctype=SCRIPT&id=43...
if ( writesDiff[path]) avgWriteTime[path]=(writeTimeDiff[path]/writesDiff[path])*1000
if (!firstSample) {
if (firstLine) {
"date" | getline now; close("date")
printf "\n"
printf "Date: %s Interval: %d secs %s\n\n", now, '"$interval"', "'"$diskgroup_string"'"
printf "%-40s %2s %3s %8s %8s %6s %6s %8s %8s %7s %7s %4s %4s\n", \
"DiskPath - DiskName","Gr","Dsk","Reads","Writes","AvRdTm",\
"AvWrTm","KBRd","KBWr","AvRdSz","AvWrSz", "RdEr", "WrEr"
firstLine=0
}
printf "%-40s %2s %3s %8d %8d %6.1f %6.1f %8d %8d %7d %7d %4d %4d\n", \
path " - " name[path], group[path], disk[path], \
readsDiff[path], writesDiff[path], \
avgReadTime[path], avgWriteTime[path], \
readKb[path], writeKb[path], \
avgReadSize[path], avgWriteSize[path], \
readErrorsDiff[path], writeErrorsDiff[path]
}
readsPrev[path]=reads[path]; writesPrev[path]=writes[path]
readErrorsPrev[path]=readErrors[path]; writeErrorsPrev[path]=writeErrors[path]
readTimePrev[path]=readTime[path]; writeTimePrev[path]=writeTime[path]
readBytesPrev[path]=readBytes[path]; writeBytesPrev[path]=writeBytes[path]
}
END {
}
'
exit 0
Script Output
7 of 9 12.4.2011 18:14
https://support.oracle.com/CSP/main/article?cmd=show&type=NOT&doctype=SCRIPT&id=43...
Script Output
DiskPath - DiskName Gr Dsk Reads Writes AvRdTm AvWrTm KBRd KBWr AvRdSz AvWrSz RdEr WrEr
/dev/asmdisk14 - DATA_0000 2 0 0 4 0.0 5.0 0 16 0 4096 0 0
/dev/asmdisk4 - DATA_0001 2 1 10 0 17.0 0.0 0 0 0 0 0 0
/dev/asmdisk17 - DATA_0002 2 2 0 1 0.0 0.0 0 0 0 512 0 0
/dev/asmdisk5 - DATA_0003 2 3 0 0 0.0 0.0 0 0 0 0 0 0
/dev/asmdisk16 - DATA_0004 2 4 3 3 6.7 3.3 0 0 0 0 0 0
/dev/asmdisk23 - DATA_0005 2 5 0 0 0.0 0.0 0 0 0 0 0 0
Attachments
Related
Products
Oracle Database Products > Oracle Database > Oracle Database > Oracle Server - Enterprise Edition
8 of 9 12.4.2011 18:14
https://support.oracle.com/CSP/main/article?cmd=show&type=NOT&doctype=SCRIPT&id=43...
Keywords
Back to top
Copyright (c) 2007, 2010, Oracle. All rights reserved. Legal Notices and Terms of Use | Privacy Statement
9 of 9 12.4.2011 18:14