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

Category Tree: Reduce number of categories

icecast -> streaming (icecast)
moodle -> cms (moodle)
postfwd2: mail -> fw (postfix)
This commit is contained in:
dipohl 2017-02-23 17:46:56 +01:00
parent 6aa977b250
commit a8d024ace4
13 changed files with 15 additions and 10 deletions

181
plugins/icecast/icecast2 Executable file
View file

@ -0,0 +1,181 @@
#!/bin/sh
#
# Plugin to monitor icecast2 streams / listeners
#
# Contributed by drew Roberts
#
# based on the postfix_mailqueue plugin as per below
#
# Plugin to monitor postfix mail spools
#
# Contributed by Nicolai Langfeldt
#
# $Log$
# Revision 1.0 2008/07/04 16:02:36 zotz
# Initial work
#
#
#%# family=auto
#%# capabilities=autoconf
# Can be set via environment, but default is /var/spool/postfix
ICEDIR=${icedir:-/var/www/rrd/logs/stream_stats/}
case $1 in
autoconf|detect)
if [ -d $ICEDIR/ ] ; then
echo yes
exit 0
else
echo "no (icedir not found)"
exit 1
fi;;
config)
cat <<'EOF'
graph_title Icecast2 Stream Listeners
graph_args --base 1000 -l 0
graph_vlabel Listeners for Streams
graph_category streaming
cool_ogg.label cool_ogg
cool_ogg.draw AREA
cool_ogg.type GAUGE
cool_mp3.label cool_mp3
cool_mp3.draw STACK
cool_mp3.type GAGUE
jamz_ogg.label jamz_ogg
jamz_ogg.draw STACK
jamz_ogg.type GAGUE
jamz_mp3.label jamz_mp3
jamz_mp3.draw STACK
jamz_mp3.type GAGUE
joy_ogg.label joy_ogg
joy_ogg.draw STACK
joy_ogg.type GAGUE
joy_mp3.label joy_mp3
joy_mp3.draw STACK
joy_mp3.type GAGUE
y_ogg.label y_ogg
y_ogg.draw STACK
y_ogg.type GAGUE
y_mp3.label y_mp3
y_mp3.draw STACK
y_mp3.type GAGUE
EOF
exit 0;;
esac
cd $ICEDIR >/dev/null 2>/dev/null || {
echo "# Cannot cd to $ICEDIR"
exit 1
}
/usr/bin/curl -s localhost:7144/status2.xsl > /tmp/ice.txt
/usr/bin/tail -n 1 /tmp/ice.txt > /tmp/ice1.txt
awk 'BEGIN {FS=","} {tot = 0 ; i = (NF-1)/6 ; j=1 ; while (j <= i) {tot = (tot + $(((j-1)*6)+4)) ; print $(((j-1)*6)+1), ":", $(((j-1)*6)+4) > "/tmp/ice2.txt" ; j++}; print "total :", tot >> "/tmp/ice2.txt"} ' /tmp/ice1.txt
# Cool ogg stream
grep cool.ogg /tmp/ice2.txt > /dev/null 2>&1
if [ "$?" -ne "0" ]; then
coologg="0"
else
coologg=`grep cool.ogg /tmp/ice2.txt | cut -d ":" -f 2 - `
coologg=$(($coologg+0))
fi
#echo $coologg
# Cool mp3 stream
grep coolmp3 /tmp/ice2.txt > /dev/null 2>&1
if [ "$?" -ne "0" ]; then
coolmp3="0"
else
coolmp3=`grep coolmp3 /tmp/ice2.txt | cut -d ":" -f 2 - `
coolmp3=$(($coolmp3+0))
fi
#echo $coolmp3
# Jamz ogg stream
grep jamz.ogg /tmp/ice2.txt > /dev/null 2>&1
if [ "$?" -ne "0" ]; then
jamzogg="0"
else
jamzogg=`grep jamz.ogg /tmp/ice2.txt | cut -d ":" -f 2 - `
jamzogg=$(($jamzogg+0))
fi
#echo $jamzogg
# Jamz mp3 stream
grep jamzmp3 /tmp/ice2.txt > /dev/null 2>&1
if [ "$?" -ne "0" ]; then
jamzmp3="0"
else
jamzmp3=`grep jamzmp3 /tmp/ice2.txt | cut -d ":" -f 2 - `
jamzmp3=$(($jamzmp3+0))
fi
#echo $jamzmp3
# Joy ogg stream
grep joy.ogg /tmp/ice2.txt > /dev/null 2>&1
if [ "$?" -ne "0" ]; then
joyogg="0"
else
joyogg=`grep joy.ogg /tmp/ice2.txt | cut -d ":" -f 2 - `
joyogg=$(($joyogg+0))
fi
#echo $joyogg
# Joy mp3 stream
grep joymp3 /tmp/ice2.txt > /dev/null 2>&1
if [ "$?" -ne "0" ]; then
joymp3="0"
else
joymp3=`grep joymp3 /tmp/ice2.txt | cut -d ":" -f 2 - `
joymp3=$(($joymp3+0))
fi
#echo $joymp3
# Y ogg stream
grep "/y.ogg" /tmp/ice2.txt > /dev/null 2>&1
if [ "$?" -ne "0" ]; then
yogg="0"
else
yogg=`grep "/y.ogg" /tmp/ice2.txt | cut -d ":" -f 2 - `
yogg=$(($yogg+0))
fi
#echo $yogg
# Y mp3 stream
grep "/ymp3" /tmp/ice2.txt > /dev/null 2>&1
if [ "$?" -ne "0" ]; then
ymp3="0"
else
ymp3=`grep "/ymp3" /tmp/ice2.txt | cut -d ":" -f 2 - `
ymp3=$(($ymp3+0))
fi
#echo $ymp3
# total streams
grep total /tmp/ice2.txt > /dev/null 2>&1
if [ "$?" -ne "0" ]; then
totals="0"
else
totals=`grep total /tmp/ice2.txt | cut -d ":" -f 2 - `
totals=$(($totals+0))
fi
#echo $totals
# output=`echo $coologg:$coolmp3:$jamzogg:$jamzmp3:$joyogg:$joymp3:$yogg:$ymp3:$totals`
cat <<EOF
cool_ogg.value $coologg
cool_mp3.value $coolmp3
jamz_ogg.value $jamzogg
jamz_mp3.value $jamzmp3
joy_ogg.value $joyogg
joy_mp3.value $joymp3
y_ogg.value $yogg
y_mp3.value $ymp3
EOF

