Here’s the code for gathering Wowza Stats from a single server. This assumes that you’ve enabled the stats on Wowza (serverinfo, connectioncounts in VHost.xml HTTPProviders), with authentication turned off). You’ll also get better detailed stats if you use Andrew Kennedy’s CasterStats module for the serverinfo.
123456789101112131415<
HTTPProvider
>
<
BaseClass
>com.wowza.wms.plugin.test.HTTPServerInfo</
BaseClass
>
<
RequestFilters
>serverinfo*</
RequestFilters
>
<
AuthenticationMethod
>none</
AuthenticationMethod
>
</
HTTPProvider
>
<
HTTPProvider
>
<
BaseClass
>com.wowza.wms.http.HTTPConnectionInfo</
BaseClass
>
<
RequestFilters
>connectioninfo*</
RequestFilters
>
<
AuthenticationMethod
>none</
AuthenticationMethod
>
</
HTTPProvider
>
<
HTTPProvider
>
<
BaseClass
>com.wowza.wms.http.HTTPConnectionCountsXML</
BaseClass
>
<
RequestFilters
>connectioncounts*</
RequestFilters
>
<
AuthenticationMethod
>none</
AuthenticationMethod
>
</
HTTPProvider
>
PHP code:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265<?PHP
error_reporting
(0);
header(
"Content-type: text/html; charset=utf-8"
);
$detailed
= false;
$graph_load
= false;
$simple_load
= false;
$simple_count
= false;
$stream_count
= false;
$geo_count
= false;
$count
= false;
$load
= false;
$form
= true;
if
(isset(
$_GET
[
'server'
])) {
$repeater
=
$_GET
[
'server'
];
$form
= false;}
if
(isset(
$_GET
[
'mode'
])) {
switch
(
$_GET
[
'mode'
]) {
case
"detailed"
:
$detailed
= true;
$count
=true;
break
;
case
"graph_load"
:
$graph_load
= true;
$load
= true;
break
;
case
"simple_load"
:
$simple_load
= true;
$load
= true;
break
;
case
"simple_count"
:
$simple_count
= true;
$load
= true;
break
;
case
"geo_count"
:
$geo_count
= true;
$count
= true;
break
;
case
"stream_count"
:
$stream_count
= true;
$count
= true;
break
;
}
$form
= false;
}
else
{
$form
= true; }
if
(isset(
$_GET
[
'port'
])) {
$adminport
=
$_GET
[
'port'
];}
else
{
$adminport
=
'8086'
; }
if
(
$form
) {
?>
<HTML>
<HEAD>
<TITLE>Single-Server Metrics</TITLE>
</HEAD>
<BODY>
<H3>Single-Server Stats Gathering</H3>
<FORM ACTION=
"#"
METHOD=
"GET"
>
<P>Server Address:<BR>
<INPUT TYPE=
"text"
size=
"15"
value=
"<?=$repeater;?>"
name=
"server"
></P>
<P>Admin Port<BR>
<INPUT TYPE=
"text"
size=
"15"
value=
"8086"
name=
"port"
></P>
<P>Data to display: <BR>
<INPUT TYPE=
"radio"
name=
"mode"
value=
"detailed"
>Detailed
Count
</INPUT><BR>
<INPUT TYPE=
"radio"
name=
"mode"
value=
"graph_load"
>Load Graph</INPUT><BR>
<INPUT TYPE=
"radio"
name=
"mode"
value=
"simple_load"
>Load in Mbps</INPUT><BR>
<INPUT TYPE=
"radio"
name=
"mode"
value=
"simple_count"
>Simple
Count
</INPUT><BR>
<INPUT TYPE=
"radio"
name=
"mode"
value=
"geo_count"
>Geographical
Count
</INPUT><BR>
<INPUT TYPE=
"radio"
name=
"mode"
value=
"stream_count"
>Stream
Count
</INPUT><BR>
<BR>
<INPUT TYPE=
"submit"
Value=
"Show Me The Data"
>
</FORM>
</BODY>
</HTML>
<?php
}
else
{
// Iterate through IP address array
// initialize counters
$agent
[
'iPhone'
]=0;
$agent
[
'iPad'
]=0;
$agent
[
'iPod'
]=0;
$agent
[
'stagefright'
]=0;
$agent
[
'Roku'
]=0;
$agent
[
'Flash'
]=0;
$proto
[
'RTMP'
]=0;
$proto
[
'RTSP'
]=0;
$proto
[
'HLS'
]=0;
$proto
[
'2'
]=0;
$proto
[
'3'
]=0;
$proto
[
'4'
]=0;
$server_bwin
= 0;
$server_bwout
= 0;
$server_conns
= 0;
if
(
$graph_load
) {
echo
"<H3>Server Load</H3>"
; }
$filter
=
array
(
"Name"
=>
'ip-address'
,
"Value"
=>
$repeater
);
$opts
=
array
(
"Filter"
=>
$filter
);
if
(
$load
) {
// compute load per server
$repeaterurl
=
"http://$repeater:$adminport/connectioncounts"
;
$repeaterxml
= simplexml_load_file(
$repeaterurl
);
foreach
(
$repeaterxml
->VHost
as
$vhost
) {
foreach
(
$vhost
->Application
as
$app
) {
// parse bandwidth usage by app in case we want it.
$appname
= (string)
$app
->Name;
if
(
$app
->Status ==
"Loaded"
) {
$inbytes
= (string)
$app
->MessagesInBytesRate;
$outbytes
= (string)
$app
->MessagesOutBytesRate;
$bwin
[
$appname
] =
$inbytes
/ 131072;
// Convert Bps to Mbps
$bwout
[
$appname
] =
$outbytes
/ 131027;
// Convert Bps to Mbps
}
}
// End App Loop
}
// End VHost Loop
$server_bwin
= (string)
$repeaterxml
->MessagesInBytesRate / 131072;
// Convert Bps to Mbps
$server_bwout
= (string)
$repeaterxml
->MessagesOutBytesRate / 131072;
// Convert Bps to Mbps
$server_conns
=
$repeaterxml
->ConnectionsCurrent;
if
(
$graph_load
) {
$server_load
=
$server_bwout
/ 1024 * 100;
// convert to percentage
$load_string
= sprintf(
"%.2f"
,
$server_load
);
$bwout_string
= sprintf(
"%.3f"
,
$server_bwout
);
$load_round
=
round
(
$server_load
);
switch
(
$server_load
) {
case
(
$server_load
> 99):
$color
=
"black"
;
$heavy
= true;
break
;
case
(
$server_load
>= 85):
$color
=
"red"
;
$heavy
= true;
break
;
case
(
$server_load
>= 75):
$color
=
"yellow"
;
break
;
default
:
$color
=
"green"
;
}
$info
=
'<A HREF="http://'
.
$repeater
.
':$adminport/serverinfo.xml" target="_blank">'
.
$repeater
.
'</A>: <B>'
.
$load_string
.
"%</B> with "
.
$server_conns
.
" connections ("
.
$bwout_string
.
" Mbps out)"
;
"<P>"
.
$info
.
"</P>"
;
?>
<DIV style=
"height: 5px; background: none repeat scroll 0% 0% #ffffff; border: 2px solid;"
>
<DIV style=
"height: 100%; background: <?=$color?>; color: black; width: <?=$load_round?>%;"
></div>
</div>
<?php
}
// End Load Graph
}
// End Bandwidth Loop
if
(
$count
) {
$repeaterurl
=
"http://$repeater:$adminport/serverinfo"
;
$repeaterxml
= simplexml_load_file(
$repeaterurl
);
foreach
(
$repeaterxml
->VHost
as
$vhost
) {
foreach
(
$vhost
->Application
as
$app
) {
foreach
(
$app
->ApplicationInstance
as
$instance
) {
foreach
(
$instance
->Client
as
$client
) {
// Skip repeaters and encoders - FMS is already filtered out by the HTTPProvider
$skip
= false;
// Init variable
if
(preg_match(
'(Repeater)'
,
$client
->Referrer)) {
$skip
= true; }
if
(preg_match(
'(Kulabyte)'
,
$client
->Referrer)) {
$skip
= true; }
if
(!
$skip
) {
$protocol
= (string)
$client
->Protocol;
$proto
[
$protocol
]++;
$streamnames
= (string)
$client
->StreamNames;
$streamarray
=
explode
(
"/"
,
$streamnames
);
$str_array_len
=sizeof(
$streamarray
);
$str_end_index
=
$str_array_len
-1;
$strname
=
$streamarray
[
$str_end_index
];
if
(
$streamarray
[0] ==
"amazons3"
) {
$vod
[
$strname
]++;
}
else
{
$live
[
$strname
]++;
}
$client_list
[] = (string)
$client
->IpAddress;
if
(
$detailed
) {
if
(
$client
->UserAgent)
// HTML clients will have a useragent defined
{
echo
$client
->IpAddress.
": "
.
$client
->UserAgent .
"<BR>\n"
;
if
(preg_match(
'(Roku)'
,
$client
->UserAgent)) {
$agent
[
'Roku'
]++; }
if
(preg_match(
'(iPhone)'
,
$client
->UserAgent)) {
$agent
[
'iPhone'
]++; }
if
(preg_match(
'(iPad)'
,
$client
->UserAgent)) {
$agent
[
'iPad'
]++; }
if
(preg_match(
'(iPod)'
,
$client
->UserAgent)) {
$agent
[
'iPod'
]++; }
if
(preg_match(
'(stagefright)'
,
$client
->UserAgent)) {
$agent
[
'Android'
]++; }
}
if
(
$client
->FlashVersion)
// Flash clients will have a different string.
{
echo
$client
->IpAddress.
": Flash version "
.
$client
->FlashVersion .
"<BR>\n"
;
$agent
[
'Flash'
]++;
}
}
//Client Details
}
// Detailed Loop
}
//Client Loop
}
//Instance Loop
}
// App Loop
}
//VHost Loop
}
// Count Loop
if
(
$geo_count
) {
"<H3>Client Connections</H3>\n"
;
echo
"<SMALL>Last Refresh: "
;
echo
$date
=
date
(
"Y-m-d H:i:s"
);
echo
"</SMALL>\n"
;
foreach
(
$client_list
as
$client_ip
) {
$geo_record
= geoip_record_by_name(
$client_ip
);
$cn
=
$geo_record
[
'country_name'
];
$cc
=
strtolower
(
$geo_record
[
'country_code'
]);
if
(
$cc
==
"us"
) {
$sn
=
$geo_record
[
'region'
];
$state_total
[
$sn
]++;
}
$country_name
[
$cc
]=
$cn
;
$country_total
[
$cc
]++;
}
//End Client iteration
arsort(
$country_total
);
'<DIV class="countries">'
.
"\n"
;
'<H4>Countries</H4>'
.
"\n"
;
foreach
(
array_keys
(
$country_total
)
as
$ccode
) {
'<IMG SRC="images/flags/'
.
$ccode
.
'.png"> '
;
"$country_name[$ccode] : "
.
$country_total
[
$ccode
].
"<BR>\n"
;
}
// End Country iteration
'</DIV>'
;
arsort(
$state_total
);
'<DIV class="states">'
.
"\n"
;
'<H4>States</H4>'
.
"\n"
;
foreach
(
array_keys
(
$state_total
)
as
$state
) {
"$state : "
.
$state_total
[
$state
].
"<BR>\n"
;
}
// End State iteration
'</DIV>'
;
}
// End Geo Loop
if
(
$detailed
) {
$agent
[
'iOS'
] =
$agent
[
'iPhone'
] +
$agent
[
'iPad'
] +
$agent
[
'iPod'
];
echo
"<BR>\n"
;
echo
"Total HLS Clients: "
.
$proto
[
'HLS'
].
"<BR>\n"
;
echo
"Total Roku clients: "
.
$agent
[
'Roku'
].
"<BR>\n"
;
echo
"Total iOS clients: "
.
$agent
[
'iOS'
] .
" ("
.
$agent
[
'iPhone'
].
" iPhone,"
.
$agent
[
'iPad'
].
" iPad,"
.
$agent
[
'iPod'
].
" iPod)<BR>\n"
;
echo
"Total RTMP clients: "
.
$proto
[
'RTMP'
].
" ("
.
$agent
[
'Flash'
] .
" Flash)<BR>\n"
;
}
// Detailed Loop
if
(
$simple_load
) { printf(
"%.3f"
,
$server_bwout
); }
if
(
$simple_count
) {
$server_conns
; }
if
(
$stream_count
) {
"<h3>Stream Connections</h3>\n"
;
arsort(
$live
);
arsort(
$vod
);
"<DIV CLASS=\"live\"><h4>Live</h4>\n"
;
foreach
(
array_keys
(
$live
)
as
$lstr
) {
strtoupper
(
$lstr
).
" : "
.
$live
[
$lstr
].
"<BR>\n"
; }
"</DIV><DIV CLASS=\"vod\"><h4>On-Demand</h4>\n"
;
foreach
(
array_keys
(
$vod
)
as
$vstr
) {
strtoupper
(
$vstr
).
" : "
.
$vod
[
$vstr
].
"<BR>\n"
; }
"</DIV>"
;
}
}
?>
HI, I´m trying to use that code, I think is perfect, but is not showing the connections…
can you help me ?
http://www.clicktoservices.com:8086/connectioncounts
is working user: admin and pass: admin
Did I miss something ???
Thanks
This uses a combination of connectioncounts.xml and serverinfo.xml from Andrew’s module.
Can you post the code if the authentication is admin-digest?
Hi,
Your PHP code is great, as I am not PHP coder. I have tried to use your code, but ut is not showing the connections as for Marcuscorrea
check server:8086/serverinfo.xml and server:8086/connectioncounts.xml to see if you’re getting the raw data in XML.
hello, where to put php code on wowza server?
Ian, can the code be easily modified to accommodate authentication?
Thank you!
It’s just a matter of updating the HTTP request – if the simplexml function won’t do it, you can use curl and dump the output into the simplexml.