Projet

Général

Profil

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

root / plugins / disk / quota2percent_ @ 6c7ad652

Historique | Voir | Annoter | Télécharger (8,01 ko)

1
#!/bin/bash
2
# -*- sh -*-
3
: <<=cut
4

    
5
=head1 NAME
6

    
7
quota2percent - Plugin to show disk usage in percent of quota hard limit.
8

    
9
=head1 APPLICABLE SYSTEMS
10

    
11
All systems with "bash", "quota", "repquota" and "munin"
12

    
13
Systems with multiple users and individual storage space limitations administered via 'quota'
14

    
15
=head1 CONFIGURATION
16

    
17
The following is the default configuration
18

    
19
  [quota2percent_*]
20
  user root
21

    
22
You could define two alert levels, the graph language, min. human UID and dealing with system users
23

    
24
  [quota2percent_*]
25
  env.warning   [value]        (default: 90)
26
  env.critical  [value]        (default: 95)
27
  env.language  [en|de|es]     (default: en)
28
  env.humanuid  [value]        (default: 1000, only need if there is an other value define for UID_MIN in /etc/login.defs)
29
  env.low_uid   [never|no|yes] (default: never)
30
                                set to no for producing rrd files for system user, but don't show those graphs (e.g. for later analyses)
31
                                if set to yes system user graphs are drawn
32

    
33
=head1 DESCRIPTION
34

    
35
Wild card Plugin for monitoring the utilization of devices with quota rules.
36
A graph is drawn for each user, which shows the usage as a percentage of his hard limit. System accounts (UID <1000) are suppressed.
37
In addition, a graph is displayed which indicates the ratio device size to device coverage.
38
The script repqutoa, usually part of the package quota, is needed.
39
The plugin itself can be stored in any directory. For example, the device sdb1 shell be monitored, a symbolic link must be created
40
in the /etc/munin/plugins/ directory as follows:
41

    
42
=over
43

    
44
I<<<  ln -s /<path to file>/quota2percent_  quota2percent_sdb1 >>>
45

    
46
=back
47

    
48
=head1 MAGIC MARKERS
49

    
50
  #%# family=auto
51
  #%# capabilities=autoconf
52

    
53
=head1 VERSION
54

    
55
17.0214
56

    
57
=head1 HISTORY
58

    
59
V17.0214
60

    
61
  fix    hard reading logic operation for skipping by Low_UID=never
62
  fix    some slips
63
  fix    some nitpicking details
64

    
65
  add    env.low_uid
66
  add    env.humanid
67
  add    env.language
68
  add    check if device exist
69
  add    if no limitations administered via 'quota' for the device the total line is shown only
70
  add    a few comments
71
  add    POD documentation
72
  add    example graph for Munin Plugin Gallery
73

    
74
  remove setting a PATH
75
  remove German comments
76

    
77
V17.0124
78

    
79
  not pubish, first version
80

    
81
=head1 AUTHOR
82

    
83
Jo Hartmann
84

    
85
=head1 LICENSE
86

    
87
GPLv2 (L<http://www.gnu.org/licenses/gpl-2.0.html>)
88

    
89
=cut
90

    
91
###################################################
92
# Autoconf section                                #
93
###################################################
94

    
95
  if [ "$1" = "autoconf" ]; then
96
     if ! repquota -V &> /dev/null ; then
97
        echo "no ('requota' executable is missing)"
98
        exit 0
99
     fi
100

    
101
     if ! df "/dev/${0##*_}" &> /dev/null; then
102
        echo "no (device /dev/${0##*_} does not exist!)"
103
        exit 0
104
     fi
105

    
106
     echo yes
107
     exit 0
108
  fi
109

    
110
###################################################
111
# Preparation section                             #
112
###################################################
113

    
114
# Load munin's shell library
115
  . "$MUNIN_LIBDIR/plugins/plugin.sh"
116

    
117
# if any fetch from munin-node file
118
     Warning=${warning:-90}
119
     Critical=${critical:-95}
120
     Language=${language:-en}
121
     Min_UID=${humanuid:-1000}
122
     Low_UID=${low_uid:-never}
123

    
124
# Checking if repquota installed and on the path
125
  if ! repquota -V &> /dev/null ; then
126
     echo "The script 'repquota' is not installed or on the path" >&2
127
     # Send the exit code FATAL ERROR happens
128
     exit 127
129
  fi
130

    
131
# get tehe wild card text
132
  Id=${0##*_}
133

    
134
# Check if device exist
135
  if ! df "/dev/$Id" &> /dev/null; then
136
     echo "The device /dev/$Id does not exist!" >&2
137
     exit 128
138
  fi
139

    
140
###################################################
141
# Data reading sections                           #
142
###################################################
143

    
144
# Reading the quotes for the selected device, using repquota
145
  if repquota "/dev/$Id" &> /dev/null; then
146
     readarray Quotas < <( repquota "/dev/$Id" | grep " -- " )
147
  else
148
     echo "No limitations administered via 'quota' for $Id" >&2
149

    
150
   # If no limitatitons administered: create a dummy for regarding
151
   # the avoidance of a divide-by-zero error
152
     Quotas[0]="root -- 1 1 1 1 1 1"
153

    
154
   # no rrd file need
155
     Low_UID="never"
156
  fi
157

    
158
  readarray Totals < <( df "/dev/$Id" )
159

    
160
# Get the count of Users
161
   Users=${#Quotas[@]}
162

    
163

    
164
###################################################
165
# Munin Configuration Section                     #
166
###################################################
167

    
168
  if [ "$1" = "config" ]; then
169

    
170
     # Localisation of the graphic texts
171
     case $Language in
172
          de)
173
            echo "graph_title    Quota-Hard-Limit von $Id"
174
            echo "graph_vlabel   Nutzung in % Hardlimit"
175
            echo "graph_info     Die Grafik zeigt die Belegung des durch Quota reglementierten Speicherplatzes für all regulären Nutzer (UID >= $Min_UID) in Prozent des Hardlimits."
176
            Total_txt="Su. aller Nutzer"
177
            Total_info="Inklusive Systemnutzer (UID < $Min_UID)"
178
            ;;
179
          es)
180
            echo "graph_title    Cuota de límite absoluto de $Id"
181
            echo "graph_vlabel   el % de uso del límite duro"
182
            echo "graph_info     El gráfico muestra la disponibilidad de espacio regulado por cuotas para todos los usuarios regulares (UID >= $Min_UID) como porcentaje de límites duros."
183
            Total_txt="Suma de todos los usuarios "
184
            Total_info="La inclusión de usuario del sistema (UID < $Min_UID) "
185
            ;;
186
           *)
