当前位置: 首页 > 工具软件 > Monibuca > 使用案例 >

monibuca监测实时推流

蒋无尘
2023-12-01

1、运用官方文档介绍的Summary接口

/api/summary 获取采样数据,这个接口返回一个SSE,里面包含cpu/memory/harddisk/流信息。其类型为 text/event-stream ,从服务器推送到业务端。

data: {
    "Address": "",
    "Memory": {
        "Total": 15926,
        "Free": 11361,
        "Used": 4140,
        "Usage": 26.000358578273936
    },
    "CPUUsage": 12.531645569650099,
    "HardDisk": {
        "Total": 204,
        "Free": 37,
        "Used": 156,
        "Usage": 80.75679390301173
    },
    "NetWork": [

        {
            "Name": "enp6s0",
            "Receive": 267469295183,
            "Sent": 23109565572,
            "ReceiveSpeed": 1160631,
            "SentSpeed": 23229
        }
    ],
    "Streams": [
        {
            "URL": "rtsp://192.168.21.186/id=1",
            "StreamPath": "live/170",
            "Type": "RTSP Pull",
            "StartTime": "2022-01-14T18:42:38.726829057+08:00",
            "Subscribers": [],
            "VideoTracks": {
                "h264": {
                    "CodecID": 7,
                    "PacketCount": 492128,
                    "BPS": 113724,
                    "SPSInfo": {
                        "ProfileIdc": 66,
                        "LevelIdc": 30,
                        "MbWidth": 44,
                        "MbHeight": 30,
                        "CropLeft": 0,
                        "CropRight": 0,
                        "CropTop": 0,
                        "CropBottom": 0,
                        "Width": 704,
                        "Height": 480
                    },
                    "GOP": 75,
                    "UsingDonlField": false
                }
            },
            "AudioTracks": {
                "pcma": {
                    "CodecID": 7,
                    "PacketCount": 656659,
                    "BPS": 8000,
                    "SoundRate": 8000,
                    "SoundSize": 16,
                    "Channels": 1
                }
            },
            "DataTracks": {},
            "AutoCloseAfter": -1,
            "Transcoding": null,
            "ExtraProp": {
                "Transport": 2
            }
        },
        {
            "URL": "",
            "StreamPath": "34020000002000010023/34020000001320010023",
            "Type": "GB28181 Live",
            "StartTime": "2022-01-14T18:42:49.106291879+08:00",
            "Subscribers": null,
            "VideoTracks": {
                "h264": {
                    "CodecID": 7,
                    "PacketCount": 493508,
                    "BPS": 155510,
                    "SPSInfo": {
                        "ProfileIdc": 77,
                        "LevelIdc": 31,
                        "MbWidth": 80,
                        "MbHeight": 45,
                        "CropLeft": 0,
                        "CropRight": 0,
                        "CropTop": 0,
                        "CropBottom": 0,
                        "Width": 1280,
                        "Height": 720
                    },
                    "GOP": 50,
                    "UsingDonlField": false
                }
            },
            "AudioTracks": {},
            "DataTracks": {},
            "AutoCloseAfter": -1,
            "Transcoding": null,
            "ExtraProp": null
        }
    ],
    "Children": null
}

2、代码部分
 

 var test = "http://" + a.server_ip + ":" + a.server_port + "/api/summary"

 var es = new EventSource(test);

      es.onmessage = function (e) {

        var data = JSON.parse(e.data);

        console.log("summary", data['Streams']);

      };

此时的console会实时打印出monibuca服务器中推流的个数,与数据库中添加的监控设备数量进行对比再将没有启动推流的视频调用推流接口

    var ajaxUrl = "http://" + a.server_ip + ":" + a.server_port + "/api/rtsp/pull?streamPath=" +
        a.video_name + "&target=rtsp://" + a.username + ":" + a.password + "@" +
        a.source_ip + ":554/Streaming/Channels/" + a.channel_id;

  $.ajax({
        url: ajaxUrl,
        type: 'GET',
        success: function (res) {
          var res = JSON.parse(res);
          if (res.code == 0) { // 开启成功
            var form_data = {};
            form_data["mineType"] = $("#mineType").val();
            form_data["id"] = a.id;
            form_data["pushflow"] = "open";
            updateDatabase(form_data);
            layer.msg("推流成功!");
          } else {
            layer.msg(res.msg);

          }
        }
      });

 类似资料: