Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom column names and scripts for zpool status/iostat -c #5852

Merged
merged 1 commit into from
Apr 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ shellcheck:
scripts/zfs-tests.sh \
scripts/zfs.sh \
scripts/commitcheck.sh \
$$(find cmd/zed/zed.d/*.sh -type f); \
$$(find cmd/zed/zed.d/*.sh -type f) \
$$(find cmd/zpool/zpool.d/* -executable); \
fi

lint: cppcheck paxcheck
Expand Down
51 changes: 51 additions & 0 deletions cmd/zpool/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,54 @@ zpool_LDADD = \
$(top_builddir)/lib/libzfs/libzfs.la \
$(top_builddir)/lib/libzfs_core/libzfs_core.la \
-lm $(LIBBLKID)

zpoolconfdir = $(sysconfdir)/zfs/zpool.d
zpoolexecdir = $(libexecdir)/zfs/zpool.d

EXTRA_DIST = zpool.d/README

dist_zpoolexec_SCRIPTS = \
zpool.d/enc \
zpool.d/encdev \
zpool.d/fault_led \
zpool.d/iostat \
zpool.d/iostat-1s \
zpool.d/iostat-10s \
zpool.d/label \
zpool.d/locate_led \
zpool.d/lsblk \
zpool.d/model \
zpool.d/serial \
zpool.d/ses \
zpool.d/size \
zpool.d/slaves \
zpool.d/slot \
zpool.d/upath \
zpool.d/vendor

zpoolconfdefaults = \
enc \
encdev \
fault_led \
iostat \
iostat-1s \
iostat-10s \
label \
locate_led \
lsblk \
model \
serial \
ses \
size \
slaves \
slot \
upath \
vendor

install-data-hook:
$(MKDIR_P) "$(DESTDIR)$(zpoolconfdir)"
for f in $(zpoolconfdefaults); do \
test -f "$(DESTDIR)$(zpoolconfdir)/$${f}" -o \
-L "$(DESTDIR)$(zpoolconfdir)/$${f}" || \
ln -s "$(zpoolexecdir)/$${f}" "$(DESTDIR)$(zpoolconfdir)"; \
done
9 changes: 9 additions & 0 deletions cmd/zpool/zpool.d/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
This directory contains scripts that can be run the zpool status/iostat
-c option:

zpool status -c script1,script2, ...

zpool iostat -vc script1,script2, ...

Some scripts output different values depending on the symlink name that is
used to run them. See the zpool(8) man page for more details.
1 change: 1 addition & 0 deletions cmd/zpool/zpool.d/enc
1 change: 1 addition & 0 deletions cmd/zpool/zpool.d/encdev
1 change: 1 addition & 0 deletions cmd/zpool/zpool.d/fault_led
65 changes: 65 additions & 0 deletions cmd/zpool/zpool.d/iostat
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/bin/sh
#
# Display most relevant iostat bandwidth/latency numbers. The output is
# dependent on the name of the script/symlink used to call it.
#

helpstr="
iostat: Show iostat values since boot (summary page).
iostat-1s: Do a single 1-second iostat sample and show values.
iostat-10s: Do a single 10-second iostat sample and show values."

script=$(basename "$0")
if [ "$1" = "-h" ] ; then
echo "$helpstr" | grep "$script:" | tr -s '\t' | cut -f 2-
exit
fi

if [ "$script" = "iostat-1s" ] ; then
# Do a single one-second sample
extra="1 1"
# Don't show summary stats
y="-y"
elif [ "$script" = "iostat-10s" ] ; then
# Do a single ten-second sample
extra="10 1"
# Don't show summary stats
y="-y"
fi

if [ -f "$VDEV_UPATH" ] ; then
# We're a file-based vdev, iostat doesn't work on us. Do nothing.
exit
fi

out=$(eval "iostat $y -k -x $VDEV_UPATH $extra")

# Sample output (we want the last two lines):
#
# Linux 2.6.32-642.13.1.el6.x86_64 (centos68) 03/09/2017 _x86_64_ (6 CPU)
#
# avg-cpu: %user %nice %system %iowait %steal %idle
# 0.00 0.00 0.00 0.00 0.00 100.00
#
# Device: rrqm/s wrqm/s r/s w/s rkB/s wkB/s avgrq-sz avgqu-sz await r_await w_await svctm %util
# 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
#

# Get the column names
cols=$(echo "$out" | grep Device)

# Get the values and tab separate them to make them cut-able.
vals="$(echo "$out" | grep -A1 Device | tail -n 1 | sed -r 's/[[:blank:]]+/\t/g')"

i=0
for col in $cols ; do
i=$((i+1))
# Skip the first column since it's just the device name
if [ "$col" = "Device:" ] ; then
continue
fi

# Get i'th value
val=$(echo "$vals" | cut -f "$i")
echo "$col=$val"
done
1 change: 1 addition & 0 deletions cmd/zpool/zpool.d/iostat-10s
1 change: 1 addition & 0 deletions cmd/zpool/zpool.d/iostat-1s
1 change: 1 addition & 0 deletions cmd/zpool/zpool.d/label
1 change: 1 addition & 0 deletions cmd/zpool/zpool.d/locate_led
84 changes: 84 additions & 0 deletions cmd/zpool/zpool.d/lsblk
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#!/bin/sh
#
# Print some common lsblk values
#
# Any (lowercased) name symlinked to the lsblk script will be passed to lsblk
# as one of its --output names. Here's a partial list of --output names
# from the lsblk binary:
#
# Available columns (for --output):
# NAME device name
# KNAME internal kernel device name
# MAJ:MIN major:minor device number
# FSTYPE filesystem type
# MOUNTPOINT where the device is mounted
# LABEL filesystem LABEL
# UUID filesystem UUID
# RA read-ahead of the device
# RO read-only device
# RM removable device
# MODEL device identifier
# SIZE size of the device
# STATE state of the device
# OWNER user name
# GROUP group name
# MODE device node permissions
# ALIGNMENT alignment offset
# MIN-IO minimum I/O size
# OPT-IO optimal I/O size
# PHY-SEC physical sector size
# LOG-SEC logical sector size
# ROTA rotational device
# SCHED I/O scheduler name
# RQ-SIZE request queue size
# TYPE device type
# DISC-ALN discard alignment offset
# DISC-GRAN discard granularity
# DISC-MAX discard max bytes
# DISC-ZERO discard zeroes data
#
# If the script is run as just 'lsblk' then print out disk size, vendor,
# model number and serial number.


helpstr="
label: Show filesystem label.
model: Show disk model number.
serial: Show disk serial number.
size: Show the disk capacity.
vendor: Show the disk vendor.
lsblk: Show the disk size, vendor, model number, and serial number."

script=$(basename "$0")

if [ "$1" = "-h" ] ; then
echo "$helpstr" | grep "$script:" | tr -s '\t' | cut -f 2-
exit
fi

if [ "$script" = "lsblk" ] ; then
list="size vendor model serial"
else
list=$(echo "$script" | tr '[:upper:]' '[:lower:]')
fi

# Older versions of lsblk don't support all these values (like SERIAL).
for i in $list ; do

# Special case: Looking up the size of a file-based vdev can't
# be done with lsblk.
if [ "$i" = "size" ] && [ -f "$VDEV_UPATH" ] ; then
size="$(du -h --apparent-size $VDEV_UPATH | cut -f 1)"
echo "size=$size"
continue
fi


val=""
if val=$(eval "lsblk -dl -n -o $i $VDEV_UPATH 2>/dev/null") ; then
# Remove leading/trailing whitespace from value
val=$(echo "$val" | sed -e 's/^[[:space:]]*//' \
-e 's/[[:space:]]*$//')
fi
echo "$i=$val"
done
1 change: 1 addition & 0 deletions cmd/zpool/zpool.d/model
1 change: 1 addition & 0 deletions cmd/zpool/zpool.d/serial
52 changes: 52 additions & 0 deletions cmd/zpool/zpool.d/ses
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/sh
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: You'll want to add an empty line here for consistency with the other scripts.

#
# Print SCSI Enclosure Services (SES) info. The output is dependent on the name
# of the script/symlink used to call it.
#
helpstr="
enc: Show disk enclosure w:x:y:z value.
slot: Show disk slot number as reported by the enclosure.
encdev: Show the /dev/sg* device for the enclosure associated with the disk slot.
fault_led: Show the value of the disk enclosure slot fault LED.
locate_led: Show the value of the disk enclosure slot locate LED.
ses: Show disk's enclosure, enclosure dev, slot number, and fault/locate LED values."

script=$(basename "$0")
if [ "$1" = "-h" ] ; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related to the nit: about helpstr, would it be worth making a helper function and placing it in a lib style shell script? You can then define helpstr in each script and simply call a handle_helpstr function of some sort.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, nevermind. I don't see any other things that you could pull into a lib style shell script. Just ignore this.

echo "$helpstr" | grep "$script:" | tr -s '\t' | cut -f 2-
exit
fi

if [ "$script" = "ses" ] ; then
scripts='enc encdev slot fault_led locate_led'
else
scripts="$script"
fi

for i in $scripts ; do
if [ -z "$VDEV_ENC_SYSFS_PATH" ] ; then
echo "$i="
continue
fi

val=""
case $i in
enc)
val=$(ls "$VDEV_ENC_SYSFS_PATH/../../" 2>/dev/null)
;;
slot)
val=$(cat "$VDEV_ENC_SYSFS_PATH/slot" 2>/dev/null)
;;
encdev)
val=$(ls "$VDEV_ENC_SYSFS_PATH/../device/scsi_generic" 2>/dev/null)
;;
fault_led)
val=$(cat "$VDEV_ENC_SYSFS_PATH/fault" 2>/dev/null)
;;
locate_led)
val=$(cat "$VDEV_ENC_SYSFS_PATH/locate" 2>/dev/null)
;;
esac
echo "$i=$val"
done

1 change: 1 addition & 0 deletions cmd/zpool/zpool.d/size
32 changes: 32 additions & 0 deletions cmd/zpool/zpool.d/slaves
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/sh
#
# Show device mapper slave devices. This is useful for looking up the
# /dev/sd* devices associated with a dm or multipath device. For example:
#
# $ ls /sys/block/dm-113/slaves/
# sddt sdjw
#

if [ "$1" = "-h" ] ; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: you should be consistent with your helpstr format all the way through these scripts.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I just realized what you were doing in all the other scripts... and it's really clever. It's still a nit in the sense that you have a helpstr in most of the other scripts. But, I'm not so bothered by this anymore. Feel free to ignore the nits related to this.

echo "Show device mapper slave devices."
exit
fi

dev="$VDEV_PATH"

# If the VDEV path is a symlink, resolve it to a real device
if [ -L "$dev" ] ; then
dev=$(readlink "$dev")
fi

dev=$(basename "$dev")
val=""
if [ -d "/sys/class/block/$dev/slaves" ] ; then
# ls -C: output in columns, no newlines
val=$(ls -C "/sys/class/block/$dev/slaves")

# ls -C will print two spaces between files; change to one space.
val=$(echo "$val" | sed -r 's/[[:blank:]]+/ /g')
fi

echo "slaves=$val"
1 change: 1 addition & 0 deletions cmd/zpool/zpool.d/slot
7 changes: 7 additions & 0 deletions cmd/zpool/zpool.d/upath
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh
if [ "$1" = "-h" ] ; then
echo "Show the underlying path for a device."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: ditto 'helpstr` format.

exit
fi

echo upath="$VDEV_UPATH"
1 change: 1 addition & 0 deletions cmd/zpool/zpool.d/vendor
Loading