2021-09-16 19:58:32 +02:00
|
|
|
#!/bin/bash
|
|
|
|
#%# family=auto
|
|
|
|
#%# capabilities=autoconf
|
|
|
|
|
|
|
|
# Michael Grote
|
|
|
|
# michael.grote ät posteo.de
|
|
|
|
# Outputs the count of zfs pools, datasets and snapshots.
|
|
|
|
|
|
|
|
# lese alle pools, sed löscht die erste zeile
|
|
|
|
list_pools=$(zpool list | sed 1d)
|
|
|
|
|
|
|
|
# wenn parameter = ...
|
|
|
|
if [ "$1" = "autoconf" ]; then
|
|
|
|
echo yes
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$1" = "config" ]; then
|
|
|
|
# https://superuser.com/questions/284187/bash-iterating-over-lines-in-a-variable
|
|
|
|
while read -r line; do
|
|
|
|
# setze label <pool>.label <pool> snapshots
|
2021-09-29 14:04:15 +02:00
|
|
|
echo $line | awk '{print $1"_snapshot.label " $1 " snapshots"}'
|
|
|
|
echo $line | awk '{print $1"_dataset.label " $1 " datasets"}'
|
2021-09-16 19:58:32 +02:00
|
|
|
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
|