2012-11-06 12:37:30 +01:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
# vim: set ft=sh :
|
|
|
|
# -*- sh -*-
|
|
|
|
|
|
|
|
: << =cut
|
|
|
|
|
|
|
|
=head1 NAME
|
|
|
|
|
|
|
|
mpdstats_ - Munin plugin to monitor a MPD database
|
|
|
|
|
|
|
|
=head1 DEPENDENCIES
|
|
|
|
|
|
|
|
This plugin uses netcat(1) to communicate with the MPD daemon.
|
|
|
|
|
|
|
|
Tip: To see if it is already set up correctly, just run this plugin
|
|
|
|
with the parameter "autoconf". If you get a "yes", everything should
|
|
|
|
work like a charm already.
|
|
|
|
|
|
|
|
=head1 INSTALLATION
|
|
|
|
|
2016-10-22 13:43:31 +02:00
|
|
|
This wildcard plugin can be symlinked using one of the statistic
|
|
|
|
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.
|
2012-11-06 12:37:30 +01:00
|
|
|
|
|
|
|
=head1 CONFIGURATION
|
|
|
|
|
|
|
|
No configuration should be required if run on the same server as
|
|
|
|
MPD. If the plugin is run from remote or in a non-default configuration,
|
|
|
|
please use the environment variables 'mpd_host' and 'mpd_port' to connect.
|
|
|
|
|
|
|
|
Also, if your netcat(1) binary is anywhere else than /bin/nc please define
|
|
|
|
it using the 'netcat' environment variable.
|
|
|
|
|
|
|
|
=head2 CONFIGURATION EXAMPLE
|
|
|
|
|
2015-01-31 14:56:49 +01:00
|
|
|
[mpdstats_*]
|
2012-11-06 12:37:30 +01:00
|
|
|
env.mpd_host 192.168.0.43
|
|
|
|
env.mpd_port 6606
|
|
|
|
env.netcat /usr/local/bin/nc
|
|
|
|
|
|
|
|
=head1 AUTHOR
|
|
|
|
|
|
|
|
Copyright (C) 2012 ToM <tom@leloop.org>
|
|
|
|
|
|
|
|
=head1 LICENSE
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; version 2 dated June,
|
|
|
|
1991.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
|
|
|
|
=head1 MAGIC MARKERS
|
|
|
|
|
|
|
|
#%# family=auto
|
|
|
|
#%# capabilities=autoconf suggest
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
|
2016-10-22 13:43:31 +02:00
|
|
|
. "$MUNIN_LIBDIR/plugins/plugin.sh"
|
2012-11-06 12:37:30 +01:00
|
|
|
|
|
|
|
MPDHOST=${mpd_host:-localhost}
|
|
|
|
MPDPORT=${mpd_port:-6600}
|
2016-10-22 13:41:58 +02:00
|
|
|
NCBIN=${netcat:-$(which nc)}
|
|
|
|
|
2016-10-22 13:43:31 +02:00
|
|
|
ACTION="$(basename "$0" | sed 's/^.*_//')"
|
2012-11-06 12:37:30 +01:00
|
|
|
|
|
|
|
#
|
|
|
|
# FUNCTIONS
|
|
|
|
#
|
|
|
|
|
|
|
|
do_autoconf () {
|
2016-10-22 13:41:58 +02:00
|
|
|
if [ -z "$NCBIN" ] ; then
|
|
|
|
echo "no (missing netcat program ('nc'))"
|
2018-09-16 05:03:47 +02:00
|
|
|
elif ! echo version | "$NCBIN" "$MPDHOST" "$MPDPORT" >/dev/null 2>&1; then
|
2012-11-06 12:37:30 +01:00
|
|
|
echo "no (connection failed)"
|
2018-09-16 05:03:47 +02:00
|
|
|
else
|
|
|
|
echo "yes"
|
2012-11-06 12:37:30 +01:00
|
|
|
fi
|
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
2016-10-22 13:43:31 +02:00
|
|
|
|
|
|
|
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"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-06 12:37:30 +01:00
|
|
|
#
|
|
|
|
# MAIN
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
|
|
case "$1" in
|
|
|
|
autoconf)
|
|
|
|
do_autoconf
|
|
|
|
;;
|
|
|
|
suggest)
|
2016-10-22 13:43:31 +02:00
|
|
|
get_mpd_stats_keys
|
2012-11-06 12:37:30 +01:00
|
|
|
;;
|
|
|
|
config)
|
2017-02-23 00:15:13 +01:00
|
|
|
echo "graph_category streaming"
|
2016-10-22 13:43:31 +02:00
|
|
|
echo "graph_args --base 1000 -l 0"
|
|
|
|
echo "graph_scale no"
|
|
|
|
if [ -z "$ACTION" ]; then
|
|
|
|
echo "graph_title MPD Statistics"
|
|
|
|
echo "graph_vlabel number of items"
|
|
|
|
for stat_key in $(get_mpd_stats_keys); do
|
|
|
|
fieldname="$(clean_fieldname "$stat_key")"
|
|
|
|
echo "${fieldname}.type GAUGE"
|
|
|
|
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
|
2012-11-06 12:37:30 +01:00
|
|
|
;;
|
|
|
|
*)
|
2016-10-22 13:43:31 +02:00
|
|
|
if [ -z "$ACTION" ]; then
|
|
|
|
for stat_key in $(get_mpd_stats_keys); do
|
|
|
|
print_mpd_stat_value "$stat_key"
|
|
|
|
done
|
|
|
|
else
|
|
|
|
print_mpd_stat_value "$ACTION"
|
|
|
|
fi
|
2012-11-06 12:37:30 +01:00
|
|
|
;;
|
|
|
|
esac
|
2016-10-22 13:43:31 +02:00
|
|
|
exit 0
|