Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Z
ZLMediaKit
概览
Overview
Details
Activity
Cycle Analytics
版本库
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
问题
0
Issues
0
列表
Board
标记
里程碑
合并请求
0
Merge Requests
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
Snippets
成员
Collapse sidebar
Close sidebar
活动
图像
聊天
创建新问题
作业
提交
Issue Boards
Open sidebar
张翔宇
ZLMediaKit
Commits
10afab77
Commit
10afab77
authored
Aug 21, 2021
by
xiongziliang
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature/keep_alive_monk' of
https://gitee.com/xia-chu/ZLMediaKit
parents
41c09757
a60ce1b1
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
65 行增加
和
26 行删除
+65
-26
conf/config.ini
+4
-0
server/WebApi.cpp
+31
-25
server/WebApi.h
+1
-0
server/WebHook.cpp
+29
-1
没有找到文件。
conf/config.ini
查看文件 @
10afab77
...
...
@@ -131,8 +131,12 @@ on_stream_none_reader=https://127.0.0.1/index/hook/on_stream_none_reader
on_stream_not_found
=
https://127.0.0.1/index/hook/on_stream_not_found
#服务器启动报告,可以用于服务器的崩溃重启事件监听
on_server_started
=
https://127.0.0.1/index/hook/on_server_started
#server保活上报
on_server_keepalive
=
https://127.0.0.1/index/hook/on_server_keepalive
#hook api最大等待回复时间,单位秒
timeoutSec
=
10
#keepalive hook触发间隔,单位秒,float类型
alive_interval
=
10.0
[http]
#http服务器字符编码,windows上默认gb2312
...
...
server/WebApi.cpp
查看文件 @
10afab77
...
...
@@ -348,6 +348,36 @@ Value makeMediaSourceJson(MediaSource &media){
return
item
;
}
Value
getStatisticJson
()
{
Value
val
(
objectValue
);
val
[
"MediaSource"
]
=
(
Json
::
UInt64
)(
ObjectStatistic
<
MediaSource
>::
count
());
val
[
"MultiMediaSourceMuxer"
]
=
(
Json
::
UInt64
)(
ObjectStatistic
<
MultiMediaSourceMuxer
>::
count
());
val
[
"TcpServer"
]
=
(
Json
::
UInt64
)(
ObjectStatistic
<
TcpServer
>::
count
());
val
[
"TcpSession"
]
=
(
Json
::
UInt64
)(
ObjectStatistic
<
TcpSession
>::
count
());
val
[
"UdpServer"
]
=
(
Json
::
UInt64
)(
ObjectStatistic
<
UdpServer
>::
count
());
val
[
"UdpSession"
]
=
(
Json
::
UInt64
)(
ObjectStatistic
<
UdpSession
>::
count
());
val
[
"TcpClient"
]
=
(
Json
::
UInt64
)(
ObjectStatistic
<
TcpClient
>::
count
());
val
[
"Socket"
]
=
(
Json
::
UInt64
)(
ObjectStatistic
<
Socket
>::
count
());
val
[
"FrameImp"
]
=
(
Json
::
UInt64
)(
ObjectStatistic
<
FrameImp
>::
count
());
val
[
"Frame"
]
=
(
Json
::
UInt64
)(
ObjectStatistic
<
Frame
>::
count
());
val
[
"Buffer"
]
=
(
Json
::
UInt64
)(
ObjectStatistic
<
Buffer
>::
count
());
val
[
"BufferRaw"
]
=
(
Json
::
UInt64
)(
ObjectStatistic
<
BufferRaw
>::
count
());
val
[
"BufferLikeString"
]
=
(
Json
::
UInt64
)(
ObjectStatistic
<
BufferLikeString
>::
count
());
val
[
"BufferList"
]
=
(
Json
::
UInt64
)(
ObjectStatistic
<
BufferList
>::
count
());
val
[
"RtpPacket"
]
=
(
Json
::
UInt64
)(
ObjectStatistic
<
RtpPacket
>::
count
());
val
[
"RtmpPacket"
]
=
(
Json
::
UInt64
)(
ObjectStatistic
<
RtmpPacket
>::
count
());
#ifdef ENABLE_MEM_DEBUG
auto
bytes
=
getTotalMemUsage
();
val
[
"totalMemUsage"
]
=
(
Json
::
UInt64
)
bytes
;
val
[
"totalMemUsageMB"
]
=
(
int
)(
bytes
/
1024
/
1024
);
#endif
return
val
;
}
/**
* 安装api接口
* 所有api都支持GET和POST两种方式
...
...
@@ -1150,31 +1180,7 @@ void installWebApi() {
api_regist
(
"/index/api/getStatistic"
,[](
API_ARGS_MAP
){
CHECK_SECRET
();
val
[
"data"
][
"MediaSource"
]
=
(
Json
::
UInt64
)(
ObjectStatistic
<
MediaSource
>::
count
());
val
[
"data"
][
"MultiMediaSourceMuxer"
]
=
(
Json
::
UInt64
)(
ObjectStatistic
<
MultiMediaSourceMuxer
>::
count
());
val
[
"data"
][
"TcpServer"
]
=
(
Json
::
UInt64
)(
ObjectStatistic
<
TcpServer
>::
count
());
val
[
"data"
][
"TcpSession"
]
=
(
Json
::
UInt64
)(
ObjectStatistic
<
TcpSession
>::
count
());
val
[
"data"
][
"UdpServer"
]
=
(
Json
::
UInt64
)(
ObjectStatistic
<
UdpServer
>::
count
());
val
[
"data"
][
"UdpSession"
]
=
(
Json
::
UInt64
)(
ObjectStatistic
<
UdpSession
>::
count
());
val
[
"data"
][
"TcpClient"
]
=
(
Json
::
UInt64
)(
ObjectStatistic
<
TcpClient
>::
count
());
val
[
"data"
][
"Socket"
]
=
(
Json
::
UInt64
)(
ObjectStatistic
<
Socket
>::
count
());
val
[
"data"
][
"FrameImp"
]
=
(
Json
::
UInt64
)(
ObjectStatistic
<
FrameImp
>::
count
());
val
[
"data"
][
"Frame"
]
=
(
Json
::
UInt64
)(
ObjectStatistic
<
Frame
>::
count
());
val
[
"data"
][
"Buffer"
]
=
(
Json
::
UInt64
)(
ObjectStatistic
<
Buffer
>::
count
());
val
[
"data"
][
"BufferRaw"
]
=
(
Json
::
UInt64
)(
ObjectStatistic
<
BufferRaw
>::
count
());
val
[
"data"
][
"BufferLikeString"
]
=
(
Json
::
UInt64
)(
ObjectStatistic
<
BufferLikeString
>::
count
());
val
[
"data"
][
"BufferList"
]
=
(
Json
::
UInt64
)(
ObjectStatistic
<
BufferList
>::
count
());
val
[
"data"
][
"RtpPacket"
]
=
(
Json
::
UInt64
)(
ObjectStatistic
<
RtpPacket
>::
count
());
val
[
"data"
][
"RtmpPacket"
]
=
(
Json
::
UInt64
)(
ObjectStatistic
<
RtmpPacket
>::
count
());
#ifdef ENABLE_MEM_DEBUG
auto
bytes
=
getTotalMemUsage
();
val
[
"data"
][
"totalMemUsage"
]
=
(
Json
::
UInt64
)
bytes
;
val
[
"data"
][
"totalMemUsageMB"
]
=
(
int
)(
bytes
/
1024
/
1024
);
#endif
val
[
"data"
]
=
getStatisticJson
();
});
#ifdef ENABLE_WEBRTC
...
...
server/WebApi.h
查看文件 @
10afab77
...
...
@@ -235,4 +235,5 @@ bool checkArgs(Args &args, const First &first, const KeyTypes &...keys) {
void
installWebApi
();
void
unInstallWebApi
();
Value
makeMediaSourceJson
(
MediaSource
&
media
);
Value
getStatisticJson
();
#endif //ZLMEDIAKIT_WEBAPI_H
server/WebHook.cpp
查看文件 @
10afab77
...
...
@@ -42,7 +42,9 @@ const string kOnShellLogin = HOOK_FIELD"on_shell_login";
const
string
kOnStreamNoneReader
=
HOOK_FIELD
"on_stream_none_reader"
;
const
string
kOnHttpAccess
=
HOOK_FIELD
"on_http_access"
;
const
string
kOnServerStarted
=
HOOK_FIELD
"on_server_started"
;
const
string
kOnServerKeepalive
=
HOOK_FIELD
"on_server_keepalive"
;
const
string
kAdminParams
=
HOOK_FIELD
"admin_params"
;
const
string
kAliveInterval
=
HOOK_FIELD
"alive_interval"
;
onceToken
token
([](){
mINI
::
Instance
()[
kEnable
]
=
false
;
...
...
@@ -61,7 +63,9 @@ onceToken token([](){
mINI
::
Instance
()[
kOnStreamNoneReader
]
=
""
;
mINI
::
Instance
()[
kOnHttpAccess
]
=
""
;
mINI
::
Instance
()[
kOnServerStarted
]
=
""
;
mINI
::
Instance
()[
kOnServerKeepalive
]
=
""
;
mINI
::
Instance
()[
kAdminParams
]
=
"secret=035c73f7-bb6b-4889-a715-d9eb2d1925cc"
;
mINI
::
Instance
()[
kAliveInterval
]
=
30.0
;
},
nullptr
);
}
//namespace Hook
...
...
@@ -184,6 +188,27 @@ static void reportServerStarted(){
do_http_hook
(
hook_server_started
,
body
,
nullptr
);
}
// 服务器定时保活定时器
static
Timer
::
Ptr
g_keepalive_timer
;
static
void
reportServerKeepalive
()
{
GET_CONFIG
(
bool
,
hook_enable
,
Hook
::
kEnable
);
GET_CONFIG
(
string
,
hook_server_keepalive
,
Hook
::
kOnServerKeepalive
);
if
(
!
hook_enable
||
hook_server_keepalive
.
empty
())
{
return
;
}
GET_CONFIG
(
float
,
alive_interval
,
Hook
::
kAliveInterval
);
g_keepalive_timer
=
std
::
make_shared
<
Timer
>
(
alive_interval
,
[]()
{
ArgsType
body
;
body
[
"data"
]
=
getStatisticJson
();
//执行hook
do_http_hook
(
hook_server_keepalive
,
body
,
nullptr
);
return
true
;
},
nullptr
);
}
void
installWebHook
(){
GET_CONFIG
(
bool
,
hook_enable
,
Hook
::
kEnable
);
GET_CONFIG
(
string
,
hook_adminparams
,
Hook
::
kAdminParams
);
...
...
@@ -484,8 +509,11 @@ void installWebHook(){
//汇报服务器重新启动
reportServerStarted
();
//定时上报保活
reportServerKeepalive
();
}
void
unInstallWebHook
(){
g_keepalive_timer
.
reset
();
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论