Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / zfs / zfs_pool_dataset_count @ db27ad45

Historique | Voir | Annoter | Télécharger (1,6 ko)

1 02630d31 Michael Grote
#!/bin/bash
2
#%# family=auto
3
4
: << EOF
5
=head1 NAME
6
7 f63321c5 Michael Grote
zfs_pool_dataset_count - Outputs the count of zfs pools, datasets and snapshots.
8 02630d31 Michael Grote
9
=head1 AUTHOR
10 f63321c5 Michael Grote
11
Michael Grote
12 02630d31 Michael Grote
13
=head1 LICENSE
14 f63321c5 Michael Grote
15 02630d31 Michael Grote
GPLv3 or later
16
17
SPDX-License-Identifier: GPL-3.0-or-later
18
19
=head1 MAGIC MARKERS
20 f63321c5 Michael Grote
21
 #%# family=auto
22
23 02630d31 Michael Grote
=cut
24
25
EOF
26
27
if [ "$1" = "autoconf" ]; then
28
    if ! command -v zpool &> /dev/null; then
29
        echo "no (zpool could not be found)"
30
    else
31
        echo "yes"
32
    fi
33
    exit 0
34
fi
35
36
37
# lese alle pools, sed löscht die erste zeile
38
list_pools=$(zpool list | sed 1d)
39
40
41
if [ "$1" = "config" ]; then
42
  # https://superuser.com/questions/284187/bash-iterating-over-lines-in-a-variable
43
  while read -r line; do
44
    # setze label <pool>.label <pool> snapshots
45
    echo "$line" | awk '{print $1"_snapshot.label " $1 " snapshots"}'
46
    echo "$line" | awk '{print $1"_dataset.label " $1 " datasets"}'
47
  done <<< "$list_pools"
48
  echo 'pools.label pools'
49
  # setze optionen
50
  echo 'graph_title zfs -  pool, dataset and snapshot count' # Titelzeile
51
  echo 'graph_vlabel count' # Text links, hochkant
52
  echo 'graph_category fs' # Kategorie
53
  echo 'graph_args -l 0' # wertebegrenzer 0-100
54
  exit 0
55
fi
56
57
# lese jede Zeile der Variable $list
58
# tue für jede Zeile
59
# "echo" die Zeile, wende awk drauf, Spalte $1/$7
60
while read -r line; do
61
  echo pools.value "$(zpool list | sed 1d | wc -l)"
62
  # setze poolnamen
63
  poolname=$(echo "$line" | awk '{ print $1 }')
64
  # zähle snapshots
65
  echo "${poolname}_snapshot.value" "$(zfs list -r -t snapshot "$poolname" | sed 1d | wc -l)"
66
  echo "$poolname""_dataset.value" "$(zfs list -r "$poolname" | sed 1d | wc -l)"
67
done <<< "$list_pools"
68
exit 0