-
Notifications
You must be signed in to change notification settings - Fork 2
/
df_abs
executable file
·142 lines (133 loc) · 4 KB
/
df_abs
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/bin/sh
#
# Script to monitor absolute disk usage. The script is forked from the one shipped with
# some munin 1.2.x version because it continously showed some useless
# filesystems. This version is extended so it can exclude certain filesystems
# or devices.
#
# Parameters understood:
#
# config (required)
# autoconf (optional - used by munin-config)
#
# Configuration:
#
# This script supports four environment variables:
# EXCLUDE_FS - Exclude given filesystems
# (default: iso9660, udf and none.)
# EXCLUDE_DEVS - Exclude filesystems on given devices. This is useful
# to exclude pseudo filesystems like /dev or /proc.
# (default: "none" - which excludes most pseudo
# filesystems.)
# EXCLUDE_MOUNTS - Exclude given mountpoints (default:
# "^(/dev/shm|/sys/fs/cgroup)$").
# MOUNTPOINT_AS_LABEL - Filesystems where the mount point should be used as
# label (instead of the device path). Useful for pseudo-fileystems
# that don't have a real device (default: "^(udev|tmpfs)$").
# Note that setting any of these settings *overrides* the default values and
# does NOT *add* to them.
#
# Example configuration:
#
# The following example excludes XFS and JFS filesystems and any filesystems
# with device "none" or "/scratch":
#
# [df]
# env.EXCLUDE_FS=xfs jfs
# env.EXCLUDE_DEVS=none /scratch
#
# $Log$
#
# Revision 2.1.3 2016/07/31 17:56 Mathias Ertl <[email protected]>
# * Exclude any filesystem under /run.
#
# Revision 2.1.2 2016/07/08 18:04 Mathias Ertl <[email protected]>
# * Exclude /run/user/[0-9]+ tmpfs filesystems, their existance is dynamic
# and depends on who is currently logged in.
#
# Revision 2.1 2016/01/01 16:20 Mathias Ertl <[email protected]>
# * Added EXCLUDE_MOUNTS and MOUNTPOINT_AS_LABEL parameters.
# * Exclude devtmpfs (-> /dev) filesystems by default.
#
# Revision 2.0 2010-08-29 14:03:11 Mathias Ertl <[email protected]>
# Added EXLCUDE_FS and EXCLUDE_TYPE paramaters
#
# Revision 1.2.2.1 2005/02/16 22:50:14 jimmyo
# linux/df* now ignores bind mounts.
#
# Revision 1.2 2004/08/24 13:37:29 ilmari
# Add total line
#
# Revision 1.1 2004/08/24 12:26:48 ilmari
# Added plugin linux/df_abs
#
# Magic markers (optional - used by munin-config and installation
# scripts):
#
#%# family=auto
#%# capabilities=autoconf
if [ "$1" = "autoconf" ]; then
echo yes
exit 0
fi
[ -z $EXCLUDE_DEVS ] && EXCLUDE_DEVS="none"
[ -z $EXCLUDE_FS ] && EXCLUDE_FS="iso9660 udf none devtmpfs"
[ -z $EXCLUDE_MOUNTS ] && EXCLUDE_MOUNTS="^(/dev/shm|/sys/fs/cgroup|/run/?.*)$"
[ -z $MOUNTPOINT_AS_LABEL ] && MOUNTPOINT_AS_LABEL="^(udev|tmpfs)$"
DF_PARAMS='-T -P -l'
for fs in $EXCLUDE_FS; do
DF_PARAMS="$DF_PARAMS -x $fs"
done
clean_name() {
if [ "$(echo $1 | egrep -c "$MOUNTPOINT_AS_LABEL")" -eq "1" ]; then
echo $7 | sed 's/[\/.-]/_/g'
else
echo $1 | sed 's/[\/.-]/_/g'
fi
}
# Determine if a device should be excluded or not. Return 1 (true) if the device
# name is listed in EXCLUDE_DEVS or the mount point is listed in EXCLUDE_MOUNTS,
# 0 (false) otherwise.
exclude_dev() {
if [ "$(echo $EXCLUDE_DEVS | grep -c $1)" -eq "1" ]; then
return 1
else
if [ "$(echo $7 | egrep -c "$EXCLUDE_MOUNTS")" -eq "1" ]; then
return 1
fi
return 0
fi
}
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'
echo 'graph_total Total'
df $DF_PARAMS | sed 1d | while read i; do
exclude_dev $i
if [ "$?" -eq "1" ]; then
continue
fi
name=`clean_name $i`
echo -n "$name.label "
echo $i | awk "{
print \$7
print \"$name.info \" \$7 \" (\" \$2 \") -> \" \$1;
}"
echo "$name.cdef $name,1024,*"
size=`echo $i | awk '{print $3}'`
echo "$name.warning $((size / 100 * 92))"
echo "$name.critical $((size / 100 * 98))"
done
exit 0
fi
df $DF_PARAMS | sed 1d | while read i; do
exclude_dev $i
if [ "$?" -eq "1" ]; then
continue
fi
name=`clean_name $i`
echo -n "$name.value "
echo $i | awk '{ print $4 }'
done