一、目前只有一个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. Extjs 一些配置以及方法

    1.例如想要实现以下功能,本来model中只有用户的firstname和lastname,但是在grid中展示还需要展示用户姓名,或者只展示用户姓名

  2. linux格式批量转换为dos格式

    注:写的只是基本知识,望高手勿喷,写这个不是为了炫耀,只是为了方便其他人,仅此而已. 一:脚本功能: 批量处理目录以及子目录下的文件格式问题,能够轻易的将linux格式转换为dos格式. 二:写此博客 ...

  3. WebSQL 查询工具

    最近在写 WebSQL ,每次都在浏览器控制台执行 SQL 太费劲了,并且脑子不好使,总是忘记上次初始化的数据库是什么,所以写了一个特别简单的 WebSQL 可视化工具,说工具有点大了,就是为了方便, ...

  4. 快速排序算法 java 实现

    快速排序算法 java 实现 快速排序算法Java实现 白话经典算法系列之六 快速排序 快速搞定 各种排序算法的分析及java实现 算法概念 快速排序是C.R.A.Hoare于1962年提出的一种划分 ...

  5. iOS 收起键盘的几种方式

    iOS 收起键盘的几种方式 1.一般的view上收起键盘 // 手势 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ ...

  6. module not exists: xxxx Error in ThinkPHP

    Introduction ThinkPHP is a very charming PHP framework to easily build a website. It's structured in ...

  7. maven国内镜像(maven下载慢的解决方法)

    Maven是当前流行的项目管理工具,但官方的库在国外经常连不上,连上也下载速度很慢.国内oschina的maven服务器很早之前就关了.今天发现阿里云的一个中央仓库,亲测可用. <mirror& ...

  8. MVC系列2-Model

    上一篇我讲了ASP.MET MVC的基础概念,我相信从上一篇,我们可以知道MVC的执行过程.这一篇我们开始讲解Model.我们知道,在我们的应用程序中,大多时候是在遵循业务逻辑通过UI操作数据.所以这 ...

  9. 《编写可维护的JavaScript》——JavaScript编码规范(五)

    语句和表达式 在JavaScript中,诸如if和for之类的语句有两种写法,使用花括号的多行代码或者不使用花括号的单行代码.比如: //不好的写法,尽管这是合法的JavaScript代码 if (c ...

  10. Java RandomAccessFile用法

    RandomAccessFile RandomAccessFile是用来访问那些保存数据记录的文件的,你就可以用seek( )方法来访问记录,并进行读写了.这些记录的大小不必相同:但是其大小和位置必须 ...