From 02630d318ce12da72631ebacd478e3e214e73d42 Mon Sep 17 00:00:00 2001 From: Michael Grote <38253905+quotengrote@users.noreply.github.com> Date: Sat, 13 Nov 2021 19:53:54 +0100 Subject: [PATCH] add zfs plugins (#1250) --- plugins/zfs/zfs_pool_dataset_count | 70 ++++++++++++++++++++++++++++++ plugins/zfs/zpool_fragmentation | 69 +++++++++++++++++++++++++++++ 2 files changed, 139 insertions(+) create mode 100644 plugins/zfs/zfs_pool_dataset_count create mode 100644 plugins/zfs/zpool_fragmentation diff --git a/plugins/zfs/zfs_pool_dataset_count b/plugins/zfs/zfs_pool_dataset_count new file mode 100644 index 00000000..3ef6bb4e --- /dev/null +++ b/plugins/zfs/zfs_pool_dataset_count @@ -0,0 +1,70 @@ +#!/bin/bash +#%# family=auto + +: << EOF +=head1 NAME +zfs_pool_dataset_count - Outputs the count of zfs pools, datasets and snapshots. + + +=head1 AUTHOR +=over 4 +=item * Michael Grote +=back + +=head1 LICENSE +GPLv3 or later + +SPDX-License-Identifier: GPL-3.0-or-later + +=head1 MAGIC MARKERS +=begin comment +These magic markers are used by munin-node-configure when installing +munin-node. +=end comment + #%# family=auto +=cut + +EOF + +if [ "$1" = "autoconf" ]; then + if ! command -v zpool &> /dev/null; then + echo "no (zpool could not be found)" + else + echo "yes" + fi + exit 0 +fi + + +# lese alle pools, sed löscht die erste zeile +list_pools=$(zpool list | sed 1d) + + +if [ "$1" = "config" ]; then + # https://superuser.com/questions/284187/bash-iterating-over-lines-in-a-variable + while read -r line; do + # setze label .label snapshots + echo "$line" | awk '{print $1"_snapshot.label " $1 " snapshots"}' + echo "$line" | awk '{print $1"_dataset.label " $1 " datasets"}' + done <<< "$list_pools" + echo 'pools.label pools' + # setze optionen + echo 'graph_title zfs - pool, dataset and snapshot count' # Titelzeile + echo 'graph_vlabel count' # Text links, hochkant + echo 'graph_category fs' # Kategorie + echo 'graph_args -l 0' # wertebegrenzer 0-100 + exit 0 +fi + +# lese jede Zeile der Variable $list +# tue für jede Zeile +# "echo" die Zeile, wende awk drauf, Spalte $1/$7 +while read -r line; do + echo pools.value "$(zpool list | sed 1d | wc -l)" + # setze poolnamen + poolname=$(echo "$line" | awk '{ print $1 }') + # zähle snapshots + echo "${poolname}_snapshot.value" "$(zfs list -r -t snapshot "$poolname" | sed 1d | wc -l)" + echo "$poolname""_dataset.value" "$(zfs list -r "$poolname" | sed 1d | wc -l)" +done <<< "$list_pools" +exit 0 diff --git a/plugins/zfs/zpool_fragmentation b/plugins/zfs/zpool_fragmentation new file mode 100644 index 00000000..7bf7900c --- /dev/null +++ b/plugins/zfs/zpool_fragmentation @@ -0,0 +1,69 @@ +#!/bin/bash +#%# family=auto + +: << EOF +=head1 NAME +zpool_fragmentation - Outputs the zpool fragmentation per zfs pool. + + +=head1 AUTHOR +=over 4 +=item * Michael Grote +=back + +=head1 LICENSE +GPLv3 or later + +SPDX-License-Identifier: GPL-3.0-or-later + +=head1 MAGIC MARKERS +=begin comment +These magic markers are used by munin-node-configure when installing +munin-node. +=end comment + #%# family=auto +=cut + +EOF + +if [ "$1" = "autoconf" ]; then + if ! command -v zpool &> /dev/null; then + echo "no (zpool could not be found!)" + else + echo "yes" + fi + exit 0 +fi + +# lese alle pools, sed löscht die erste zeile +# entferne das %-zeichen +list=$(zpool list | sed 1d | tr -d %) + + +if [ "$1" = "config" ]; then + # https://superuser.com/questions/284187/bash-iterating-over-lines-in-a-variable + while read -r line; do + # setze label + echo "$line" | awk '{print $1".label " $1}' + # setze warn-limits + echo "$line" | awk '{print $1".warning " 50}' + echo "$line" | awk '{print $1".critical " 75}' + done <<< "$list" + # setze optionen + echo 'graph_title ZFS storage pool - fragmentation' # Titelzeile + echo 'graph_vlabel fragmentation in %' # Text links, hochkant + echo 'graph_category fs' # Kategorie + echo 'graph_info This graph shows the ZFS Pool fragmentation.' # Text über Tabelle/Infos + echo 'graph_args -l 0 --upper-limit 100' # wertebegrenzer 0-100 + exit 0 +fi + +# lese jede Zeile der Variable $list +# tue für jede Zeile +# "echo" die Zeile, wende awk drauf, Spalte $1/$7 +while read -r line; do + # gebe wert aus + # .value + echo "$line" | awk '{print $1".value " $7}' +done <<< "$list" +exit 0