Advertisement
Guest User

Script

a guest
Aug 29th, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.08 KB | None | 0 0
  1. #!/usr/bin/env python
  2. import sys
  3. import os
  4. import urllib2
  5. import commands
  6.  
  7. from xml.dom.minidom import parseString
  8.  
  9. print "Content-Type: text/plain;charset=utf-8"     # HTML is following
  10. print                               # blank line, end of headers
  11.  
  12. #Load the XML from Wowza host.
  13. def loadxml(host, username, password):
  14. #    url = 'http://' + host + ':8086/connectioncounts'
  15.     url = 'http://' + host + ':1935/connectioncounts'
  16.     mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
  17.     mgr.add_password(None,url,username,password)
  18.  
  19.     opener = urllib2.build_opener(urllib2.HTTPBasicAuthHandler(mgr), urllib2.HTTPDigestAuthHandler(mgr))
  20.  
  21.     urllib2.install_opener(opener)
  22.  
  23.     try:
  24.         f = urllib2.urlopen(url)
  25.         return f.read()
  26.     except:
  27.                 return ''
  28.  
  29. #Set default variables.
  30. _host = ''
  31. _host2 = ''
  32. _username = ''
  33. _password = ''
  34.  
  35. #Set variables through command line arguments.
  36. if len(sys.argv) > 1:
  37.     _host = sys.argv[1]
  38. if len(sys.argv) > 2:
  39.     _username = sys.argv[2]
  40. if len(sys.argv) > 3:
  41.     _password = sys.argv[3]
  42.  
  43. _xml = loadxml(_host, _username, _password)
  44. _xml2 = loadxml(_host2, _username, _password)
  45.  
  46. dom = parseString(_xml)
  47. dom2 = parseString(_xml2)
  48.  
  49.  
  50.  
  51. ## Get some stats
  52. Wowza1ConnCur = dom.getElementsByTagName('ConnectionsCurrent')
  53. Wowza1ConnAccepted = dom.getElementsByTagName('ConnectionsTotalAccepted')
  54. Wowza1ConnRejected = dom.getElementsByTagName('ConnectionsTotalRejected')
  55. Wowza1InBytes = dom.getElementsByTagName('MessagesInBytesRate')
  56. Wowza1OutBytes = dom.getElementsByTagName('MessagesOutBytesRate')
  57.  
  58. Wowza2ConnCur = dom2.getElementsByTagName('ConnectionsCurrent')
  59. Wowza2ConnAccepted = dom2.getElementsByTagName('ConnectionsTotalAccepted')
  60. Wowza2ConnRejected = dom2.getElementsByTagName('ConnectionsTotalRejected')
  61. Wowza2InBytes = dom2.getElementsByTagName('MessagesInBytesRate')
  62. Wowza2OutBytes = dom2.getElementsByTagName('MessagesOutBytesRate')
  63.  
  64. GlobalConn = int(Wowza1ConnCur[0].firstChild.nodeValue) + int(Wowza2ConnCur[0].firstChild.nodeValue)
  65. GlobalConn = str(GlobalConn)
  66. GlobalAccepted = int(Wowza1ConnAccepted[0].firstChild.nodeValue) + int(Wowza2ConnAccepted[0].firstChild.nodeValue)
  67. GlobalAccepted = str(GlobalAccepted)
  68. GlobalRejected = int(Wowza1ConnRejected[0].firstChild.nodeValue) + int(Wowza2ConnRejected[0].firstChild.nodeValue)
  69. GlobalRejected = str(GlobalRejected)
  70. GlobalInBytes = float(Wowza1InBytes[0].firstChild.nodeValue) + float(Wowza2InBytes[0].firstChild.nodeValue) / 1024
  71. GlobalInMBytes = str(GlobalInBytes)
  72. GlobalOutBytes = float(Wowza1OutBytes[0].firstChild.nodeValue) + float(Wowza2OutBytes[0].firstChild.nodeValue) / 1024
  73. GlobalOutMBytes = str(GlobalOutBytes)
  74.  
  75.  
  76. print "Global Active Conn: " + GlobalConn   +\
  77.       "     Wowza1 Active Conn: " + Wowza1ConnCur[0].firstChild.nodeValue +\
  78.       "     Wowza2 Active Conn: " + Wowza2ConnCur[0].firstChild.nodeValue
  79. print "Global Accepted Conn: " + GlobalAccepted + \
  80.       "     Wowza1 Accepted Conn: " + Wowza1ConnAccepted[0].firstChild.nodeValue +\
  81.       "     Wowza2 Accepted Conn: " + Wowza2ConnAccepted[0].firstChild.nodeValue
  82. print "Global Rejected Connt: " + GlobalRejected +\
  83.       "     Wowza1 Rejected Conn: " + Wowza1ConnRejected[0].firstChild.nodeValue +\
  84.       "         Wowza2 Rejected Conn: " + Wowza2ConnRejected[0].firstChild.nodeValue
  85. print "Global in mb/s: " + GlobalInMBytes + \
  86.       "     Wowza1 IN Bytes/s: " + Wowza1InBytes[0].firstChild.nodeValue +\
  87.       "         Wowza2 IN Bytes/s: " + Wowza2InBytes[0].firstChild.nodeValue
  88. print "Global out mb/s: " + GlobalOutMBytes +\
  89.       "     Wowza1 OUT Bytes/s: " + Wowza1OutBytes[0].firstChild.nodeValue +\
  90.       "     Wowza2 OUT Bytes/s: " + Wowza2OutBytes[0].firstChild.nodeValue
  91.  
  92. # Loop through the stream applications and print stream info
  93.  
  94. applications = dom.getElementsByTagName('Application') + dom2.getElementsByTagName('Application')
  95.  
  96. for apps in applications:
  97.     AppName = apps.getElementsByTagName('Name')
  98.     ConnConnect = apps.getElementsByTagName('ConnectionsCurrent')
  99.     AcceptConnect = apps.getElementsByTagName('ConnectionsTotalAccepted')
  100.     print
  101.     print "Application: "
  102.     print AppName[0].firstChild.nodeValue + " - Connected Clients: " + ConnConnect[0].firstChild.nodeValue
  103.     print "Active Streams:"
  104.     print
  105.  
  106.     streams = apps.getElementsByTagName('Stream')
  107.     for stream in streams:
  108.         StreamName = stream.getElementsByTagName('Name')
  109.         StreamConn = stream.getElementsByTagName('SessionsTotal')
  110.         Flash = stream.getElementsByTagName('SessionsFlash')
  111.         Cup = stream.getElementsByTagName('SessionsCupertino')
  112.         San = stream.getElementsByTagName('SessionsSanJose')
  113.         Smooth = stream.getElementsByTagName('SessionsSmooth')
  114.         Rtsp = stream.getElementsByTagName('SessionsRTSP')
  115.         Dash = stream.getElementsByTagName('SessionsMPEGDash')
  116.  
  117.         print StreamName[0].firstChild.nodeValue
  118.         print "Has " + StreamConn[0].firstChild.nodeValue + " clients watching. Flash:" + Flash[0].firstChild.nodeValue + \
  119.         " HLS:" + Cup[0].firstChild.nodeValue + " HDS:" + San[0].firstChild.nodeValue + " Smooth:" + \
  120.         Smooth[0].firstChild.nodeValue + " RTSP:" + Rtsp[0].firstChild.nodeValue + " Dash:" + \
  121.         Dash[0].firstChild.nodeValue
  122.         print
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement