Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import sys
- import os
- import urllib2
- import commands
- from xml.dom.minidom import parseString
- print "Content-Type: text/plain;charset=utf-8" # HTML is following
- print # blank line, end of headers
- #Load the XML from Wowza host.
- def loadxml(host, username, password):
- # url = 'http://' + host + ':8086/connectioncounts'
- url = 'http://' + host + ':1935/connectioncounts'
- mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
- mgr.add_password(None,url,username,password)
- opener = urllib2.build_opener(urllib2.HTTPBasicAuthHandler(mgr), urllib2.HTTPDigestAuthHandler(mgr))
- urllib2.install_opener(opener)
- try:
- f = urllib2.urlopen(url)
- return f.read()
- except:
- return ''
- #Set default variables.
- _host = ''
- _host2 = ''
- _username = ''
- _password = ''
- #Set variables through command line arguments.
- if len(sys.argv) > 1:
- _host = sys.argv[1]
- if len(sys.argv) > 2:
- _username = sys.argv[2]
- if len(sys.argv) > 3:
- _password = sys.argv[3]
- _xml = loadxml(_host, _username, _password)
- _xml2 = loadxml(_host2, _username, _password)
- dom = parseString(_xml)
- dom2 = parseString(_xml2)
- ## Get some stats
- Wowza1ConnCur = dom.getElementsByTagName('ConnectionsCurrent')
- Wowza1ConnAccepted = dom.getElementsByTagName('ConnectionsTotalAccepted')
- Wowza1ConnRejected = dom.getElementsByTagName('ConnectionsTotalRejected')
- Wowza1InBytes = dom.getElementsByTagName('MessagesInBytesRate')
- Wowza1OutBytes = dom.getElementsByTagName('MessagesOutBytesRate')
- Wowza2ConnCur = dom2.getElementsByTagName('ConnectionsCurrent')
- Wowza2ConnAccepted = dom2.getElementsByTagName('ConnectionsTotalAccepted')
- Wowza2ConnRejected = dom2.getElementsByTagName('ConnectionsTotalRejected')
- Wowza2InBytes = dom2.getElementsByTagName('MessagesInBytesRate')
- Wowza2OutBytes = dom2.getElementsByTagName('MessagesOutBytesRate')
- GlobalConn = int(Wowza1ConnCur[0].firstChild.nodeValue) + int(Wowza2ConnCur[0].firstChild.nodeValue)
- GlobalConn = str(GlobalConn)
- GlobalAccepted = int(Wowza1ConnAccepted[0].firstChild.nodeValue) + int(Wowza2ConnAccepted[0].firstChild.nodeValue)
- GlobalAccepted = str(GlobalAccepted)
- GlobalRejected = int(Wowza1ConnRejected[0].firstChild.nodeValue) + int(Wowza2ConnRejected[0].firstChild.nodeValue)
- GlobalRejected = str(GlobalRejected)
- GlobalInBytes = float(Wowza1InBytes[0].firstChild.nodeValue) + float(Wowza2InBytes[0].firstChild.nodeValue) / 1024
- GlobalInMBytes = str(GlobalInBytes)
- GlobalOutBytes = float(Wowza1OutBytes[0].firstChild.nodeValue) + float(Wowza2OutBytes[0].firstChild.nodeValue) / 1024
- GlobalOutMBytes = str(GlobalOutBytes)
- print "Global Active Conn: " + GlobalConn +\
- " Wowza1 Active Conn: " + Wowza1ConnCur[0].firstChild.nodeValue +\
- " Wowza2 Active Conn: " + Wowza2ConnCur[0].firstChild.nodeValue
- print "Global Accepted Conn: " + GlobalAccepted + \
- " Wowza1 Accepted Conn: " + Wowza1ConnAccepted[0].firstChild.nodeValue +\
- " Wowza2 Accepted Conn: " + Wowza2ConnAccepted[0].firstChild.nodeValue
- print "Global Rejected Connt: " + GlobalRejected +\
- " Wowza1 Rejected Conn: " + Wowza1ConnRejected[0].firstChild.nodeValue +\
- " Wowza2 Rejected Conn: " + Wowza2ConnRejected[0].firstChild.nodeValue
- print "Global in mb/s: " + GlobalInMBytes + \
- " Wowza1 IN Bytes/s: " + Wowza1InBytes[0].firstChild.nodeValue +\
- " Wowza2 IN Bytes/s: " + Wowza2InBytes[0].firstChild.nodeValue
- print "Global out mb/s: " + GlobalOutMBytes +\
- " Wowza1 OUT Bytes/s: " + Wowza1OutBytes[0].firstChild.nodeValue +\
- " Wowza2 OUT Bytes/s: " + Wowza2OutBytes[0].firstChild.nodeValue
- # Loop through the stream applications and print stream info
- applications = dom.getElementsByTagName('Application') + dom2.getElementsByTagName('Application')
- for apps in applications:
- AppName = apps.getElementsByTagName('Name')
- ConnConnect = apps.getElementsByTagName('ConnectionsCurrent')
- AcceptConnect = apps.getElementsByTagName('ConnectionsTotalAccepted')
- print
- print "Application: "
- print AppName[0].firstChild.nodeValue + " - Connected Clients: " + ConnConnect[0].firstChild.nodeValue
- print "Active Streams:"
- print
- streams = apps.getElementsByTagName('Stream')
- for stream in streams:
- StreamName = stream.getElementsByTagName('Name')
- StreamConn = stream.getElementsByTagName('SessionsTotal')
- Flash = stream.getElementsByTagName('SessionsFlash')
- Cup = stream.getElementsByTagName('SessionsCupertino')
- San = stream.getElementsByTagName('SessionsSanJose')
- Smooth = stream.getElementsByTagName('SessionsSmooth')
- Rtsp = stream.getElementsByTagName('SessionsRTSP')
- Dash = stream.getElementsByTagName('SessionsMPEGDash')
- print StreamName[0].firstChild.nodeValue
- print "Has " + StreamConn[0].firstChild.nodeValue + " clients watching. Flash:" + Flash[0].firstChild.nodeValue + \
- " HLS:" + Cup[0].firstChild.nodeValue + " HDS:" + San[0].firstChild.nodeValue + " Smooth:" + \
- Smooth[0].firstChild.nodeValue + " RTSP:" + Rtsp[0].firstChild.nodeValue + " Dash:" + \
- Dash[0].firstChild.nodeValue
- print
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement