root / plugins / streaming / icecast2_all @ 430d68ff
Historique | Voir | Annoter | Télécharger (2,45 ko)
| 1 | 8c5cea31 | Andreas Bergstr?m | #! /usr/bin/python |
|---|---|---|---|
| 2 | # -*- coding: iso-8859-1 -*- |
||
| 3 | |||
| 4 | # Hostname of Icecast server |
||
| 5 | # Just canonical name, no http:// nor ending / |
||
| 6 | host = "foo.bar.com" |
||
| 7 | username = "admin" |
||
| 8 | # Password for admin access to Icecast2 server to fetch statistics |
||
| 9 | password = "" |
||
| 10 | realm = "Icecast2 Server" |
||
| 11 | |||
| 12 | # This plugin shows the statistics of every source currently connected to the Icecast2 server. See the Icecast2_ plugin for specific mountpoint plugin. |
||
| 13 | |||
| 14 | import urllib2, os.path, time, sys |
||
| 15 | from xml.dom import minidom |
||
| 16 | |||
| 17 | def hent_XML(): |
||
| 18 | auth_handler = urllib2.HTTPBasicAuthHandler() |
||
| 19 | auth_handler.add_password(realm, host, username, password) |
||
| 20 | opener = urllib2.build_opener(auth_handler) |
||
| 21 | urllib2.install_opener(opener) |
||
| 22 | |||
| 23 | xmlweb = urllib2.urlopen("http://%s/admin/stats" % host)
|
||
| 24 | xml = xmlweb.read() |
||
| 25 | xmlweb.close() |
||
| 26 | |||
| 27 | # Parser oversikt |
||
| 28 | |||
| 29 | xmldoc = minidom.parseString(xml) |
||
| 30 | xmldoc = xmldoc.firstChild |
||
| 31 | |||
| 32 | #Totalt antall lyttere |
||
| 33 | total_lyttere = xmldoc.getElementsByTagName("clients")[0].firstChild.nodeValue
|
||
| 34 | #Totalt antall kilder |
||
| 35 | total_kilder = xmldoc.getElementsByTagName("sources")[0].firstChild.nodeValue
|
||
| 36 | #Status for enkelt str?m |
||
| 37 | sources = xmldoc.getElementsByTagName("source")
|
||
| 38 | sourcelist = {}
|
||
| 39 | for source in sources: |
||
| 40 | mount = source.getAttribute("mount")
|
||
| 41 | listeners = source.getElementsByTagName("listeners")[0].firstChild.nodeValue
|
||
| 42 | name = source.getElementsByTagName("server_name")[0].firstChild.nodeValue
|
||
| 43 | mount = mount.replace("-", "_").replace(".", "_")
|
||
| 44 | sourcelist[mount[1:]] = (listeners, name) |
||
| 45 | |||
| 46 | if len(sys.argv) > 0 and sys.argv[1] == "autoconf": |
||
| 47 | print "yes" |
||
| 48 | elif len(sys.argv) == 1 or sys.argv[1] != "config": |
||
| 49 | print "totallyttere.value %s" % total_lyttere |
||
| 50 | print "totalkilder.value %s" % total_kilder |
||
| 51 | sourcesort = sourcelist.keys() |
||
| 52 | sourcesort.sort() |
||
| 53 | for source in sourcesort: |
||
| 54 | listeners, name = sourcelist[source] |
||
| 55 | print "%s.value %s" % (source, listeners) |
||
| 56 | elif sys.argv[1] == "config": |
||
| 57 | print "graph_title Total number of listeners" |
||
| 58 | print "graph_vlabel listeners" |
||
| 59 | print "graph_category Icecast" |
||
| 60 | print "totallyttere.label Total number of listeners" |
||
| 61 | print "totalkilder.label Totalt number of sources" |
||
| 62 | sourcesort = sourcelist.keys() |
||
| 63 | sourcesort.sort() |
||
| 64 | for source in sourcesort: |
||
| 65 | listeners, name = sourcelist[source] |
||
| 66 | print "%s.label %s" % (source, "/" + source) |
||
| 67 | else: |
||
| 68 | print sys.argv[1] |
||
| 69 | |||
| 70 | |||
| 71 | if __name__ == "__main__": |
||
| 72 | hent_XML() |
