日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Nginx >内容正文

Nginx

Nginx模块之———— RTMP 模块的在线统计功能 stat 数据流数据的获取(不同节点则获取的方式不同)...

發(fā)布時間:2025/4/16 Nginx 72 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Nginx模块之———— RTMP 模块的在线统计功能 stat 数据流数据的获取(不同节点则获取的方式不同)... 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

一、目前只有一個Live節(jié)點存在?

單節(jié)點獲取方式如下:

public function getStreamByIp($outerIP, $streamName){//查詢錄像模塊的IP地址外網(wǎng),根據(jù)這個可以查看到相應(yīng)的流$url = $outerIP . "/rtmp/stat";$ch = curl_init();curl_setopt($ch, CURLOPT_URL, $url);curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ch, CURLOPT_HEADER, 0);$output = curl_exec($ch);curl_close($ch);//所有流的信息,解析Xml$outputs = $this->FromXml($output); // $streamInfo = $outputs['server']['application']['live']['stream'];$streamInfo = $outputs['server']['application']['live']['stream'];if (array_key_exists("name", $streamInfo)) {//判斷該設(shè)備是否在這個數(shù)組中,真:獲取這個設(shè)備的所有打流信息if ($streamName == $streamInfo['name']) {$totalInfo['status'] = 200;$totalInfo['message'] = 'The server is normal and is currently streaming';$totalInfo['dataList']['name'] = $streamInfo['name'];$totalInfo['dataList']['bw_in'] = $streamInfo['bw_in'];$totalInfo['dataList']['bw_out'] = $streamInfo['bw_out'];} else {$totalInfo['status'] = 500;$totalInfo['message'] = 'The server has a problem or is not currently streaming information 1';$totalInfo['dataList']['name'] = $streamName;$totalInfo['dataList']['bw_in'] = 0;$totalInfo['dataList']['bw_out'] = 0;}} else {//存放所有的設(shè)備號到一個數(shù)組中foreach ($streamInfo as $key => $val) {$deviceInfo[] = $val['name'];}//判斷該設(shè)備是否在這個數(shù)組中,真:獲取這個設(shè)備的所有打流信息if (in_array($streamName, $deviceInfo)) {$totalInfo['status'] = 200;$totalInfo['message'] = 'The server is normal and is currently streaming';foreach ($streamInfo as $val) {if ($val['name'] == $streamName) {$totalInfo['dataList']['name'] = $val['name'];$totalInfo['dataList']['bw_in'] = $val['bw_in'];$totalInfo['dataList']['bw_out'] = $val['bw_out'];}}} else {$totalInfo['status'] = 500;$totalInfo['message'] = 'The server has a problem or is not currently streaming information 2';$totalInfo['dataList']['name'] = $streamName;$totalInfo['dataList']['bw_in'] = 0;$totalInfo['dataList']['bw_out'] = 0;}}return $totalInfo;}

二、目前有兩個節(jié)點Live節(jié)點和Live2節(jié)點存在?

?多節(jié)點獲取方式如下:

public function getStreamByIp($outerIP, $streamName){//查詢錄像模塊的IP地址外網(wǎng),根據(jù)這個可以查看到相應(yīng)的流$url = $outerIP . "/rtmp/stat";$ch = curl_init();curl_setopt($ch, CURLOPT_URL, $url);curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ch, CURLOPT_HEADER, 0);$output = curl_exec($ch);curl_close($ch);//所有流的信息,解析Xml$outputs = $this->FromXml($output);$streamInfo = $outputs['server']['application'][0]['live']['stream']; //主要看這里哦!!!!!!!!!!!!!!!!這里獲取的時候是一個二維數(shù)組if (array_key_exists("name", $streamInfo)) {//判斷該設(shè)備是否在這個數(shù)組中,真:獲取這個設(shè)備的所有打流信息if ($streamName == $streamInfo['name']) {$totalInfo['status'] = 200;$totalInfo['message'] = 'The server is normal and is currently streaming';$totalInfo['dataList']['name'] = $streamInfo['name'];$totalInfo['dataList']['bw_in'] = $streamInfo['bw_in'];$totalInfo['dataList']['bw_out'] = $streamInfo['bw_out'];} else {$totalInfo['status'] = 500;$totalInfo['message'] = 'The server has a problem or is not currently streaming information 1';$totalInfo['dataList']['name'] = $streamName;$totalInfo['dataList']['bw_in'] = 0;$totalInfo['dataList']['bw_out'] = 0;}} else {//存放所有的設(shè)備號到一個數(shù)組中foreach ($streamInfo as $key => $val) {$deviceInfo[] = $val['name'];}//判斷該設(shè)備是否在這個數(shù)組中,真:獲取這個設(shè)備的所有打流信息if (in_array($streamName, $deviceInfo)) {$totalInfo['status'] = 200;$totalInfo['message'] = 'The server is normal and is currently streaming';foreach ($streamInfo as $val) {if ($val['name'] == $streamName) {$totalInfo['dataList']['name'] = $val['name'];$totalInfo['dataList']['bw_in'] = $val['bw_in'];$totalInfo['dataList']['bw_out'] = $val['bw_out'];}}} else {$totalInfo['status'] = 500;$totalInfo['message'] = 'The server has a problem or is not currently streaming information 2';$totalInfo['dataList']['name'] = $streamName;$totalInfo['dataList']['bw_in'] = 0;$totalInfo['dataList']['bw_out'] = 0;}}return $totalInfo;}

三、解析Xml

public function FromXml($xml){if (!$xml) {$totalInfo['status'] = 500;$totalInfo['message'] = '沒有該設(shè)備的相應(yīng)信息';$totalInfo['dataList'] = null;return $totalInfo;}//將XML轉(zhuǎn)為array$values = json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);return $values;}

以上為在錄像時候遇到問題,已經(jīng)解決!

?

轉(zhuǎn)載于:https://www.cnblogs.com/tinywan/p/6223054.html

總結(jié)

以上是生活随笔為你收集整理的Nginx模块之———— RTMP 模块的在线统计功能 stat 数据流数据的获取(不同节点则获取的方式不同)...的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。