root / plugins / wowza / wowza-media-server @ 17f78427
Historique | Voir | Annoter | Télécharger (15,7 ko)
| 1 |
#!/usr/bin/python |
|---|---|
| 2 |
""" |
| 3 |
Plugin to monitor Wowza streaming servers. |
| 4 |
|
| 5 |
Author: Srijan Choudhary <srijan4@gmail.com> |
| 6 |
Version: 2011031507 |
| 7 |
|
| 8 |
This program is free software: you can redistribute it and/or modify |
| 9 |
it under the terms of the GNU General Public License as published by |
| 10 |
the Free Software Foundation, either version 3 of the License, or |
| 11 |
(at your option) any later version. |
| 12 |
|
| 13 |
This program is distributed in the hope that it will be useful, |
| 14 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
GNU General Public License for more details. |
| 17 |
|
| 18 |
You should have received a copy of the GNU General Public License |
| 19 |
along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 |
|
| 21 |
Usage: |
| 22 |
- Link or copy to /etc/munin/plugins |
| 23 |
- To enable extra graphs, also link to one or more of the |
| 24 |
possible links (given below) |
| 25 |
- Then restart munin-node |
| 26 |
|
| 27 |
Links possible: |
| 28 |
<default> total number of listeners in wowza |
| 29 |
wowza_duration duration of listeners (avg and mdn) |
| 30 |
|
| 31 |
wowza_vhost_listeners number of listeners per vhost |
| 32 |
wowza_vhost_duration duration of listeners per vhost |
| 33 |
wowza_vhost_uptime uptime of vhosts |
| 34 |
|
| 35 |
wowza_app_listeners number of listeners per application |
| 36 |
wowza_app_duration duration of listeners per application |
| 37 |
wowza_app_uptime uptime of applications |
| 38 |
|
| 39 |
Configuration: |
| 40 |
- Enter your server, username, and password below |
| 41 |
(The plugin does not need to run on the same host |
| 42 |
as the Wowza media server) |
| 43 |
- Optionally provide clients to exclude |
| 44 |
- Optionally provide apps to exclude |
| 45 |
- Optionally provide vhosts to exclude |
| 46 |
|
| 47 |
Possible TODOs: |
| 48 |
- use autoconf |
| 49 |
- use munin's configuration system |
| 50 |
|
| 51 |
""" |
| 52 |
from __future__ import print_function |
| 53 |
from sys import argv, exit, stderr |
| 54 |
import urllib2 |
| 55 |
from xml.etree.ElementTree import ElementTree |
| 56 |
from os.path import basename |
| 57 |
|
| 58 |
# CONFIGURATION |
| 59 |
|
| 60 |
server = "127.0.0.1:8086" |
| 61 |
user = "admin" |
| 62 |
pw = "password" |
| 63 |
|
| 64 |
# Exclude these in all calculations |
| 65 |
client_exclude = ("127.0.0.1")
|
| 66 |
app_exclude = ("testapp")
|
| 67 |
vhost_exclude = ("testhost")
|
| 68 |
|
| 69 |
# /CONFIGURATION |
| 70 |
|
| 71 |
url = "http://%s/serverinfo" %server |
| 72 |
|
| 73 |
passman = urllib2.HTTPPasswordMgrWithDefaultRealm() |
| 74 |
passman.add_password(None, url, user, pw) |
| 75 |
authhandler = urllib2.HTTPDigestAuthHandler(passman) |
| 76 |
|
| 77 |
opener = urllib2.build_opener(authhandler) |
| 78 |
urllib2.install_opener(opener) |
| 79 |
f = urllib2.urlopen(url) |
| 80 |
|
| 81 |
tree = ElementTree() |
| 82 |
tree.parse(f) |
| 83 |
f.close() |
| 84 |
|
| 85 |
vhosts = [] |
| 86 |
for vh in tree.findall("VHost"):
|
| 87 |
if vh.find("Name").text not in vhost_exclude:
|
| 88 |
applications = [] |
| 89 |
for app in vh.findall("Application"):
|
| 90 |
if app.find("Name").text not in app_exclude:
|
| 91 |
if app.find("Status").text == "loaded":
|
| 92 |
clients = [] |
| 93 |
for client in app.findall("Client"):
|
| 94 |
if client.find("IpAddress").text not in client_exclude:
|
| 95 |
clients.append({"ClientId": client.find("ClientId").text,
|
| 96 |
"FlashVersion": client.find("FlashVersion").text,
|
| 97 |
"IpAddress": client.find("IpAddress").text,
|
| 98 |
"TimeRunning": float(client.find("TimeRunning").text),
|
| 99 |
"DateStarted": client.find("DateStarted").text,
|
| 100 |
"URI": client.find("URI").text,
|
| 101 |
"Protocol": client.find("Protocol").text,
|
| 102 |
"IsSSL": client.find("IsSSL").text,
|
| 103 |
"IsEncrypted": client.find("IsEncrypted").text,
|
| 104 |
"Port": client.find("Port").text
|
| 105 |
}) |
| 106 |
applications.append({"Name": app.find("Name").text,
|
| 107 |
"Status": app.find("Status").text,
|
| 108 |
"TimeRunning": float(app.find("TimeRunning").text),
|
| 109 |
"ConnectionsCurrent" : app.find("ConnectionsCurrent").text,
|
| 110 |
"ConnectionsTotal": app.find("ConnectionsTotal").text,
|
| 111 |
"ConnectionsTotalAccepted" : app.find("ConnectionsTotalAccepted").text,
|
| 112 |
"ConnectionsTotalRejected" : app.find("ConnectionsTotalRejected").text,
|
| 113 |
"Clients": clients}) |
| 114 |
else: |
| 115 |
applications.append({"Name": app.find("Name").text,
|
| 116 |
"Status": app.find("Status").text,
|
| 117 |
"TimeRunning": float(0), |
| 118 |
"ConnectionsCurrent" : 0, |
| 119 |
"ConnectionsTotal": 0, |
| 120 |
"ConnectionsTotalAccepted" : 0, |
| 121 |
"ConnectionsTotalRejected" : 0, |
| 122 |
"Clients": []}) |
| 123 |
vhosts.append({"Name": vh.find("Name").text,
|
| 124 |
"TimeRunning": float(vh.find("TimeRunning").text),
|
| 125 |
"ConnectionsLimit": vh.find("ConnectionsLimit").text,
|
| 126 |
"ConnectionsCurrent" : vh.find("ConnectionsCurrent").text,
|
| 127 |
"ConnectionsTotal": vh.find("ConnectionsTotal").text,
|
| 128 |
"ConnectionsTotalAccepted" : vh.find("ConnectionsTotalAccepted").text,
|
| 129 |
"ConnectionsTotalRejected" : vh.find("ConnectionsTotalRejected").text,
|
| 130 |
"Applications": applications}) |
| 131 |
|
| 132 |
plugin_name = basename(argv[0]) |
| 133 |
|
| 134 |
try: |
| 135 |
if argv[1] == "config": |
| 136 |
if plugin_name == "wowza_duration": |
| 137 |
print ("graph_title Wowza clients listening duration")
|
| 138 |
print ("graph_args --base 1000 -l 0")
|
| 139 |
print ("graph_scale no")
|
| 140 |
print ("graph_category streaming")
|
| 141 |
print ("graph_vlabel minutes")
|
| 142 |
print ("avg.label average listening duration")
|
| 143 |
print ("mdn.label median listening duration")
|
| 144 |
|
| 145 |
elif plugin_name == "wowza_vhost_listeners": |
| 146 |
print ("graph_title Wowza listeners count by vhosts")
|
| 147 |
print ("graph_args --base 1000 -l 0")
|
| 148 |
print ("graph_scale no")
|
| 149 |
print ("graph_category streaming")
|
| 150 |
print ("graph_vlabel listeners")
|
| 151 |
is_first = True |
| 152 |
for vh in vhosts: |
| 153 |
vname = vh["Name"].strip("/").replace(".","_").replace("-","_")
|
| 154 |
print (vname,".label vhost: ",vh["Name"],sep='') |
| 155 |
if is_first: |
| 156 |
print (vname,".draw AREA",sep='') |
| 157 |
is_first = False |
| 158 |
else: |
| 159 |
print (vname,".draw STACK",sep='') |
| 160 |
|
| 161 |
elif plugin_name == "wowza_vhost_duration": |
| 162 |
print ("graph_title Wowza clients listening duration by vhosts")
|
| 163 |
print ("graph_args --base 1000 -l 0")
|
| 164 |
print ("graph_scale no")
|
| 165 |
print ("graph_category streaming")
|
| 166 |
print ("graph_vlabel minutes")
|
| 167 |
for vh in vhosts: |
| 168 |
vname = vh["Name"].strip("/").replace(".","_").replace("-","_")
|
| 169 |
print (vname,"_avg.label average listening duration for ",vh["Name"],sep='') |
| 170 |
print (vname,"_mdn.label median listening duration for ",vh["Name"],sep='') |
| 171 |
|
| 172 |
elif plugin_name == "wowza_vhost_uptime": |
| 173 |
print ("graph_title Wowza vhosts uptime")
|
| 174 |
print ("graph_args --base 1000 -l 0")
|
| 175 |
print ("graph_scale no")
|
| 176 |
print ("graph_category streaming")
|
| 177 |
print ("graph_vlabel hours")
|
| 178 |
for vh in vhosts: |
| 179 |
vname = vh["Name"].strip("/").replace(".","_").replace("-","_")
|
| 180 |
print (vname,".label vhost: ",vh["Name"],sep='') |
| 181 |
|
| 182 |
elif plugin_name == "wowza_app_listeners": |
| 183 |
print ("graph_title Wowza listeners count by apps")
|
| 184 |
print ("graph_args --base 1000 -l 0")
|
| 185 |
print ("graph_scale no")
|
| 186 |
print ("graph_category streaming")
|
| 187 |
print ("graph_vlabel listeners")
|
| 188 |
is_first = True |
| 189 |
for vh in vhosts: |
| 190 |
vname = vh["Name"].strip("/").replace(".","_").replace("-","_")
|
| 191 |
for app in vh["Applications"]: |
| 192 |
aname = app["Name"].strip("/").replace(".","_").replace("-","_")
|
| 193 |
print (vname,"_",aname,".label vhost.app: ",vh["Name"],".",app["Name"],sep='') |
| 194 |
if is_first: |
| 195 |
print (vname,"_",aname,".draw AREA",sep='') |
| 196 |
is_first = False |
| 197 |
else: |
| 198 |
print (vname,"_",aname,".draw STACK",sep='') |
| 199 |
|
| 200 |
elif plugin_name == "wowza_app_duration": |
| 201 |
print ("graph_title Wowza clients listening duration by apps")
|
| 202 |
print ("graph_args --base 1000 -l 0")
|
| 203 |
print ("graph_scale no")
|
| 204 |
print ("graph_category streaming")
|
| 205 |
print ("graph_vlabel minutes")
|
| 206 |
for vh in vhosts: |
| 207 |
vname = vh["Name"].strip("/").replace(".","_").replace("-","_")
|
| 208 |
for app in vh["Applications"]: |
| 209 |
aname = app["Name"].strip("/").replace(".","_").replace("-","_")
|
| 210 |
print (vname,"_",aname,"_avg.label average listening duration for ",vh["Name"],".",app["Name"],sep='') |
| 211 |
print (vname,"_",aname,"_mdn.label median listening duration for ",vh["Name"],".",app["Name"],sep='') |
| 212 |
|
| 213 |
elif plugin_name == "wowza_app_uptime": |
| 214 |
print ("graph_title Wowza apps uptime")
|
| 215 |
print ("graph_args --base 1000 -l 0")
|
| 216 |
print ("graph_scale no")
|
| 217 |
print ("graph_category streaming")
|
| 218 |
print ("graph_vlabel hours")
|
| 219 |
for vh in vhosts: |
| 220 |
vname = vh["Name"].strip("/").replace(".","_").replace("-","_")
|
| 221 |
for app in vh["Applications"]: |
| 222 |
aname = app["Name"].strip("/").replace(".","_").replace("-","_")
|
| 223 |
print (vname,"_",aname,".label vhost.app: ",vh["Name"],".",app["Name"],sep='') |
| 224 |
|
| 225 |
else: # wowza_listeners |
| 226 |
print ("graph_title Wowza listeners count")
|
| 227 |
print ("graph_args --base 1000 -l 0")
|
| 228 |
print ("graph_scale no")
|
| 229 |
print ("graph_category streaming")
|
| 230 |
print ("graph_vlabel listeners")
|
| 231 |
print ("wowza_listeners.label Total Listeners")
|
| 232 |
print ("wowza_listeners.draw AREA")
|
| 233 |
pass |
| 234 |
exit(0) |
| 235 |
|
| 236 |
except IndexError: |
| 237 |
pass |
| 238 |
|
| 239 |
if plugin_name == "wowza_duration": |
| 240 |
alldurations = [] |
| 241 |
for vh in vhosts: |
| 242 |
for app in vh["Applications"]: |
| 243 |
for client in app["Clients"]: |
| 244 |
alldurations.append(client["TimeRunning"]) |
| 245 |
alldurations.sort() |
| 246 |
if len(alldurations) == 0: |
| 247 |
average = 0 |
| 248 |
else: |
| 249 |
average = (sum(alldurations) / float(len(alldurations)) / 60.) |
| 250 |
print ("avg.value ",average,sep='')
|
| 251 |
if len(alldurations) % 2: |
| 252 |
median = alldurations[len(alldurations) / 2] / 60. |
| 253 |
elif len(alldurations): |
| 254 |
median = (alldurations[len(alldurations) / 2 - 1] + alldurations[len(alldurations) / 2]) / 2. / 60. |
| 255 |
else: |
| 256 |
median = 0 |
| 257 |
print ("mdn.value ",median,sep='')
|
| 258 |
|
| 259 |
elif plugin_name == "wowza_vhost_listeners": |
| 260 |
for vh in vhosts: |
| 261 |
print (vh["Name"].strip("/").replace(".","_").replace("-","_"),".value ",vh["ConnectionsCurrent"],sep='')
|
| 262 |
|
| 263 |
elif plugin_name == "wowza_vhost_duration": |
| 264 |
alldurations = {}
|
| 265 |
for vh in vhosts: |
| 266 |
vname = vh["Name"].strip("/").replace(".","_").replace("-","_")
|
| 267 |
alldurations[vh["Name"]] = [] |
| 268 |
for app in vh["Applications"]: |
| 269 |
for client in app["Clients"]: |
| 270 |
alldurations[vh["Name"]].append(client["TimeRunning"]) |
| 271 |
alldurations[vh["Name"]].sort() |
| 272 |
if len(alldurations[vh["Name"]]) == 0: |
| 273 |
average = 0 |
| 274 |
else: |
| 275 |
average = (sum(alldurations[vh["Name"]]) / float(len(alldurations[vh["Name"]])) / 60.) |
| 276 |
print (vname,"_avg.value ",average,sep='') |
| 277 |
if len(alldurations[vh["Name"]]) % 2: |
| 278 |
median = alldurations[vh["Name"]][len(alldurations[vh["Name"]]) / 2] / 60. |
| 279 |
elif len(alldurations): |
| 280 |
median = (alldurations[vh["Name"]][len(alldurations[vh["Name"]]) / 2 - 1] + alldurations[vh["Name"]][len(alldurations[vh["Name"]]) / 2]) / 2. / 60. |
| 281 |
else: |
| 282 |
median = 0 |
| 283 |
print (vname,"_mdn.value ",median,sep='') |
| 284 |
|
| 285 |
elif plugin_name == "wowza_vhost_uptime": |
| 286 |
for vh in vhosts: |
| 287 |
print (vh["Name"].strip("/").replace(".","_").replace("-","_"),".value ",vh["TimeRunning"]/3600.,sep='')
|
| 288 |
|
| 289 |
elif plugin_name == "wowza_app_listeners": |
| 290 |
for vh in vhosts: |
| 291 |
for app in vh["Applications"]: |
| 292 |
print (vh["Name"].strip("/").replace(".","_").replace("-","_"),"_",app["Name"].strip("/").replace(".","_").replace("-","_"),".value ",app["ConnectionsCurrent"],sep='')
|
| 293 |
|
| 294 |
elif plugin_name == "wowza_app_duration": |
| 295 |
alldurations = {}
|
| 296 |
for vh in vhosts: |
| 297 |
vname = vh["Name"].strip("/").replace(".","_").replace("-","_")
|
| 298 |
for app in vh["Applications"]: |
| 299 |
aname = app["Name"].strip("/").replace(".","_").replace("-","_")
|
| 300 |
name = ''.join([vname,'_',aname]) |
| 301 |
alldurations[name] = [] |
| 302 |
for client in app["Clients"]: |
| 303 |
alldurations[name].append(client["TimeRunning"]) |
| 304 |
alldurations[name].sort() |
| 305 |
if len(alldurations[name]) == 0: |
| 306 |
average = 0 |
| 307 |
else: |
| 308 |
average = (sum(alldurations[name]) / float(len(alldurations[name])) / 60.) |
| 309 |
print (name,"_avg.value ",average,sep='') |
| 310 |
if len(alldurations[name]) % 2: |
| 311 |
median = alldurations[name][len(alldurations[name]) / 2] / 60. |
| 312 |
elif len(alldurations): |
| 313 |
median = (alldurations[name][len(alldurations[name]) / 2 - 1] + alldurations[name][len(alldurations[name]) / 2]) / 2. / 60. |
| 314 |
else: |
| 315 |
median = 0 |
| 316 |
print (name,"_mdn.value ",median,sep='') |
| 317 |
|
| 318 |
elif plugin_name == "wowza_app_uptime": |
| 319 |
for vh in vhosts: |
| 320 |
for app in vh["Applications"]: |
| 321 |
print (vh["Name"].strip("/").replace(".","_").replace("-","_"),"_",app["Name"].strip("/").replace(".","_").replace("-","_"),".value ",app["TimeRunning"]/3600.,sep='')
|
| 322 |
|
| 323 |
else: # wowza_listeners |
| 324 |
listeners = 0 |
| 325 |
for vh in vhosts: |
| 326 |
listeners += int(vh["ConnectionsCurrent"]) |
| 327 |
print ("wowza_listeners.value ",listeners,sep='')
|