187
            echo "graph_title    quota hard limit of $Id"
188
            echo "graph_vlabel   Usage in %"
189
            echo "graph_info     The graphic shows the allocation of the quota-regulated storage space for all regular users (UID >= $Min_UID) as a percentage of the hard limit ."
190
            Total_txt="all users"
191
            Total_info="system users (UID < $Min_UID) included"
192
            ;;
193
     esac
194

    
195
     # Defaults configuration
196
       echo "graph_category disk"
197
       echo "graph_args     --lower-limit 0 --upper-limit 100"
198
       echo "graph_printf   %5.2lf %%"
199
       echo "graph_scale    no"
200

    
201
     # Processing the individual user
202
       for((i=0; i<"$Users"; i++));do
203
         Quota=( ${Quotas[$i]} )
204
         User=${Quota[0]}
205
       # solve the root problem
206
         Fieldname="$(clean_fieldname "$User")"
207

    
208
       # Determine the currently processing UID
209
         Cur_UID="$(id -u "$User")"
210

    
211
       # skip if actual user a system user und low_uid is set to never
212
         [ "$Cur_UID" -lt "$Min_UID" ] && [ "$Low_UID" = "never" ] && continue
213

    
214
       # No graph for none human uid if low_uid is set to no
215
         [ "$Cur_UID" -lt "$Min_UID" ] && echo "$Fieldname.graph    $Low_UID"
216

    
217
       # configure the user lines
218
         echo "$Fieldname.label    $User"
219
         echo "$Fieldname.warning  $Warning"
220
         echo "$Fieldname.critical $Critical"
221

    
222
       done
223

    
224
     # configure the total line and send exit code NO ERROR happens
225
       echo "total.label    $Total_txt"
226
       echo "total.warning  $Warning"
227
       echo "total.critical $Critical"
228
       echo "total.info     $Total_info"
229
       exit 0
230
  fi
231

    
232
###################################################
233
# Munin value section                             #
234
###################################################
235

    
236
# fetch the needed values (used and hard limit) for each user, work around the root problem, calculate the percent value
237
  for((i=0; i<"$Users"; i++));do
238
    Quota=( ${Quotas[$i]} )
239
    Fieldname="$(clean_fieldname "${Quota[0]}")"
240

    
241
  # skip if actual user a system user und low_uid is set to never
242
    [ "$Cur_UID" -lt "$Min_UID" ] && [ "$Low_UID" = "never" ] && continue
243

    
244
  # write the result zu munin
245
    echo "${Quota[2]} ${Quota[4]} $Fieldname.value" | awk '{printf "%s %f\n",$3,$1*100/$2}'
246

    
247
  done
248

    
249
# the value for the total line
250
  Total=( ${Totals[1]} )
251
  echo "${Total[2]} ${Total[1]} total.value" | awk '{printf "%s %f\n",$3,$1*100/$2}'
252

    
253
# send the exit code NO ERROR happens
254
  exit 0
255

    
256
###################################################
257
# Script end                                      #
258
###################################################