-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdf
executable file
·166 lines (157 loc) · 4.75 KB
/
df
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#!/bin/sh
#
# Script to monitor 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.5.2.4 2005/03/12 21:35:07 jimmyo
# Correct history loss in linux/{df,df_inode}.
#
# Revision 1.5.2.3 2005/03/10 10:04:48 jimmyo
# Fixed minor bug introduced with yesterdays change.
#
# Revision 1.5.2.2 2005/03/09 19:10:32 jimmyo
# Made linux/df work properly with tmpfs and devmapper (Deb#298442).
#
# Revision 1.5.2.1 2005/02/16 22:50:14 jimmyo
# linux/df* now ignores bind mounts.
#
# Revision 1.5 2004/12/09 20:27:45 jimmyo
# Sort fields in df*-plugins alphabetically.
#
# Revision 1.4 2004/09/25 22:29:16 jimmyo
# Added info fields to a bunch of plugins.
#
# Revision 1.3 2004/05/20 13:57:12 jimmyo
# Set categories to some of the plugins.
#
# Revision 1.2 2004/05/18 22:04:30 jimmyo
# Use "sed 1d" instead of "tail +2" in df plugins (patch by Olivier Delhomme).
#
# Revision 1.1 2004/01/02 18:50:01 jimmyo
# Renamed occurrances of lrrd -> munin
#
# Revision 1.1.1.1 2004/01/02 15:18:07 jimmyo
# Import of LRRD CVS tree after renaming to Munin
#
# Revision 1.2 2003/11/07 17:43:16 jimmyo
# Cleanups and log entries
#
#
#
# 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 %)'
echo 'graph_args --upper-limit 100 -l 0'
echo 'graph_vlabel %'
echo 'graph_category disk'
echo 'graph_info This graph shows disk usage on the machine.'
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.warning 92"
echo "$name.critical 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 $6 }' | cut -f1 -d%
done