Nginx模块之———— RTMP 模块的在线统计功能 stat 数据流数据的获取(不同节点则获取的方式不同)
一、目前只有一个Live节点存在

单节点获取方式如下:
public function getStreamByIp($outerIP, $streamName)
{
//查询录像模块的IP地址外网,根据这个可以查看到相应的流
$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)) {
//判断该设备是否在这个数组中,真:获取这个设备的所有打流信息
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 {
//存放所有的设备号到一个数组中
foreach ($streamInfo as $key => $val) {
$deviceInfo[] = $val['name'];
}
//判断该设备是否在这个数组中,真:获取这个设备的所有打流信息
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;
}
二、目前有两个节点Live节点和Live2节点存在

多节点获取方式如下:
public function getStreamByIp($outerIP, $streamName)
{
//查询录像模块的IP地址外网,根据这个可以查看到相应的流
$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']; //主要看这里哦!!!!!!!!!!!!!!!!这里获取的时候是一个二维数组 if (array_key_exists("name", $streamInfo)) {
//判断该设备是否在这个数组中,真:获取这个设备的所有打流信息
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 {
//存放所有的设备号到一个数组中
foreach ($streamInfo as $key => $val) {
$deviceInfo[] = $val['name'];
}
//判断该设备是否在这个数组中,真:获取这个设备的所有打流信息
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'] = '没有该设备的相应信息';
$totalInfo['dataList'] = null;
return $totalInfo;
}
//将XML转为array
$values = json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
return $values;
}
以上为在录像时候遇到问题,已经解决!
Nginx模块之———— RTMP 模块的在线统计功能 stat 数据流数据的获取(不同节点则获取的方式不同)的更多相关文章
- Nginx 的 RTMP 模块的在线统计功能 stat 在 multi-worker 模式下存在 Bug
< 让你的 Nginx 的 RTMP 直播具有统计某频道在线观看用户数量的功能>一文介绍了 Nginx 的在线统计模块. 我们的在线直播服务使用了 Nginx 的 Rtmp ...
- Nginx模块之———— RTMP模块 统计某频道在线观看流的客户数
获得订阅者人数,可以方便地显示观看流的客户数. 查看已经安装好的模块 /usr/local/nginx/sbin/nginx -V 安装从源编译Nginx和Nginx-RTMP所需的工具 sudo a ...
- Nginx模块之————RTMP模块在Ubuntu 14.04年的设置与搭建
Nginx的设置,RTMP在Ubuntu 14.04 https://www.vultr.com/docs/setup-nginx-rtmp-on-ubuntu-14-04
- Nginx模块之————RTMP模块的FFmpeg的配置问题是FFmpeg的连续退出
rtmp { server { listen ; application live { allow publish all; allow play all; live on; exec /root/b ...
- Nginx模块之————RTMP模块在Ubuntu上以串流直播HLS视频
Nginx的安装在Ubuntu上以串流直播HLS视频 https://www.vultr.com/docs/setup-nginx-on-ubuntu-to-stream-live-hls-video
- Nginx基础知识之————RTMP模块中的中HLS专题(翻译文档)
一.在Nginx配置文件的RTMP模块中配置hls hls_key_path /tmp/hlskeys; 提示错误信息: nginx: [emerg] the same path name " ...
- go语言实战教程之 后台管理页面统计功能开发(1)
本节内容我们将学习开发实现后台管理平台页面统计功能开发的功能接口,本章节内容将涉及到多种请求路由的方式. 功能介绍 后台管理平台不仅是功能管理平台,同时还是数据管理平台.从数据管理平台角度来说,在管理 ...
- Nginx学习之配置RTMP模块搭建推流服务
写在开始 小程序升级实时音视频录制及播放能力,开放 Wi-Fi.NFC(HCE) 等硬件连接功能.同时提供按需加载.自定义组件和更多访问层级等新特性,增强了第三方平台的能力,以满足日趋丰富的业务需求. ...
- Nginx基础知识之————RTMP模块专题(实践文档)
on_publish 语法:on_publish url上下文:rtmp, server, application描述:这个可以设置为一个API接口(GET方式接受所有参数),会给这个API接口返回8 ...
随机推荐
- Linux Bond的原理及其不足
http://www.tektea.com/archives/1969.html. 在企业及电信Linux服务器环境上,网络配置都会使用Bonding技术做网口硬件层面的冗余,防止单个网口应用的单点故 ...
- ubuntu配置NFS
ubuntu配置NFS: sudo apt-get install nfs-kernel-server 配置/etc/exports 例如:我们要将根目录下的 /opt/FriendlyARM/min ...
- github Android-Universal-Image-Loader
目存在于Github上面https://github.com/nostra13/Android-Universal-Image-Loader,我们可以先看看这个开源库存在哪些特征 多线程下载图片,图片 ...
- 基于Centos7+Nginx+Tomcat8的负载均衡服务器的搭建
由于工作的需求,在使用中,需要搭建负载均衡,研究了Apache+Tomat负载均衡的方案,并且通过检索相关的文章,进行了比较发现,Apache负载负载均衡在使用的效率上,远远不如Nginx的效率高,因 ...
- 夺命雷公狗-----React---25--小案例之react经典案例todos(单选框的修改)
还是老样子,首先给li里面的单选框一个函数,然后通过props来对她进行处理 然后在ul里面对父组建进行传送 补充一下啊第一步,因为到时候要用到index属性,所以我们需要发送多一个index过来 然 ...
- 【转载】Spring MVC 整合 Freemarker
前言 1.为什么要使用Spring MVC呢? 2.为什么要使用Freemarker呢? 3.为什么不使用Struts2呢? 此示例出现的原因就是发现了struts2的性能太差,所以学习Spring ...
- win下命令行替代品Cmder
Cmder简单使用小结 Cmder是一款Windows环境下非常简洁美观易用的cmd替代者,它支持了大部分的Linux命令. 从官网下载下来一个zip安装包,解压之后运行根目录的Cmder.exe即可 ...
- Entity Framework7 有哪些不同?现在开发到什么程度了?
Entity Framework7之开篇 一.Entity Framework7 简介 Entity Framework7简称EF7,是微软正在开发的最新的在.NET应用中首选的数据访问技术.它是轻量 ...
- Install Jenkins Slave as Windows Service
https://wiki.jenkins-ci.org/display/JENKINS/Installing+Jenkins+as+a+Windows+service SC 直接创建windows s ...
- 在ie与火狐的兼容性
1.在火狐下 document.getElementById("id").textContent可以获取当前获取id下的内容 而在ie下则为:document.getElem ...