2016-10-29 08:43:40 +02:00
|
|
|
#!/bin/sh
|
2016-09-03 13:04:25 +02:00
|
|
|
|
|
|
|
: << =cut
|
|
|
|
|
|
|
|
=head1 NAME
|
|
|
|
|
|
|
|
file_length_ - Plugin to monitor the length of specified files
|
|
|
|
|
|
|
|
Useful for things such as lists (white, black, user, ...).
|
|
|
|
|
|
|
|
=head1 CONFIGURATION
|
|
|
|
|
|
|
|
[file_length_IDENTIFIER]
|
|
|
|
env.files FILEPATHGLOB1 FILEPATHGLOB2 ...
|
|
|
|
env.category DEFAULTS_TO_system
|
|
|
|
env.title OPTIONAL_TITLE
|
2016-09-04 06:15:20 +02:00
|
|
|
env.logarithmic 1
|
2016-09-03 13:04:25 +02:00
|
|
|
|
|
|
|
=head1 AUTHOR
|
|
|
|
|
2016-10-29 08:43:40 +02:00
|
|
|
Olivier Mehani <shtrom+munin@ssji.net> (based on disk/log_sizes)
|
2016-09-03 13:04:25 +02:00
|
|
|
|
|
|
|
=head1 LICENSE
|
|
|
|
|
|
|
|
GPLv2
|
|
|
|
|
2016-10-29 08:43:40 +02:00
|
|
|
=head1 MAGIC MARKERS
|
|
|
|
|
|
|
|
#%# family=manual
|
|
|
|
|
2016-09-03 13:04:25 +02:00
|
|
|
=cut
|
|
|
|
|
2016-10-29 08:43:40 +02:00
|
|
|
# needs shellcheck -x /usr/share/munin/plugins/plugin.sh
|
|
|
|
# shellcheck source=/usr/share/munin/plugins/plugin.sh
|
|
|
|
. "$MUNIN_LIBDIR/plugins/plugin.sh"
|
|
|
|
|
|
|
|
NAME=$(echo "$0" | sed 's/.*_//')
|
2016-09-03 13:04:25 +02:00
|
|
|
TITLE=${title:-File lengths for $NAME}
|
|
|
|
CATEGORY=${category:-system}
|
|
|
|
|
|
|
|
FILES=${files:-/var/log/messages}
|
2016-10-29 08:43:40 +02:00
|
|
|
# we want globbing to happen here
|
|
|
|
# shellcheck disable=SC2116 disable=SC2086
|
|
|
|
FILES=$(echo $FILES)
|
2016-09-03 13:04:25 +02:00
|
|
|
|
2016-09-04 06:15:20 +02:00
|
|
|
|
2016-09-03 13:04:25 +02:00
|
|
|
if [ "$1" = "config" ] ; then
|
2016-10-29 08:43:40 +02:00
|
|
|
# shellcheck disable=SC2154
|
|
|
|
if [ "${logarithmic}" = "1" ]; then
|
2016-09-04 06:15:20 +02:00
|
|
|
graph_args="-o"
|
|
|
|
else
|
|
|
|
graph_args="-l 0"
|
|
|
|
fi
|
2016-09-03 13:04:25 +02:00
|
|
|
cat <<EOF
|
|
|
|
graph_title ${TITLE}
|
2016-09-04 06:15:20 +02:00
|
|
|
graph_args ${graph_args} --base 1000
|
2016-09-03 13:04:25 +02:00
|
|
|
graph_category ${CATEGORY}
|
|
|
|
graph_info This graph shows the length of ${FILES}
|
2016-09-04 06:15:20 +02:00
|
|
|
graph_vlabel length (lines)
|
2016-09-03 13:04:25 +02:00
|
|
|
EOF
|
|
|
|
|
|
|
|
for F in $FILES; do
|
2016-10-29 08:43:40 +02:00
|
|
|
MF=$(clean_fieldname "$F")
|
|
|
|
BF=$(basename "$F")
|
|
|
|
echo "$MF.label ${BF}"
|
2016-09-03 13:04:25 +02:00
|
|
|
done
|
|
|
|
|
|
|
|
else
|
|
|
|
for F in $FILES; do
|
2016-10-29 08:43:40 +02:00
|
|
|
MF=$(echo "$F" | sed 's/[-\/\.]/_/g')
|
|
|
|
echo "$MF.value $(wc -l < "$F")"
|
|
|
|
echo "$MF.extinfo $(stat --printf="%sB\n" "$F")"
|
2016-09-03 13:04:25 +02:00
|
|
|
done
|
|
|
|
fi
|