2017-02-11 11:49:13 +01:00
#!/bin/bash
# -*- sh -*-
: <<=cut
=head1 NAME
quota2percent - Plugin to show disk usage in percent of quota hard limit.
=head1 APPLICABLE SYSTEMS
All systems with "bash", "quota", "repquota" and "munin"
2017-02-13 18:52:37 +01:00
2017-02-11 11:49:13 +01:00
Systems with multiple users and individual storage space limitations administered via 'quota'
=head1 CONFIGURATION
The following is the default configuration
[quota2percent_*]
user root
2017-02-14 14:57:46 +01:00
You could define two alert levels, the graph language, min. human UID and dealing with system users
2017-02-11 11:49:13 +01:00
[quota2percent_*]
env.warning [value] (default: 90)
env.critical [value] (default: 95)
env.language [en|de|es] (default: en)
env.humanuid [value] (default: 1000, only need if there is an other value define for UID_MIN in /etc/login.defs)
2017-02-13 18:52:37 +01:00
env.low_uid [never|no|yes] (default: never)
set to no for producing rrd files for system user, but don't show those graphs (e.g. for later analyses)
2018-08-02 02:03:42 +02:00
if set to yes system user graphs are drawn
2017-02-11 11:49:13 +01:00
=head1 DESCRIPTION
2018-08-02 02:03:42 +02:00
Wild card Plugin for monitoring the utilization of devices with quota rules.
A graph is drawn for each user, which shows the usage as a percentage of his hard limit. System accounts (UID <1000) are suppressed.
In addition, a graph is displayed which indicates the ratio device size to device coverage.
The script repqutoa, usually part of the package quota, is needed.
2017-02-11 11:49:13 +01:00
The plugin itself can be stored in any directory. For example, the device sdb1 shell be monitored, a symbolic link must be created
2018-08-02 02:03:42 +02:00
in the /etc/munin/plugins/ directory as follows:
2017-02-11 11:49:13 +01:00
2018-08-02 02:03:42 +02:00
=over
2017-02-11 11:49:13 +01:00
I<<< ln -s /<path to file>/quota2percent_ quota2percent_sdb1 >>>
=back
=head1 MAGIC MARKERS
#%# family=auto
#%# capabilities=autoconf
=head1 VERSION
2017-02-14 14:57:46 +01:00
17.0214
2017-02-11 11:49:13 +01:00
=head1 HISTORY
2017-02-14 14:57:46 +01:00
V17.0214
2017-02-12 17:56:49 +01:00
2017-02-14 14:57:46 +01:00
fix hard reading logic operation for skipping by Low_UID=never
2017-02-12 17:56:49 +01:00
fix some slips
2017-02-14 14:57:46 +01:00
fix some nitpicking details
2017-02-11 11:49:13 +01:00
2017-02-14 14:57:46 +01:00
add env.low_uid
2017-02-11 11:49:13 +01:00
add env.humanid
2017-02-14 14:57:46 +01:00
add env.language
2017-02-11 11:49:13 +01:00
add check if device exist
add if no limitations administered via 'quota' for the device the total line is shown only
2017-02-14 14:57:46 +01:00
add a few comments
2017-02-11 11:49:13 +01:00
add POD documentation
add example graph for Munin Plugin Gallery
2017-02-14 14:57:46 +01:00
remove setting a PATH
2018-08-02 02:03:42 +02:00
remove German comments
2017-02-11 11:49:13 +01:00
V17.0124
2017-02-14 14:57:46 +01:00
not pubish, first version
2017-02-11 11:49:13 +01:00
=head1 AUTHOR
Jo Hartmann
=head1 LICENSE
2018-08-02 02:03:42 +02:00
2017-02-11 11:49:13 +01:00
GPLv2 (L<http://www.gnu.org/licenses/gpl-2.0.html>)
=cut
###################################################
# Autoconf section #
###################################################
if [ "$1" = "autoconf" ]; then
if ! repquota -V &> /dev/null ; then
echo "no ('requota' executable is missing)"
2017-02-12 17:56:49 +01:00
exit 0
2017-02-11 11:49:13 +01:00
fi
if ! df "/dev/${0##*_}" &> /dev/null; then
2017-02-12 17:56:49 +01:00
echo "no (device /dev/${0##*_} does not exist!)"
exit 0
2017-02-11 11:49:13 +01:00
fi
echo yes
exit 0
fi
###################################################
# Preparation section #
###################################################
# Load munin's shell libary
. "$MUNIN_LIBDIR/plugins/plugin.sh"
# if any fetch from munin-node file
Warning=${warning:-90}
Critical=${critical:-95}
Language=${language:-en}
Min_UID=${humanuid:-1000}
2017-02-13 18:52:37 +01:00
Low_UID=${low_uid:-never}
2017-02-11 11:49:13 +01:00
# Checking if repquota installed and on the path
if ! repquota -V &> /dev/null ; then
echo "The script 'repquota' is not installed or on the path" >&2
# Send the exit code FATAL ERROR happens
exit 127
fi
# get tehe wild card text
Id=${0##*_}
# Check if device exist
if ! df "/dev/$Id" &> /dev/null; then
echo "The device /dev/$Id does not exist!" >&2
exit 128
fi
###################################################
# Data reading sections #
###################################################
# Reading the quotes for the selected device, using repquota
2018-08-02 02:03:42 +02:00
if repquota "/dev/$Id" &> /dev/null; then
2017-02-11 11:49:13 +01:00
readarray Quotas < <( repquota "/dev/$Id" | grep " -- " )
else
echo "No limitations administered via 'quota' for $Id" >&2
2017-02-14 14:57:46 +01:00
# If no limitatitons administered: create a dummy for regarding
# the avoidance of a divide-by-zero error
2017-02-11 11:49:13 +01:00
Quotas[0]="root -- 1 1 1 1 1 1"
2017-02-14 14:57:46 +01:00
2018-08-02 02:03:42 +02:00
# no rrd file need
2017-02-13 18:52:37 +01:00
Low_UID="never"
2017-02-11 11:49:13 +01:00
fi
readarray Totals < <( df "/dev/$Id" )
2018-08-02 02:03:42 +02:00
# Get the count of Users
2017-02-11 11:49:13 +01:00
Users=${#Quotas[@]}
###################################################
# Munin Configuration Section #
###################################################
if [ "$1" = "config" ]; then
2018-08-02 02:03:42 +02:00
# Localisation of the graphic texts
2017-02-11 11:49:13 +01:00
case $Language in
de)
2017-02-13 18:52:37 +01:00
echo "graph_title Quota-Hard-Limit von $Id"
echo "graph_vlabel Nutzung in % Hardlimit"
2017-02-14 14:57:46 +01:00
echo "graph_info Die Grafik zeigt die Belegung des durch Quota reglementierten Speicherplatzes für alle regulären Nutzer (UID >= $Min_UID) in Prozent des Hardlimits."
2017-02-11 11:49:13 +01:00
Total_txt="Su. aller Nutzer"
Total_info="Inklusive Systemnutzer (UID < $Min_UID)"
;;
2018-08-02 02:03:42 +02:00
es)
echo "graph_title Cuota de límite absoluto de $Id"
echo "graph_vlabel el % de uso del límite duro"
2017-02-14 14:57:46 +01:00
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."
2017-02-11 11:49:13 +01:00
Total_txt="Suma de todos los usuarios "
2017-02-14 14:57:46 +01:00
Total_info="La inclusión de usuario del sistema (UID < $Min_UID) "
2017-02-11 11:49:13 +01:00
;;
*)
2017-02-13 18:52:37 +01:00
echo "graph_title quota hard limit of $Id"
echo "graph_vlabel Usage in %"
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 ."
2017-02-11 11:49:13 +01:00
Total_txt="all users"
2018-08-02 02:03:42 +02:00
Total_info="system users (UID < $Min_UID) included"
2017-02-11 11:49:13 +01:00
;;
esac
2018-08-02 02:03:42 +02:00
# Defaults configuration
2017-02-13 18:52:37 +01:00
echo "graph_category disk"
echo "graph_args --lower-limit 0 --upper-limit 100"
echo "graph_printf %5.2lf %%"
echo "graph_scale no"
2017-02-11 11:49:13 +01:00
2017-02-13 18:52:37 +01:00
# Processing the individual user
2017-02-11 11:49:13 +01:00
for((i=0; i<"$Users"; i++));do
Quota=( ${Quotas[$i]} )
2017-02-13 18:52:37 +01:00
User=${Quota[0]}
# solve the root problem
Fieldname="$(clean_fieldname "$User")"
2017-02-11 11:49:13 +01:00
2017-02-13 18:52:37 +01:00
# Determine the currently processing UID
Cur_UID="$(id -u "$User")"
2017-02-11 11:49:13 +01:00
2018-08-02 02:03:42 +02:00
# skip if actual user a system user und low_uid ist set to never
2017-02-14 14:57:46 +01:00
[ "$Cur_UID" -lt "$Min_UID" ] && [ "$Low_UID" = "never" ] && continue
2018-08-02 02:03:42 +02:00
2017-02-14 14:57:46 +01:00
# No graph for none human uid if low_uid ist set to no
[ "$Cur_UID" -lt "$Min_UID" ] && echo "$Fieldname.graph $Low_UID"
2017-02-11 11:49:13 +01:00
2017-02-14 14:57:46 +01:00
# configure the user lines
echo "$Fieldname.label $User"
echo "$Fieldname.warning $Warning"
echo "$Fieldname.critical $Critical"
2018-08-02 02:03:42 +02:00
2017-02-11 11:49:13 +01:00
done
# configure the total line and send exit code NO ERROR happens
2017-02-13 18:52:37 +01:00
echo "total.label $Total_txt"
echo "total.warning $Warning"
echo "total.critical $Critical"
echo "total.info $Total_info"
2017-02-11 11:49:13 +01:00
exit 0
fi
###################################################
# Munin value section #
###################################################
# fetch the needed values (used and hard limit) for each user, work around the root problem, calculate the percent value
for((i=0; i<"$Users"; i++));do
Quota=( ${Quotas[$i]} )
2017-02-13 18:52:37 +01:00
Fieldname="$(clean_fieldname "${Quota[0]}")"
2018-08-02 02:03:42 +02:00
# skip if actual user a system user und low_uid ist set to never
2017-02-14 14:57:46 +01:00
[ "$Cur_UID" -lt "$Min_UID" ] && [ "$Low_UID" = "never" ] && continue
2018-08-02 02:03:42 +02:00
# write the result zu munin
2017-02-14 14:57:46 +01:00
echo "${Quota[2]} ${Quota[4]} $Fieldname.value" | awk '{printf "%s %f\n",$3,$1*100/$2}'
2017-02-13 18:52:37 +01:00
2017-02-11 11:49:13 +01:00
done
2018-08-02 02:03:42 +02:00
# the value for the total line
2017-02-11 11:49:13 +01:00
Total=( ${Totals[1]} )
echo "${Total[2]} ${Total[1]} total.value" | awk '{printf "%s %f\n",$3,$1*100/$2}'
# send the exit code NO ERROR happens
exit 0
###################################################
# Script end #
###################################################