一、目前只有一个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 数据流数据的获取(不同节点则获取的方式不同)的更多相关文章

  1. Nginx 的 RTMP 模块的在线统计功能 stat 在 multi-worker 模式下存在 Bug

    < 让你的 Nginx 的 RTMP 直播具有统计某频道在线观看用户数量的功能>一文介绍了 Nginx 的在线统计模块.         我们的在线直播服务使用了 Nginx 的 Rtmp ...

  2. Nginx模块之———— RTMP模块 统计某频道在线观看流的客户数

    获得订阅者人数,可以方便地显示观看流的客户数. 查看已经安装好的模块 /usr/local/nginx/sbin/nginx -V 安装从源编译Nginx和Nginx-RTMP所需的工具 sudo a ...

  3. Nginx模块之————RTMP模块在Ubuntu 14.04年的设置与搭建

    Nginx的设置,RTMP在Ubuntu 14.04 https://www.vultr.com/docs/setup-nginx-rtmp-on-ubuntu-14-04

  4. Nginx模块之————RTMP模块的FFmpeg的配置问题是FFmpeg的连续退出

    rtmp { server { listen ; application live { allow publish all; allow play all; live on; exec /root/b ...

  5. Nginx模块之————RTMP模块在Ubuntu上以串流直播HLS视频

    Nginx的安装在Ubuntu上以串流直播HLS视频 https://www.vultr.com/docs/setup-nginx-on-ubuntu-to-stream-live-hls-video

  6. Nginx基础知识之————RTMP模块中的中HLS专题(翻译文档)

    一.在Nginx配置文件的RTMP模块中配置hls hls_key_path /tmp/hlskeys; 提示错误信息: nginx: [emerg] the same path name " ...

  7. go语言实战教程之 后台管理页面统计功能开发(1)

    本节内容我们将学习开发实现后台管理平台页面统计功能开发的功能接口,本章节内容将涉及到多种请求路由的方式. 功能介绍 后台管理平台不仅是功能管理平台,同时还是数据管理平台.从数据管理平台角度来说,在管理 ...

  8. Nginx学习之配置RTMP模块搭建推流服务

    写在开始 小程序升级实时音视频录制及播放能力,开放 Wi-Fi.NFC(HCE) 等硬件连接功能.同时提供按需加载.自定义组件和更多访问层级等新特性,增强了第三方平台的能力,以满足日趋丰富的业务需求. ...

  9. Nginx基础知识之————RTMP模块专题(实践文档)

    on_publish 语法:on_publish url上下文:rtmp, server, application描述:这个可以设置为一个API接口(GET方式接受所有参数),会给这个API接口返回8 ...

随机推荐

  1. XPath 简介

    XPath 是一门在 XML 文档中查找信息的语言.XPath 用于在 XML 文档中通过元素和属性进行导航. 在学习之前应该具备的知识: 在您继续学习之前,应该对下面的知识有基本的了解: HTML ...

  2. CentOS7下Apache及Tomcat开启SSL

    安装: 复制代码 yum install -y openssl #使用openssl可手动创建证书 yum install -y httpd yum install -y mod_ssl 防火墙打开8 ...

  3. BeanUtils

    BeanUtils包的使用   BeanUtils工具包是由Apache公司所开发,主要是方便程序员对Bean类能够进行简便的操作. 在使用BeanUtils工具包之前我们需要的Jar包有以下几种: ...

  4. springmvc中的controller是单例的

    今天发现spring3中的controller默认是单例的,若是某个controller中有一个私有的变量a,所有请求到同一个controller时,使用的a变量是共用的,即若是某个请求中修改了这个变 ...

  5. Asp.net MVC5 框架揭秘 S412 实例解析 – 绝妙的扩展 模式的胜利

    Asp.net MVC5 框架是个 开源的,处处可扩展的框架. 蒋先生 在他的这本书里 对如何理解框架,如何扩展框架, 给出了大量的说明和实例. 先上效果图 大部分做传统BS 的同学看到这个页面,脑海 ...

  6. 诚信的cpm广告联盟该怎么选择

    诚信的cpm广告联盟该怎么选择?58传媒广告联盟介绍说,在目前我国的互联网行业发展中,新站长在不断的崛起,这也就意味着老站长在不断的衰败,而老站长的衰败并不是一天两天造成的,而是其长期积累形成的,将错 ...

  7. DataList删除操作

    <asp:DataList ID="fileList" runat="server" RepeatColumns="1" Repeat ...

  8. python直接执行另一个文件中的代码

    看你弄的这么辛苦,给你的方法exec(open(".py","r").read)open(".py",'r').read() 就是读取文件的 ...

  9. 【C解毒】缘木求鱼

    见:[C解毒]缘木求鱼

  10. 接口测试第十二课(fidller过滤)(转)

    转自: 经常有人问我,如何只抓手机上某个应用的请求包?在使用fiddler抓手机包的过程中,fiddler会话框上瞬间就满屏了,因为它不仅抓到手机上的请求数据包,也抓到了PC端的网络请求包.这时候很难 ...