一、目前只有一个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. js隐式转换

    JavaScript的数据类型分为六种,分别为null,undefined,boolean,string,number,object.object是引用类型,其它的五种是基本类型或者是原始类型.我们可 ...

  2. 6周学习计划,攻克JavaScript难关(React/Redux/ES6 etc.)

    作者:余博伦链接:https://zhuanlan.zhihu.com/p/23412169来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. 和大家一样,最近我也看了Jo ...

  3. FileSaver.js ////////////////////zzzzzzzzzzzzzz

    FileSaver.js 实现浏览器端文件保存的 JavaScript 库 查看次数: 758 下载次数: 89 更新时间: 2015-06-05 发布时间: 2015-06-05 收藏 插件信息金币 ...

  4. jffs2和yaffs2文件系统制作工具的编译与使用

    一 . 先准备文件 mtd-utils-1.4.5.tar.bz2 ftp://ftp.infradead.org/pub/mtd-utils/ zlib-1.2.5.tar.bz2 http://z ...

  5. VIM 常用快捷键

    一,光标移动 大家不要觉得光标移动不重要,其实它是基础,更好的光标移动,复制,粘贴,删除等才能更加的得心应手,进入了编辑器里面后,鼠标就不能用了. 光标移动 h 或 向左箭头键(←) 20h或者20( ...

  6. linux shell脚本使用结构化命令(2)

    一.for命令 二.while命令 三.until命令 1.for命令基本格式 for var in list do commands done oracle@suse:~/testshell> ...

  7. Redmine插件

    1.redmine_customize_core_fields可以对自带字段进行设置,看起来很不错,2016年6月23日上线,安装失败, 看来测试不完整.redmine_issue_field_vis ...

  8. eclipse构建maven+scala+spark工程 转载

    转载地址:http://jingpin.jikexueyuan.com/article/47043.html 本文先叙述如何配置eclipse中maven+scala的开发环境,之后,叙述如何实现sp ...

  9. PRINCE2项目管理七大流程之指导流程

    PRINCE2项目管理七大流程之指导流程   今天学习七大流程之二--项目指导流程 项目指导流程的目的就是使项目管理委员会能够对项目的成功负责,具体来说,是由项目管理委员会作出关键决策,并进行总体控制 ...

  10. Cocos2dx3.11.1Android播放视频,后台 黑屏,无法记忆播放bug修改

    /* * Copyright (C) 2006 The Android Open Source Project * Copyright (c) 2014 Chukong Technologies In ...