153
plugins/icecast/icecast2_ Normal file
View file

@ -0,0 +1,153 @@
#! /usr/bin/python
# -*- coding: iso-8859-1 -*-
# Hostname of Icecast server
# Just canonical name, no http:// nor ending /
host = "foo.bar.com"
username = "admin"
# Password for admin access to Icecast2 server to fetch statistics
password = ""
realm = "Icecast2 Server"
# Bitrates the MP3 stream is served with
mp3bitrates = [56, 128]
# Bitrates the Ogg Stream is served with
oggbitrates = [56, 128, 172]
# This plugin shows the statistics of a specific subset of sources connected to an Icecast2 server.
# Place the file in /usr/share/munin/plugins and then symlink to it from
# /etc/munin/plugins
# The name icecast2_total will show total number of listeners on server, as
# well the total number of listeners for any configured stream.
# For each stream with multiple bitrates, create one
# icecast2_streamname
# If the name contains a "-" exchange it with a "_", and the script will change it back for you. This is to satisfy internal requirements of Munin.
# For each streamname, the plugin will check for the configured bitrates
# Expecting the mountpoints to be on the form of
# /streamname_<bitrate> for mp3
# /streamname_<bitrate>.ogg for Ogg/Vorbis
import urllib2, os.path, time, sys
from xml.dom import minidom
def hent_XML():
auth_handler = urllib2.HTTPBasicAuthHandler()
auth_handler.add_password(realm, host, username, password)
opener = urllib2.build_opener(auth_handler)
urllib2.install_opener(opener)
xmlweb = urllib2.urlopen("http://%s/admin/stats" % host)
xml = xmlweb.read()
xmlweb.close()
# Parser oversikt
xmldoc = minidom.parseString(xml)
xmldoc = xmldoc.firstChild
#Totalt antall lyttere
total_lyttere = xmldoc.getElementsByTagName("clients")[0].firstChild.nodeValue
#Totalt antall kilder
total_kilder = xmldoc.getElementsByTagName("sources")[0].firstChild.nodeValue
#Status for enkelt strøm
sources = xmldoc.getElementsByTagName("source")
sourcelist = {}
for source in sources:
mount = source.getAttribute("mount")
listeners = source.getElementsByTagName("listeners")[0].firstChild.nodeValue
name = source.getElementsByTagName("server_name")[0].firstChild.nodeValue
mount = mount.replace("-", "_")
sourcelist[mount[1:]] = (listeners, name)
sourcename = sys.argv[0].split("/")[-1][len("icecast2_"):]
if len(sys.argv) == 1:
sys.argv.append("")
if sys.argv[1] == "autoconf":
print "yes"
elif sys.argv[1] == "config":
if sourcename == "total":
print "graph_title Totalt antall lyttere"
print "graph_vlabel lyttere"
print "graph_category streaming"
print "totallyttere.label Totalt antall lyttere"
print "totalkilder.label Totalt antall kilder"
chanlist = {}
for a, b, filelist in os.walk("/etc/munin/plugins"):
for file in filelist:
if file.find("icecast2_") != -1:
channelname = file[len("icecast2_"):]
if channelname != "total" and chanlist.has_key(channelname) != 1:
chanlist[channelname] = 0
chanlist = chanlist.keys()
chanlist.sort()
for chan in chanlist:
graphtitle = ""
for key in sourcelist.keys():
if key.find(chan) != -1:
l, graphtitle = sourcelist[key]
break
if graphtitle == "":
graphtitle = chan
print "%s.label %s" % (chan, graphtitle)
else:
sumstring = ""
graphtitle = ""
for key in sourcelist.keys():
if key.find(sourcename) != -1:
l, graphtitle = sourcelist[key]
break
if graphtitle == "":
graphtitle = sourcename
print "graph_title %s" % graphtitle
print "graph_vlabel lyttere"
print "graph_category streaming"
for bitrate in mp3bitrates:
print "%s_%s.label %s-%s" % (sourcename, bitrate, "/" + sourcename.replace("_", "-"), bitrate)
sumstring += "%s_%s " % (sourcename, bitrate)
print "%s_%s.critical -0.5:" % (sourcename, bitrate)
for bitrate in oggbitrates:
print "%s_%s_ogg.label %s-%s.ogg" % (sourcename, bitrate, "/" + sourcename.replace("_", "-"), bitrate)
print "%s_%s_ogg.critical -0.5:" % (sourcename, bitrate)
sumstring += "%s_%s_ogg " % (sourcename, bitrate)
print "%slyttere.label Totalt antall lyttere" % sourcename
print "%slyttere.sum %s" % (sourcename, sumstring)
elif sys.argv[1] != "config":
if sourcename == "total":
print "totallyttere.value %s" % total_lyttere
print "totalkilder.value %s" % total_kilder
statslist = {}
for a, b, filelist in os.walk("/etc/munin/plugins"):
for file in filelist:
if file.find("icecast2_") != -1:
channelname = file[len("icecast2_"):]
if channelname != "total" and statslist.has_key(channelname) != 1:
statslist[channelname] = 0
for source in sourcelist:
listeners, name = sourcelist[source]
if not statslist.has_key(source[:source.rfind("_")]):
statslist[source[:source.rfind("_")]] = 0
statslist[source[:source.rfind("_")]] += int(listeners)
for stat in statslist:
print "%s.value %s" % (stat, statslist[stat])
else:
for bitrate in mp3bitrates:
if sourcelist.has_key("%s_%s" % (sourcename, bitrate)):
listeners = sourcelist["%s_%s" % (sourcename, bitrate)][0]
print listeners
else:
listeners = -1
print "%s_%s.value %s" % (sourcename, bitrate, listeners)
for bitrate in oggbitrates:
if sourcelist.has_key("%s_%s.ogg" % (sourcename, bitrate)):
listeners = sourcelist["%s_%s.ogg" % (sourcename, bitrate)][0]
else:
listeners = -1
print "%s_%s_ogg.value %s" % (sourcename, bitrate, listeners)
else:
print sys.argv[1]
if __name__ == "__main__":
hent_XML()

View file

@ -0,0 +1,72 @@
#! /usr/bin/python
# -*- coding: iso-8859-1 -*-
# Hostname of Icecast server
# Just canonical name, no http:// nor ending /
host = "foo.bar.com"
username = "admin"
# Password for admin access to Icecast2 server to fetch statistics
password = ""
realm = "Icecast2 Server"
# This plugin shows the statistics of every source currently connected to the Icecast2 server. See the Icecast2_ plugin for specific mountpoint plugin.
import urllib2, os.path, time, sys
from xml.dom import minidom
def hent_XML():
auth_handler = urllib2.HTTPBasicAuthHandler()
auth_handler.add_password(realm, host, username, password)
opener = urllib2.build_opener(auth_handler)
urllib2.install_opener(opener)
xmlweb = urllib2.urlopen("http://%s/admin/stats" % host)
xml = xmlweb.read()
xmlweb.close()
# Parser oversikt
xmldoc = minidom.parseString(xml)
xmldoc = xmldoc.firstChild
#Totalt antall lyttere
total_lyttere = xmldoc.getElementsByTagName("clients")[0].firstChild.nodeValue
#Totalt antall kilder
total_kilder = xmldoc.getElementsByTagName("sources")[0].firstChild.nodeValue
#Status for enkelt strøm
sources = xmldoc.getElementsByTagName("source")
sourcelist = {}
for source in sources:
mount = source.getAttribute("mount")
listeners = source.getElementsByTagName("listeners")[0].firstChild.nodeValue
name = source.getElementsByTagName("server_name")[0].firstChild.nodeValue
mount = mount.replace("-", "_").replace(".", "_")
sourcelist[mount[1:]] = (listeners, name)
if len(sys.argv) > 0 and sys.argv[1] == "autoconf":
print "yes"
elif len(sys.argv) == 1 or sys.argv[1] != "config":
print "totallyttere.value %s" % total_lyttere
print "totalkilder.value %s" % total_kilder
sourcesort = sourcelist.keys()
sourcesort.sort()
for source in sourcesort:
listeners, name = sourcelist[source]
print "%s.value %s" % (source, listeners)
elif sys.argv[1] == "config":
print "graph_title Total number of listeners"
print "graph_vlabel listeners"
print "graph_category streaming"
print "totallyttere.label Total number of listeners"
print "totalkilder.label Totalt number of sources"
sourcesort = sourcelist.keys()
sourcesort.sort()
for source in sourcesort:
listeners, name = sourcelist[source]
print "%s.label %s" % (source, "/" + source)
else:
print sys.argv[1]
if __name__ == "__main__":
hent_XML()

