root / plugins / mpd / mpdstats_ @ f41b6861
Historique | Voir | Annoter | Télécharger (3,92 ko)
| 1 |
#!/bin/sh |
|---|---|
| 2 |
|
| 3 |
# vim: set ft=sh : |
| 4 |
# -*- sh -*- |
| 5 |
|
| 6 |
: << =cut |
| 7 |
|
| 8 |
=head1 NAME |
| 9 |
|
| 10 |
mpdstats_ - Munin plugin to monitor a MPD database |
| 11 |
|
| 12 |
=head1 DEPENDENCIES |
| 13 |
|
| 14 |
This plugin uses netcat(1) to communicate with the MPD daemon. |
| 15 |
|
| 16 |
Tip: To see if it is already set up correctly, just run this plugin |
| 17 |
with the parameter "autoconf". If you get a "yes", everything should |
| 18 |
work like a charm already. |
| 19 |
|
| 20 |
=head1 INSTALLATION |
| 21 |
|
| 22 |
This wildcard plugin can be symlinked using one of the statistic |
| 23 |
categories of mpd. See the output of "echo stats | nc MPD_HOST 6600". |
| 24 |
Without a symlink configuration (no suffix after the underscore) all |
| 25 |
stats are shown. |
| 26 |
|
| 27 |
=head1 CONFIGURATION |
| 28 |
|
| 29 |
No configuration should be required if run on the same server as |
| 30 |
MPD. If the plugin is run from remote or in a non-default configuration, |
| 31 |
please use the environment variables 'mpd_host' and 'mpd_port' to connect. |
| 32 |
|
| 33 |
Also, if your netcat(1) binary is anywhere else than /bin/nc please define |
| 34 |
it using the 'netcat' environment variable. |
| 35 |
|
| 36 |
=head2 CONFIGURATION EXAMPLE |
| 37 |
|
| 38 |
[mpdstats_*] |
| 39 |
env.mpd_host 192.168.0.43 |
| 40 |
env.mpd_port 6606 |
| 41 |
env.netcat /usr/local/bin/nc |
| 42 |
|
| 43 |
=head1 AUTHOR |
| 44 |
|
| 45 |
Copyright (C) 2012 ToM <tom@leloop.org> |
| 46 |
|
| 47 |
=head1 LICENSE |
| 48 |
|
| 49 |
This program is free software; you can redistribute it and/or |
| 50 |
modify it under the terms of the GNU General Public License |
| 51 |
as published by the Free Software Foundation; version 2 dated June, |
| 52 |
1991. |
| 53 |
|
| 54 |
This program is distributed in the hope that it will be useful, |
| 55 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 56 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 57 |
GNU General Public License for more details. |
| 58 |
|
| 59 |
You should have received a copy of the GNU General Public License |
| 60 |
along with this program; if not, write to the Free Software |
| 61 |
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 62 |
|
| 63 |
=head1 MAGIC MARKERS |
| 64 |
|
| 65 |
#%# family=auto |
| 66 |
#%# capabilities=autoconf suggest |
| 67 |
|
| 68 |
=cut |
| 69 |
|
| 70 |
|
| 71 |
. "$MUNIN_LIBDIR/plugins/plugin.sh" |
| 72 |
|
| 73 |
MPDHOST=${mpd_host:-localhost}
|
| 74 |
MPDPORT=${mpd_port:-6600}
|
| 75 |
NCBIN=${netcat:-$(which nc)}
|
| 76 |
|
| 77 |
ACTION="$(basename "$0" | sed 's/^.*_//')" |
| 78 |
|
| 79 |
# |
| 80 |
# FUNCTIONS |
| 81 |
# |
| 82 |
|
| 83 |
do_autoconf () {
|
| 84 |
if [ -z "$NCBIN" ] ; then |
| 85 |
echo "no (missing netcat program ('nc'))"
|
| 86 |
exit 1 |
| 87 |
fi |
| 88 |
|
| 89 |
if ! echo version | "$NCBIN" "$MPDHOST" "$MPDPORT" >/dev/null 2>&1; then |
| 90 |
echo "no (connection failed)" |
| 91 |
exit 1 |
| 92 |
fi |
| 93 |
|
| 94 |
echo "yes" |
| 95 |
exit 0 |
| 96 |
} |
| 97 |
|
| 98 |
|
| 99 |
get_mpd_stats_keys() {
|
| 100 |
echo stats | "$NCBIN" "$MPDHOST" "$MPDPORT" | awk 'BEGIN {FS=":"} /^[^ ]+:/ {print $1}'
|
| 101 |
} |
| 102 |
|
| 103 |
|
| 104 |
print_mpd_stat_value() {
|
| 105 |
local key="$1" |
| 106 |
local fieldname |
| 107 |
local stat_value |
| 108 |
fieldname="$(clean_fieldname "$key")" |
| 109 |
stat_value="$(echo stats | "$NCBIN" "$MPDHOST" "$MPDPORT" | awk "/^${key}:/ {print \$2}")"
|
| 110 |
echo "${fieldname}.value $stat_value"
|
| 111 |
} |
| 112 |
|
| 113 |
|
| 114 |
# |
| 115 |
# MAIN |
| 116 |
# |
| 117 |
|
| 118 |
|
| 119 |
case "$1" in |
| 120 |
autoconf) |
| 121 |
do_autoconf |
| 122 |
;; |
| 123 |
suggest) |
| 124 |
get_mpd_stats_keys |
| 125 |
;; |
| 126 |
config) |
| 127 |
echo "graph_category streaming" |
| 128 |
echo "graph_args --base 1000 -l 0" |
| 129 |
echo "graph_scale no" |
| 130 |
if [ -z "$ACTION" ]; then |
| 131 |
echo "graph_title MPD Statistics" |
| 132 |
echo "graph_vlabel number of items" |
| 133 |
for stat_key in $(get_mpd_stats_keys); do |
| 134 |
fieldname="$(clean_fieldname "$stat_key")" |
| 135 |
echo "${fieldname}.type GAUGE"
|
| 136 |
echo "${fieldname}.draw LINE"
|
| 137 |
echo "${fieldname}.label $stat_key"
|
| 138 |
done |
| 139 |
else |
| 140 |
# Show only a single stat |
| 141 |
echo "graph_title $ACTION in the MPD database" |
| 142 |
echo "graph_info Number of $ACTION in the database." |
| 143 |
echo "graph_vlabel $ACTION in the db" |
| 144 |
echo "$ACTION.type GAUGE" |
| 145 |
echo "$ACTION.draw LINE2" |
| 146 |
echo "$ACTION.label $ACTION" |
| 147 |
fi |
| 148 |
;; |
| 149 |
*) |
| 150 |
if [ -z "$ACTION" ]; then |
| 151 |
for stat_key in $(get_mpd_stats_keys); do |
| 152 |
print_mpd_stat_value "$stat_key" |
| 153 |
done |
| 154 |
else |
| 155 |
print_mpd_stat_value "$ACTION" |
| 156 |
fi |
| 157 |
;; |
| 158 |
esac |
| 159 |
exit 0 |
