File: df_abs.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 (107 lines) | stat: -rw-r--r-- 2,031 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!@@BASH@@
# -*- sh -*-

: <<EOF

=head1 NAME

df_abs - Plugin to monitor absolute disk usage

=head1 CONFIGURATION

The following configuration parameters are used by this plugin

 [df_abs]
  env.exclude  - space separated list of file system types to exclude
  env.warning  - Warning percentage
  env.critical - Critical percentage
  env.total    - Enable/Disable graph total [on|off]

=head2 DEFAULT CONFIGURATION

 [df_abs]
  env.exclude  iso9660
  env.warning  92
  env.critical 98
  env.total    on

=head1 AUTHORS

Unknown author

=head1 LICENSE

GPLv2

=head1 BUGS

Does not handle cases where the block device is the same
for multiple mounts.

=head1 MAGIC MARKERS

 #%# family=manual
 #%# capabilities=autoconf

=cut

EOF

. "$MUNIN_LIBDIR/plugins/plugin.sh"

if [ "$1" = "autoconf" ]; then
	echo yes
	exit 0
fi

# Append $mnt in case $dev is not a real block device
get_fieldname() {
	local dev="$1"
	local mnt="$2"
	case "$dev" in
		/* )
			clean_fieldname "$dev"
			;;
		* )
			clean_fieldname "$dev $mnt"
			;;
	esac
}

total=${total:-on}

exclude=${exclude:-iso9660}
exclude=$(echo "$exclude" | sed -r -e 's/ +/ -x /g' -e 's/^/-x /')

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

	echo 'graph_title Filesystem usage (in bytes)'
	echo 'graph_args --base 1024 --lower-limit 0'
	echo 'graph_vlabel bytes'
	echo 'graph_category disk'
	if [ "$total" = "on" ]; then
		echo 'graph_total Total'
	fi
	# shellcheck disable=SC2086
	df -P -l $exclude | sed 1d | grep -v "//" |
	while read -r dev size used avail cap mnt; do
		name="$(get_fieldname "$dev" "$mnt")"
		echo "$name.label $mnt"
		echo "$name.cdef $name,1024,*"
		warn=$(get_warning "$name")
		crit=$(get_critical "$name")
		if [ -n "$warn" ]; then
			echo "$name.warning $((size * warn / 100))"
		fi
		if [ -n "$crit" ]; then
			echo "$name.critical $((size * crit / 100))"
		fi
	done
	exit 0
fi

# shellcheck disable=SC2034,SC2086
df -P -l $exclude | sed 1d | grep -v "//" |
	while read -r dev size used avail cap mnt; do
		echo "$(get_fieldname "$dev" "$mnt").value $used"
	done