1#!/bin/sh 2# 3# Display most relevant iostat bandwidth/latency numbers. The output is 4# dependent on the name of the script/symlink used to call it. 5# 6 7helpstr=" 8iostat: Show iostat values since boot (summary page). 9iostat-1s: Do a single 1-second iostat sample and show values. 10iostat-10s: Do a single 10-second iostat sample and show values." 11 12script=$(basename "$0") 13if [ "$1" = "-h" ] ; then 14 echo "$helpstr" | grep "$script:" | tr -s '\t' | cut -f 2- 15 exit 16fi 17 18if [ "$script" = "iostat-1s" ] ; then 19 # Do a single one-second sample 20 interval=1 21 # Don't show summary stats 22 brief="yes" 23elif [ "$script" = "iostat-10s" ] ; then 24 # Do a single ten-second sample 25 interval=10 26 # Don't show summary stats 27 brief="yes" 28fi 29 30if [ -f "$VDEV_UPATH" ] ; then 31 # We're a file-based vdev, iostat doesn't work on us. Do nothing. 32 exit 33fi 34 35if [ "$(uname)" = "FreeBSD" ]; then 36 out=$(iostat -dKx \ 37 ${interval:+"-w $interval"} \ 38 ${interval:+"-c 1"} \ 39 "$VDEV_UPATH" | tail -n 2) 40else 41 out=$(iostat -kx \ 42 ${brief:+"-y"} \ 43 ${interval:+"$interval"} \ 44 ${interval:+"1"} \ 45 "$VDEV_UPATH" | awk NF | tail -n 2) 46fi 47 48 49# Sample output (we want the last two lines): 50# 51# Linux 2.6.32-642.13.1.el6.x86_64 (centos68) 03/09/2017 _x86_64_ (6 CPU) 52# 53# avg-cpu: %user %nice %system %iowait %steal %idle 54# 0.00 0.00 0.00 0.00 0.00 100.00 55# 56# Device: rrqm/s wrqm/s r/s w/s rkB/s wkB/s avgrq-sz avgqu-sz await r_await w_await svctm %util 57# sdb 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 58# 59 60# Get the column names 61cols=$(echo "$out" | head -n 1) 62 63# Get the values and tab separate them to make them cut-able. 64vals=$(echo "$out" | tail -n 1 | sed -r 's/[[:blank:]]+/\t/g') 65 66i=0 67for col in $cols ; do 68 i=$((i+1)) 69 # Skip the first column since it's just the device name 70 if [ $i -eq 1 ]; then 71 continue 72 fi 73 74 # Get i'th value 75 val=$(echo "$vals" | cut -f "$i") 76 echo "$col=$val" 77done 78