REST API – get historic connection counts

You can obtain historical connection & bandwidth information via Wowza’s REST API. As a quick & dirty test, you can try the following curl example:

curl -X GET --header 'Accept:application/json; charset=utf-8' "http://wowza.edgetrac.net:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/testlive/monitoring/historic"

Further you can add query string parameters to specify the date/time range:

curl -X GET --header 'Accept:application/json; charset=utf-8' "http://wowza.edgetrac.net:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/testlive/monitoring/historic?start=2015-11-01T15:00:00&end=2015-11-01T15:01:00"

Further to use PHP to do the same thing, it might look like the following:

$url = "http://wowza.edgetrac.net:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/live/monitoring/historic";
$ch = curl_init($url);                                                     
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_HEADER      ,0);  
curl_setopt($ch, CURLOPT_RETURNTRANSFER  ,1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
					'Accept:application/json; charset=utf-8',
					'Content-type:application/json; charset=utf-8',
					'Content-Length: '.strlen($json)));
$contents = curl_exec($ch); 
curl_close($ch);

$obj =  json_decode($contents);
if(isset($obj->entries)){
	if(isset($obj->entries->min) &&
			is_array($obj->entries->min) && 
				count($obj->entries->min)>0
		){
		foreach($obj->entries->min as $entry){
			$dateTime = Date("m/d/Y h:i a", strtotime($entry->dateTime));
			$data = $entry->data; 
			if(is_array($data) && count($data)==10){
				$stats = new stdClass();
				
				// data
				$stats->bandwidth_inbound = $data[0];
				$stats->bandwidth_outbound = $data[1];
				
				// connections
				$stats->rtmp = $data[2];
				$stats->rtsp = $data[3];
				$stats->hds = $data[4];
				$stats->hls = $data[5];
				$stats->smooth = $data[6];
				$stats->webrtc = $data[7];
				$stats->webm = $data[8];
				$stats->dash = $data[9];
				
				echo "Date: ".$dateTime."\n";
				var_dump($stats);
				echo "\n=====\n\n";
			}
		}
	}
} 

Comments are closed.