70
plugins/icecast/icecast2_simple Executable file
View file

@ -0,0 +1,70 @@
#!/usr/bin/ruby
#
# Plugin author: Gunnar Wolf <gwolf@gwolf.org>
#
# You are hereby granted authorization to copy, use, modify, distribute,
# and in general do anything you please with this plugin. It is too simple
# even to GPL-protect it.
#
# This plugin expects to receive via environment variables:
#
# icecast_host - Which host to monitor (default: 127.0.0.1)
# icecast_username - Username to connect with (default: admin)
# icecast_password - Password to connect with (default: hackme)
# icecast_realm - Realm to connect with (default: 'Icecast2 server')
#
require 'hpricot'
require 'open-uri'
def get_conf
# Default values
conf = {:host => '127.0.0.1', :port => 8000,
:username => 'admin', :password => 'hackme' }
conf.keys.each do |key|
env_key = sprintf('icecast_%s', key)
conf[key] = ENV[env_key] if ENV.has_key?(env_key)
end
conf
end
def get_data(conf)
begin
data = Hpricot(open(sprintf('http://%s:%s/admin/stats',
conf[:host], conf[:port]),
:http_basic_authentication=>[conf[:username],
conf[:password]]))
rescue OpenURI::HTTPError
puts "Cannot connect: HTTP connection error"
exit 1
end
data
end
def get_values(data)
vals = {}
[:sources, :clients].each do |key|
elem = data/key
if elem.nil?
vals[key] = 0
else
vals[key] = elem.innerHTML
end
end
vals
end
data = get_data(get_conf)
vals = get_values(data)
if ARGV[0] == 'autoconf'
puts 'yes'
elsif ARGV[0] == 'config'
puts "graph_title Total sources and clients for Icecast"
puts "graph_vlabel listeners"
puts "graph_category streaming"
puts "sources.label Total number of sources"
puts "clients.label Total number of clients"
else
puts "sources.value " + vals[:sources]
puts "clients.value " + vals[:clients]
end

