1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-22 02:51:03 +00:00

More housekeeping.

This commit is contained in:
Diego Elio Pettenò 2012-08-06 22:20:20 -07:00
parent 038c3ce96b
commit e5ce74926d
43 changed files with 0 additions and 0 deletions

View file

@ -1,153 +0,0 @@
#! /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 Icecast"
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 Icecast"
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

@ -1,72 +0,0 @@
#! /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 Icecast"
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()

View file

@ -1,70 +0,0 @@
#!/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 Icecast"
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

View file

@ -1,181 +0,0 @@
#!/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 usefull 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 Icecast"
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 Icecast"
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 Icecast"
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 Icecast"
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"]]))