Projet

Général

Profil

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

root / plugins / zfs / zpool_fragmentation @ db27ad45

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

1
#!/bin/bash
2
#%# family=auto
3

    
4
: << EOF
5
=head1 NAME
6

    
7
zpool_fragmentation - Outputs the zpool fragmentation per zfs pool.
8

    
9
=head1 AUTHOR
10

    
11
Michael Grote
12

    
13
=head1 LICENSE
14
GPLv3 or later
15

    
16
SPDX-License-Identifier: GPL-3.0-or-later
17

    
18
=head1 MAGIC MARKERS
19

    
20
 #%# family=auto
21

    
22
=cut
23

    
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
# lese alle pools, sed löscht die erste zeile
37
# entferne das %-zeichen
38
list=$(zpool list | sed 1d | tr -d %)
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
45
    echo "$line" | awk '{print $1".label " $1}'
46
    # setze warn-limits
47
    echo "$line" | awk '{print $1".warning " 50}'
48
    echo "$line" | awk '{print $1".critical " 75}'
49
  done <<< "$list"
50
  # setze optionen
51
  echo 'graph_title ZFS storage pool - fragmentation' # Titelzeile
52
  echo 'graph_vlabel fragmentation in %' # Text links, hochkant
53
  echo 'graph_category fs' # Kategorie
54
  echo 'graph_info This graph shows the ZFS Pool fragmentation.' # Text über Tabelle/Infos
55
  echo 'graph_args -l 0 --upper-limit 100' # wertebegrenzer 0-100
56
  exit 0
57
fi
58

    
59
# lese jede Zeile der Variable $list
60
# tue für jede Zeile
61
# "echo" die Zeile, wende awk drauf, Spalte $1/$7
62
while read -r line; do
63
  # gebe wert aus
64
  # <name>.value <wert>
65
  echo "$line" | awk '{print $1".value " $7}'
66
done <<< "$list"
67
exit 0