|
| 1 | +#!/bin/bash |
| 2 | +#============================================================================ |
| 3 | +# Title : asmstat |
| 4 | +# Description : Wrapper for iostat that maps ASM devices |
| 5 | +# Author : Bart Sjerps <[email protected]> |
| 6 | +# License : GPLv3+ |
| 7 | +# --------------------------------------------------------------------------- |
| 8 | +# This program is free software: you can redistribute it and/or modify |
| 9 | +# it under the terms of the GNU General Public License as published by |
| 10 | +# the Free Software Foundation, either version 3 of the License, or |
| 11 | +# (at your option) any later version. |
| 12 | +# |
| 13 | +# This program is distributed in the hope that it will be useful, |
| 14 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | +# GNU General Public License at <http://www.gnu.org/licenses/> for |
| 17 | +# more details. |
| 18 | +# --------------------------------------------------------------------------- |
| 19 | +# Revision history: |
| 20 | +# 2016-10-20 : Minor update |
| 21 | +# 2015-03-08 : Fixed alignment |
| 22 | +# 2014-10-24 : Updated template |
| 23 | +# 2014-05-02 : Created |
| 24 | +# --------------------------------------------------------------------------- |
| 25 | +# Additional info: |
| 26 | +# Man page: : Yes |
| 27 | +# Bash completion : No |
| 28 | +#============================================================================ |
| 29 | +# Configuration parameters: |
| 30 | +# --------------------------------------------------------------------------- |
| 31 | + |
| 32 | +#============================================================================ |
| 33 | +# Initialization - Logging - Etc. |
| 34 | +# --------------------------------------------------------------------------- |
| 35 | +# Filter device-mapper and non-disk devices |
| 36 | +sedstring="/dm-/d;/scd/d;" |
| 37 | +#============================================================================ |
| 38 | +# Usage: |
| 39 | +# --------------------------------------------------------------------------- |
| 40 | +usage() { |
| 41 | + cat <<- EOF |
| 42 | + $(basename $0) [ options ] |
| 43 | + |
| 44 | + A wrapper for iostat that translates /dev/sdXX devices into their |
| 45 | + ASM device names. Example: asmstat -xm 2 |
| 46 | + Any options will be directly passed on to iostat. |
| 47 | + See man asmstat(1) and asm(1) for more info. |
| 48 | + |
| 49 | + EOF |
| 50 | +} |
| 51 | +#============================================================================ |
| 52 | +# Main |
| 53 | +# --------------------------------------------------------------------------- |
| 54 | +# Normal getopts doesn't work as we need to pass everything to iostat... |
| 55 | +case $1 in |
| 56 | + -h) usage ; exit 0 ;; |
| 57 | + -?) usage ; exit 0 ;; |
| 58 | +esac |
| 59 | + |
| 60 | +if ! ls /dev/oracleasm/* &>/dev/null ; then |
| 61 | + iostat $@ |
| 62 | +else |
| 63 | + for asmdev in /dev/oracleasm/* |
| 64 | + do |
| 65 | + maj=$(echo "ibase=16; $(stat -Lc '%t' ${asmdev}|tr 'a-z' 'A-Z')"|bc) |
| 66 | + min=$(echo "ibase=16; $(stat -Lc '%T' ${asmdev}|tr 'a-z' 'A-Z')"|bc) |
| 67 | + # get location of dev |
| 68 | + # old method: |
| 69 | + # dev=$(egrep -l "${maj}:${min}$" /sys/devices/{*,*/*,*/*/*}/host*/{*/*,*/*/*}/block/*/dev 2>/dev/null | head -1) |
| 70 | + # better method (!?): |
| 71 | + dev=$(readlink $(find /sys/dev/block -name "${maj}:${min}" | sed -n "1p" )|sed "s/.*\///") |
| 72 | + [[ "$dev" == "" ]] && continue |
| 73 | + disk=$(echo $dev | awk -F'/' '{print $(NF-1)}') |
| 74 | + asmvol=${asmdev##*/} |
| 75 | + # get size of largest string |
| 76 | + len=${#disk} ; (( ${#asmvol} > len)) && len=${#asmvol} |
| 77 | + # align asm volume name to 6 chars |
| 78 | + # translate /dev/sdX into /dev/oracleasm/<vol> |
| 79 | + sedstring="${sedstring}$(printf "s/%-${len}s/%-${len}s/;\n" $disk $asmvol)" |
| 80 | + done |
| 81 | + # run iostat command with translation |
| 82 | + iostat $@ | sed -u "$sedstring" |
| 83 | +fi |
| 84 | + |
0 commit comments