File: df.in

package info (click to toggle)
munin 2.0.76-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 7,064 kB
  • sloc: perl: 11,684; java: 1,924; sh: 1,632; makefile: 636; javascript: 365; python: 267
file content (78 lines) | stat: -rw-r--r-- 1,824 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!@@GOODSH@@
# -*- sh -*-

set -e

: << =cut

=head1 NAME

df - Script to monitor disk usage

=head1 CONFIGURATION

The following environment variables are used by this plugin:

 warning  - Warning percentage (Default: 92)
 critical - Critical percentage (Default: 98)

=head1 MAGIC MARKERS

 #%# family=auto
 #%# capabilities=autoconf

=cut

# shellcheck disable=SC1090
. "$MUNIN_LIBDIR/plugins/plugin.sh"


df_entries=$(df -P -l 2>/dev/null | sed -e '1d' -e '/\/\//d' -e 's/%//' | sort)


# Use the mountpoint instead of the device name for ambiguous virtual devices (tmpfs, ...).
get_unique_fieldname() {
    # do not use "local" - we want to be as portable, as possible
    this_device="$1"
    this_mountpoint="$2"
    case "$this_device" in
        tmpfs|none|udev|simfs)
            clean_fieldname "$this_mountpoint"
            ;;
        *)
            clean_fieldname "$this_device"
            ;;
    esac
}


if [ "$1" = "autoconf" ]; then
    if [ -z "$df_entries" ] ; then
        echo "no (no mounted filesystems found)"
    else
        echo yes
    fi
    exit 0
fi

if [ "$1" = "config" ]; then
    echo 'graph_title Disk usage in percent'
    echo 'graph_args --upper-limit 100 -l 0'
    echo 'graph_vlabel %'
    echo 'graph_category disk'
    echo 'graph_scale no'
    echo "$df_entries" | while read -r dev size used free pct fs; do
        name=$(get_unique_fieldname "$dev" "$fs")
        echo "$name.label $fs"
        print_warning "$name"
        print_critical "$name"
    done
    # exit now if the capability DIRTYCONFIG is missing or disabled
    if [ "${MUNIN_CAP_DIRTYCONFIG:-0}" != 1 ]; then exit 0; fi
fi

# output current values
# shellcheck disable=SC2034
echo "$df_entries" | while read -r dev size used free pct fs; do
     echo "$(get_unique_fieldname "$dev" "$fs").value $pct"
done