182
plugins/icecast/icecast2_stats_ Executable file
View file

@ -0,0 +1,182 @@
#!/usr/bin/python3
#
# This plugin shows the statistics of every source currently connected to the Icecast2 server.
# See the Icecast2_ plugin for collecting data of specific mountpoints.
#
# An icecast server v2.4 or later is required for this module since it uses the status-json.xsl
# output (see http://www.icecast.org/docs/icecast-2.4.1/server-stats.html).
#
# The following data for each source is available:
# * listeners: current count of listeners
# * duration: the age of the stream/source
#
# Additionally the Icecast service uptime is available.
#
# This plugin requires Python 3 (e.g. for urllib instead of urllib2).
#
#
# Environment variables:
# * status_url: defaults to "http://localhost:8000/status-json.xsl"
#
#
# Copyright (C) 2015 Lars Kruse <devel@sumpfralle.de>
#
# 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, either version 3 of the License, or
# (at your option) any later version.
#
# 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, see <http://www.gnu.org/licenses/>.
#
#
# Magic markers
#%# capabilities=autoconf suggest
#%# family=auto
import datetime
import json
import os
import urllib.request
import sys
status_url = os.getenv("status_url", "http://localhost:8000/status-json.xsl")
PLUGIN_SCOPES = ("sources_listeners", "sources_duration", "service_uptime")
PLUGIN_NAME_PREFIX = "icecast2_stats_"
def clean_fieldname(name):
""" see http://munin-monitoring.org/wiki/notes_on_datasource_names
This function is a bit clumsy as it tries to avoid using a regular
expression for the sake of micropython compatibility.
"""
def get_valid(char, position):
if char == '_':
return '_'
elif 'a' <= char.lower() <= 'z':
return char
elif (position > 0) and ('0' <= char <= '9'):
return char
else:
return '_'
return "".join([get_valid(char, position) for position, char in enumerate(name)])
def parse_iso8601(datestring):
""" try to avoid using an external library for parsing an ISO8601 date string """
if datestring.endswith("Z"):
timestamp_string = datestring[:-1]
time_delta = datetime.timedelta(minutes=0)
else:
# the "offset_text" is something like "+0500" or "-0130"
timestamp_string, offset_text = datestring[:-5], datestring[-5:]
offset_minutes = int(offset_text[1:3]) * 60 + int(offset_text[3:])
if offset_text.startswith("+"):
pass
elif offset_text.startswith("-"):
offset_minutes *= -1
else:
# invalid format
return None
time_delta = datetime.timedelta(minutes=offset_minutes)
local_time = datetime.datetime.strptime(timestamp_string, "%Y-%m-%dT%H:%M:%S")
return local_time + time_delta
def get_iso8601_age_days(datestring):
now = datetime.datetime.now()
timestamp = parse_iso8601(datestring)
if timestamp:
return (now - timestamp).total_seconds() / (24 * 60 * 60)
else:
return None
def _get_json_statistics():
with urllib.request.urlopen(status_url) as conn:
json_body = conn.read()
return json.loads(json_body.decode("utf-8"))
def get_sources():
sources = []
for source in _get_json_statistics()["icestats"]["source"]:
path_name = source["listenurl"].split("/")[-1]
sources.append({"name": path_name,
"fieldname": clean_fieldname(path_name),
"listeners": source["listeners"],
"duration_days": get_iso8601_age_days(source["stream_start_iso8601"])})
sources.sort(key=lambda item: item["name"])
return sources
def get_server_uptime_days():
return get_iso8601_age_days(_get_json_statistics()["icestats"]["server_start_iso8601"])
def get_scope():
called_name = os.path.basename(sys.argv[0])
if called_name.startswith(PLUGIN_NAME_PREFIX):
scope = called_name[len(PLUGIN_NAME_PREFIX):]
if not scope in PLUGIN_SCOPES:
print("Invalid scope requested: {0} (expected: {1})".format(scope, "/".join(PLUGIN_SCOPES)), file=sys.stderr)
sys.exit(2)
else:
print("Invalid filename - failed to discover plugin scope", file=sys.stderr)
sys.exit(2)
return scope
if __name__ == "__main__":
action = sys.argv[1] if (len(sys.argv) > 1) else None
if action == "autoconf":
try:
get_sources()
print("yes")
except OSError:
print("no")
elif action == "suggest":
for scope in PLUGIN_SCOPES:
print(scope)
elif action == "config":
scope = get_scope()
if scope == "sources_listeners":
print("graph_title Total number of listeners")
print("graph_vlabel listeners")
print("graph_category streaming")
for index, source in enumerate(get_sources()):
print("{0}.label {1}".format(source["fieldname"], source["name"]))
print("{0}.draw {1}".format(source["fieldname"], ("AREA" if (index == 0) else "STACK")))
elif scope == "sources_duration":
print("graph_title Duration of sources")
print("graph_vlabel duration in days")
print("graph_category streaming")
for source in get_sources():
print("{0}.label {1}".format(source["fieldname"], source["name"]))
elif scope == "service_uptime":
print("graph_title Icecast service uptime")
print("graph_vlabel uptime in days")
print("graph_category streaming")
print("uptime.label service uptime")
elif action is None:
scope = get_scope()
if scope == "sources_listeners":
for source in get_sources():
print("{0}.value {1}".format(source["fieldname"], source["listeners"]))
elif scope == "sources_duration":
for source in get_sources():
print("{0}.value {1}".format(source["fieldname"], source["duration_days"] or 0))
elif scope == "service_uptime":
print("uptime.value {0}".format(get_server_uptime_days()))
else:
print("Invalid argument given: {0}".format(action), file=sys.stderr)
sys.exit(1)
sys.exit(0)

