Repository
Munin (contrib)
Last change
2020-03-26
Graph Categories
Family
auto contrib
Keywords
Language
Bash

xfs_frag

Name

xfs_frag - Munin plugin to monitor the fragmentation level on your XFS filesystems

Applicable Systems

Any machine with an XFS file system.

Configuration

None, generally, but you may want to run as root and set a timeout.

[xfs_frag]
user root
timeout 90

Magic Markers

#%# family=auto contrib
#%# capabilities=

Version

1

Author

Paul Saunders darac+munin@darac.org.uk

#!/bin/bash

: <<=cut
=head1 NAME

xfs_frag - Munin plugin to monitor the fragmentation level on your XFS filesystems

=head1 APPLICABLE SYSTEMS

Any machine with an XFS file system.

=head1 CONFIGURATION

None, generally, but you may want to run as root and set a timeout.

  [xfs_frag]
  user root
  timeout 90

=head1 MAGIC MARKERS

  #%# family=auto contrib
  #%# capabilities=

=head1 VERSION

1

=head1 AUTHOR

Paul Saunders L<darac+munin@darac.org.uk>

=cut

declare -a TOKENS
shopt -s nocasematch

case $1 in
	config)
		cat <<'EOF'
graph_title XFS fragmentation
graph_vlabel Percent
graph_category disk
EOF
		awk '{print $2 " " $3}' </etc/mtab | while read -r LINE; do
			# shellcheck disable=SC2206
			TOKENS=($LINE)
			if [[ ${TOKENS[1]} =~ xfs ]]; then
				FIELDNAME=$(echo "${TOKENS[0]}" | sed 's/^[^A-Za-z_]/_/; s/[^A-Za-z0-9_]/_/g')
				echo "$FIELDNAME.label ${TOKENS[0]}"
				echo "$FIELDNAME.type GAUGE"
			fi
		done
		exit 0
		;;
esac

awk '{print $2 " " $3 " " $1}' </etc/mtab | while read -r LINE; do
	# shellcheck disable=SC2206
	TOKENS=($LINE)
	if [[ ${TOKENS[1]} =~ xfs ]]; then
		FIELDNAME=$(echo "${TOKENS[0]}" | sed 's/^[^A-Za-z_]/_/; s/[^A-Za-z0-9_]/_/g')
		FRAG=$(xfs_db -c frag -r "${TOKENS[2]}" | sed 's/.*fragmentation factor \(.*\)%.*/\1/')
		echo "$FIELDNAME.value $FRAG"
	fi
done