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