Repository
Munin (contrib)
Last change
2020-05-07
Graph Categories
Family
disk
Capabilities
Keywords
Language
Bash
License
GPL-2.0-only
Authors

e2

Name

ext2 - Wildcard plugin shows ext2/3/4 filesystem information (mount count, last checked, lifetime writes)

Configuration

[ext2_*]
group disk,floppy

Author

Andreas Hrubak <>

License

GPLv2

Magick Markers

#%# family=disk
#%# capabilities=autoconf
#!/bin/bash

true << =cut

=head1 NAME

ext2 - Wildcard plugin shows ext2/3/4 filesystem information (mount count, last checked, lifetime writes)

=head1 CONFIGURATION

 [ext2_*]
 group disk,floppy

=head1 AUTHOR

Andreas Hrubak <>

=head1 LICENSE

GPLv2

=head1 MAGICK MARKERS

 #%# family=disk
 #%# capabilities=autoconf

=cut

print_details() {
	local myname
	while read line; do
		key=${line%%:*}
		val=`echo ${line#*:}`
		val1=${val%% *}
		[ -z "$line" ] && break

		case "$key" in
		"Mount count")		myname=$1; mc=$val ;;
		"Maximum mount count")	mmc=$val ;;
		"Last checked")		lcts=`date +%s -d "$val" 2>/dev/null` ;;
		"Check interval")	ciis=$val1 ;;
		"Lifetime writes")	lwGB=$val1 ;;
		esac
	done
	[ -n "$myname" ] && echo "$myname ${mc:-0} ${mmc:-0} ${lcts:-0} ${ciis:-0} ${lwGB:-0}"
}

lse2() {
       while read -r line ; do
               value=( $line );
               LANG=C dumpe2fs -h "${value[0]}" 2>/dev/null | print_details "$(basename ${value[0]})"	       
       done <<< "$(lsblk -p -o NAME,FSTYPE -r | grep ext[2-4] | uniq )"
}


if [ "$1" = "autoconf" ]; then
	if which dumpe2fs >/dev/null 2>&1; then
		echo yes
	else
		echo no
	fi
	exit 0
fi
if [ "$1" = "suggest" ]; then
	lse2 | while read name rest; do
		echo mounts_$name
		echo checked_$name
		echo writes_$name
	done
	exit 0
fi


self=${0##*/}
self=${self#*_}
plugin=${self%%_*}
if [ -n "${self//[!_]/}" ]; then
	blkdev=${self#*_}
	blkdevAppend=" ($blkdev)"
	blkdevpath=$(lsblk -p -o NAME -r | grep "$blkdev" | uniq | cut -d' ' -f1)
else
	blkdev=
	blkdevAppend=
fi


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

	echo "graph_category disk"
	args="-l 0"
	case "$plugin" in
	mounts)
		echo "graph_vlabel times"
		echo "graph_title Ext2 Filesystem mount details"
		;;
	checked)
		echo "graph_vlabel days"
		echo "graph_title Ext2 Filesystem fsck interval"
		;;
	writes)
		args="$args --base 1024"
		echo "graph_vlabel bytes"
		echo "graph_title Ext2 Filesystem lifetime writes$blkdevAppend"
		;;
	esac
	echo "graph_args $args"

	if [ -z "$blkdev" ]; then
		lse2
	else
		LANG=C dumpe2fs -h "$blkdevpath" 2>/dev/null | print_details "$blkdev"
	fi | \
	while read name mounts maxmounts last interval writes; do
		[ -z "$blkdev" ] && blkdevAppend2=" ($name)" || blkdevAppend2=
		name_esc=${name//-/_}
		case "$plugin" in
		mounts)
			echo "${name_esc}_mounts.label Mount count$blkdevAppend2"
			echo "${name_esc}_mounts.draw LINE2"
			echo "${name_esc}_maxmounts.label Max. mount count$blkdevAppend2"
			echo "${name_esc}_maxmounts.draw LINE1"
			;;
		checked)
			echo "${name_esc}_last.label Since checked$blkdevAppend2"
			echo "${name_esc}_last.draw LINE2"
			echo "${name_esc}_last.cdef ${name_esc}_last,86400,/"
			echo "${name_esc}_interval.label Check interval$blkdevAppend2"
			echo "${name_esc}_interval.draw LINE1"
			echo "${name_esc}_interval.cdef ${name_esc}_interval,86400,/"
			;;
		writes)
			echo "${name_esc}_writes.label Lifetime writes$blkdevAppend2"
			echo "${name_esc}_writes.type GAUGE"
			echo "${name_esc}_writes.draw LINE2"
			echo "${name_esc}_writes.cdef ${name_esc}_writes,1073741824,*"
			;;
		esac
	done

	exit 0
fi



## fetch ##

if [ -z "$blkdev" ]; then
	lse2
else
	LANG=C dumpe2fs -h "$blkdevpath" 2>/dev/null | print_details "$blkdev"
fi | \
while read name mounts maxmounts last interval writes; do
	name_esc=${name//-/_}
	case "$plugin" in
	mounts)
		echo "${name_esc}_mounts.value $mounts"
		echo "${name_esc}_maxmounts.value $maxmounts"
		;;
	checked)
		now=`date +%s`
		past=$(( now - last ))
		echo "${name_esc}_last.value $past"
		echo "${name_esc}_interval.value $interval"
		;;
	writes)
		echo "${name_esc}_writes.value $writes"
		;;
	esac
done