1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-21 18:41:03 +00:00

[mpdstats_] allow unconfigured usage (all stats)

This commit is contained in:
Lars Kruse 2016-10-22 13:43:31 +02:00
parent 380c4a9ea5
commit 09d9f32e71

View file

@ -19,8 +19,10 @@ work like a charm already.
=head1 INSTALLATION =head1 INSTALLATION
This wildcard plugin should be symlinked using one of these names: This wildcard plugin can be symlinked using one of the statistic
mpdstats_artists, mpdstats_albums, mpdstats_songs categories of mpd. See the output of "echo stats | nc MPD_HOST 6600".
Without a symlink configuration (no suffix after the underscore) all
stats are shown.
=head1 CONFIGURATION =head1 CONFIGURATION
@ -66,33 +68,25 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
=cut =cut
. "$MUNIN_LIBDIR/plugins/plugin.sh"
MPDHOST=${mpd_host:-localhost} MPDHOST=${mpd_host:-localhost}
MPDPORT=${mpd_port:-6600} MPDPORT=${mpd_port:-6600}
NCBIN=${netcat:-$(which nc)} NCBIN=${netcat:-$(which nc)}
ACTION="$(basename "$0" | sed 's/^.*_//')"
# #
# FUNCTIONS # FUNCTIONS
# #
do_autoconf () { do_autoconf () {
case "$ACTION" in
albums|artists|songs)
;;
*)
echo "no (not a valid symlink name, please read the plugin doc)"
exit 1
;;
esac
if [ -z "$NCBIN" ] ; then if [ -z "$NCBIN" ] ; then
echo "no (missing netcat program ('nc'))" echo "no (missing netcat program ('nc'))"
exit 1 exit 1
fi fi
echo version | "$NCBIN" "$MPDHOST" "$MPDPORT" 1>/dev/null 2>&1 if ! echo version | "$NCBIN" "$MPDHOST" "$MPDPORT" >/dev/null 2>&1; then
if [ "$?" != 0 ] ; then
echo "no (connection failed)" echo "no (connection failed)"
exit 1 exit 1
fi fi
@ -101,35 +95,65 @@ do_autoconf () {
exit 0 exit 0
} }
get_mpd_stats_keys() {
echo stats | "$NCBIN" "$MPDHOST" "$MPDPORT" | awk 'BEGIN {FS=":"} /^[^ ]+:/ {print $1}'
}
print_mpd_stat_value() {
local key="$1"
local fieldname
local stat_value
fieldname="$(clean_fieldname "$key")"
stat_value="$(echo stats | "$NCBIN" "$MPDHOST" "$MPDPORT" | awk "/^${key}:/ {print \$2}")"
echo "${fieldname}.value $stat_value"
}
# #
# MAIN # MAIN
# #
SCRIPTNAME=${0##*/}
ACTION=${SCRIPTNAME##*_}
case "$1" in case "$1" in
autoconf) autoconf)
do_autoconf do_autoconf
;; ;;
suggest) suggest)
echo "$ACTION" get_mpd_stats_keys
exit 0
;; ;;
config) config)
echo "graph_category MPD echo "graph_category MPD"
graph_title $ACTION in the database echo "graph_args --base 1000 -l 0"
graph_info Number of $ACTION in the database. echo "graph_scale no"
graph_vlabel $ACTION in the db if [ -z "$ACTION" ]; then
graph_args --base 1000 -l 0 echo "graph_title MPD Statistics"
graph_scale no echo "graph_vlabel number of items"
$ACTION.type GAUGE for stat_key in $(get_mpd_stats_keys); do
$ACTION.draw LINE2 fieldname="$(clean_fieldname "$stat_key")"
$ACTION.label $ACTION" echo "${fieldname}.type GAUGE"
exit 0 echo "${fieldname}.draw LINE"
echo "${fieldname}.label $stat_key"
done
else
# Show only a single stat
echo "graph_title $ACTION in the MPD database"
echo "graph_info Number of $ACTION in the database."
echo "graph_vlabel $ACTION in the db"
echo "$ACTION.type GAUGE"
echo "$ACTION.draw LINE2"
echo "$ACTION.label $ACTION"
fi
;; ;;
*) *)
printf "$ACTION.value " if [ -z "$ACTION" ]; then
echo stats | "$NCBIN" "$MPDHOST" "$MPDPORT" | awk "/^${ACTION}:/ {print \$2}" for stat_key in $(get_mpd_stats_keys); do
print_mpd_stat_value "$stat_key"
done
else
print_mpd_stat_value "$ACTION"
fi
;; ;;
esac esac
exit 0