szaydel
7/31/2013 - 1:37 PM

This script will pull out disk statistics formatted as CSV for easier digestion later. Run the script as follows: # nohup iostat_to_csv.sh <

This script will pull out disk statistics formatted as CSV for easier digestion later. Run the script as follows: # nohup iostat_to_csv.sh <count #> <delay #> 2>/dev/null &

Example:

nohup iostat_to_csv.sh poolA 100 1 2>/dev/null &

#!/usr/bin/bash
# The MIT License (MIT)
#
# Copyright (c) 2013 RackTop Systems
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

## This script was not written to be portable, but is known to work correctly on
## RackTop's Brickstor storage appliances. It was written specifically to work on
## these appliances and thus should be assumed to not work elsewhere without prior
## validation.

## If any of the three possible arguments are empty, sane defaults are used, 
## otherwise :
## [1] first argument: pool name, i.e. <poolA>.
## [2] second argument: count == number of times to repeat command.
## [3] third argument: delay == how long to wait between repeating command.
## Run script with nohup, to keep it running disconnected from controlling term.
## >> nohup scriptname.sh 2>/dev/null &

poolname=${1:-poola}
count=${2:-86400}
delay=${3:-1}
HOME=/root

logfile=/root/iostat-xnz-${delay}-${count}-$(hostname)-$(date +"%Y%m%d").log
disks=$(zpool status ${poolname}|awk '/c[0-9]t+/ {print $1}'|xargs)

printf "Poolname: [[ %s ]] Count: [[ %d ]]\n" "$poolname" "$count" 

cd $HOME

/usr/bin/iostat -xnz ${disks} ${delay} ${count} \
| /usr/bin/awk '/c[0-9]t+/ {OFS=","; print $1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11}' >> ${logfile}

/usr/bin/gzip -f -q -9 ${logfile}