181
plugins/icecast/icecast_ Executable file
View file

@ -0,0 +1,181 @@
#!/usr/bin/env python2.5
"""
Plugin to monitor icecast2 streaming servers.
Author: Markus Lindenberg <markus.lindenberg@gmail.com>
COntributors: Julien 'Lta' BALLET <elthariel@gmail.com>
Version: 2009111101
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, either version 3 of the License, or
(at your option) any later version.
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, see <http://www.gnu.org/licenses/>.
Usage:
- Link or copy to /etc/munin/plugins
- To enable listening duration, traffic and uptime stats,
also link to icecast_duration, icecast_traffic and
icecast_uptime respectively.
Configuration:
- Enter your server, user and pw below
(The plugin does not need to run on
the same host as your icecast2 server)
- Optionally provide hosts to exclude.
- Optionally provide sources to exclude.
Possible TODOs:
- use autoconf
- use munin's configuration system
- documentation
"""
# CONFIGURATION
server = "localhost:8000"
user = "admin"
pw = "yourpassword"
# Exclude these hosts when calculating listening duration / listeners count
# (we use this to prevent our aircheck recording system from appearing in the stats)
#exclude = ("123.123.123.123",)
exclude = ()
# Exclude these sources from calculation. This is useful to excluse special sources like
# fallback sources which doesn't expose the same informations and then break this script
# Ever add fallback sources to this list
#source_exclude = ["/fallback.mp3", "/fallback.ogg"]
source_exclude = ("/fallback.mp3", "/fallback.ogg")
# /CONFIGURATION
from sys import argv, exit, stderr
import urllib
from xml.etree.ElementTree import ElementTree
from os.path import basename
class IcecastURLopener(urllib.FancyURLopener):
def prompt_user_passwd(self, host, realm):
return (user, pw)
opener = IcecastURLopener()
f = opener.open("http://%s/admin/listmounts" % server)
tree = ElementTree()
tree.parse(f)
f.close()
sources = []
for s in tree.getiterator("source"):
if s.attrib["mount"] not in source_exclude:
sources.append({"mount": s.attrib["mount"],
"listeners": s.find("listeners").text,
"connected": s.find("Connected").text})
plugin_name = basename(argv[0])
try:
if argv[1] == "config":
if plugin_name == "icecast_duration":
print "graph_title Icecast client listening duration"
print "graph_args --base 1000 -l 0"
print "graph_scale no"
print "graph_category streaming"
print "graph_vlabel minutes"
print "avg.label average listening duration"
print "mdn.label median listening duration"
elif plugin_name == "icecast_uptime":
print "graph_title Icecast source uptime"
print "graph_args --base 1000 -l 0"
print "graph_scale no"
print "graph_category streaming"
print "graph_vlabel hours"
for s in sources:
print "%s.label source %s" % (s["mount"].strip("/").replace(".","_").replace("-","_"), s["mount"])
elif plugin_name == "icecast_traffic":
print "graph_title Icecast outgoing traffic"
print "graph_args --base 1024 -l 0"
print "graph_category streaming"
print "graph_vlabel bytes / second"
is_first = True
for s in sources:
sname = s["mount"].strip("/").replace(".","_").replace("-","_")
print "%s.label source %s" % (sname, s["mount"])
print "%s.type DERIVE" % sname
print "%s.min 0" % sname
if is_first:
print "%s.draw AREA" % sname
is_first = False
else:
print "%s.draw STACK" % sname
else:
print "graph_title Icecast listeners count"
print "graph_args --base 1000 -l 0"
print "graph_scale no"
print "graph_category streaming"
print "graph_vlabel listeners"
is_first = True
for s in sources:
sname = s["mount"].strip("/").replace(".","_").replace("-","_")
print "%s.label source %s" % (sname, s["mount"])
if is_first:
print "%s.draw AREA" % sname
is_first = False
else:
print "%s.draw STACK" % sname
exit(0)
except IndexError:
pass
if plugin_name == "icecast_uptime":
for s in sources:
print "%s.value %s" % (s["mount"].strip("/").replace(".","_").replace("-","_"), int(s["connected"]) / 3600.)
elif plugin_name == "icecast_traffic":
f = opener.open("http://%s/admin/stats.xml" % server)
tree = ElementTree()
tree.parse(f)
f.close()
for s in tree.getiterator("source"):
print "%s.value %s" % (s.attrib["mount"].strip("/").replace(".","_").replace("-","_"), s.find("total_bytes_sent").text)
else:
durations = {}
for s in sources:
durations[s["mount"]] = []
f = opener.open("http://%s/admin/listclients?mount=%s" % (server, s["mount"]))
tree = ElementTree()
tree.parse(f)
f.close()
for l in tree.getiterator("listener"):
if l.find("IP").text not in exclude:
durations[s["mount"]].append(int(l.find("Connected").text))
if plugin_name == "icecast_duration":
if not durations:
exit(0)
alldurations = reduce(lambda x, y: x+y, durations.values())
alldurations.sort()
print "avg.value %s" % (sum(alldurations) / float(len(alldurations)) / 60.,)
if len(alldurations) % 2:
median = alldurations[len(alldurations) / 2] / 60.
elif len(alldurations):
median = (alldurations[len(alldurations) / 2 - 1] + alldurations[len(alldurations) / 2]) / 2. / 60.
else:
median = 0
print "mdn.value %s" % median
else:
for s in sources:
print "%s.value %s" % (s["mount"].strip("/").replace(".","_").replace("-","_"), len(durations[s["mount"]]))