Toggle navigation
Toggle navigation
此项目
正在载入...
Sign in
胡斌
/
srs
转到一个项目
Toggle navigation
项目
群组
代码片段
帮助
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
winlin
2014-07-27 14:43:55 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
e76036f40b53246188060b0d14855e29df694f30
e76036f4
1 parent
02f7c857
refine config heartbeat, add new stats. 0.9.175
隐藏空白字符变更
内嵌
并排对比
正在显示
9 个修改的文件
包含
99 行增加
和
39 行删除
trunk/conf/full.conf
trunk/conf/http.heartbeat.conf
trunk/src/app/srs_app_config.cpp
trunk/src/app/srs_app_config.hpp
trunk/src/app/srs_app_heartbeat.cpp
trunk/src/app/srs_app_utility.cpp
trunk/src/app/srs_app_utility.hpp
trunk/src/core/srs_core.hpp
trunk/src/utest/srs_utest_config.cpp
trunk/conf/full.conf
查看文件 @
e76036f
...
...
@@ -42,7 +42,10 @@ max_connections 1000;
# @remark: donot support reload.
# default: on
daemon
on
;
# heartbeat to api server
# @remark, the ip report to server, is retrieve from system stat,
# which need the config item stats.network_device_index.
heartbeat
{
# whether heartbeat is enalbed.
# default: off
...
...
@@ -61,10 +64,6 @@ heartbeat {
url
http
://
127
.
0
.
0
.
1
:
8085
/
api
/
v1
/
servers
;
# the id of devide.
device_id
"my-srs-device"
;
# the index of device ip.
# we may retrieve more than one network device.
# default: 0
device_index
0
;
# whether report with summaries
# if true, put /api/v1/summaries to the request data:
# {
...
...
@@ -115,6 +114,19 @@ http_stream {
dir
./
objs
/
nginx
/
html
;
}
# system statistics section.
# the main cycle will retrieve the system stat,
# for example, the cpu/mem/network/disk-io data,
# the http api, for instance, /api/v1/summaries will show these data.
# @remark the heartbeat depends on the network_device_index,
# for example, the eth0 maybe the device which index is 0.
stats
{
# the index of device ip.
# we may retrieve more than one network device.
# default: 0
network_device_index
0
;
}
#############################################################################################
# RTMP/HTTP VHOST sections
#############################################################################################
...
...
trunk/conf/http.heartbeat.conf
查看文件 @
e76036f
...
...
@@ -8,6 +8,10 @@ heartbeat {
interval
9
.
3
;
url
http
://
127
.
0
.
0
.
1
:
8085
/
api
/
v1
/
servers
;
device_id
"my-srs-device"
;
summaries
on
;
}
stats
{
network_device_index
0
;
}
vhost
__
defaultVhost__
{
}
...
...
trunk/src/app/srs_app_config.cpp
查看文件 @
e76036f
...
...
@@ -1202,7 +1202,7 @@ int SrsConfig::check_config()
if
(
n
!=
"listen"
&&
n
!=
"pid"
&&
n
!=
"chunk_size"
&&
n
!=
"ff_log_dir"
&&
n
!=
"srs_log_tank"
&&
n
!=
"srs_log_level"
&&
n
!=
"srs_log_file"
&&
n
!=
"max_connections"
&&
n
!=
"daemon"
&&
n
!=
"heartbeat"
&&
n
!=
"http_api"
&&
n
!=
"http_stream"
&&
n
!=
"vhost"
&&
n
!=
"http_api"
&&
n
!=
"http_stream"
&&
n
!=
"
stats"
&&
n
!=
"
vhost"
&&
n
!=
"pithy_print"
)
{
ret
=
ERROR_SYSTEM_CONFIG_INVALID
;
...
...
@@ -1237,7 +1237,7 @@ int SrsConfig::check_config()
for
(
int
i
=
0
;
conf
&&
i
<
(
int
)
conf
->
directives
.
size
();
i
++
)
{
string
n
=
conf
->
at
(
i
)
->
name
;
if
(
n
!=
"enabled"
&&
n
!=
"interval"
&&
n
!=
"url"
&&
n
!=
"device_id"
&&
n
!=
"
device_index"
&&
n
!=
"
summaries"
&&
n
!=
"device_id"
&&
n
!=
"summaries"
)
{
ret
=
ERROR_SYSTEM_CONFIG_INVALID
;
srs_error
(
"unsupported heartbeat directive %s, ret=%d"
,
n
.
c_str
(),
ret
);
...
...
@@ -1246,6 +1246,17 @@ int SrsConfig::check_config()
}
}
if
(
true
)
{
SrsConfDirective
*
conf
=
get_stats
();
for
(
int
i
=
0
;
conf
&&
i
<
(
int
)
conf
->
directives
.
size
();
i
++
)
{
string
n
=
conf
->
at
(
i
)
->
name
;
if
(
n
!=
"network_device_index"
)
{
ret
=
ERROR_SYSTEM_CONFIG_INVALID
;
srs_error
(
"unsupported stats directive %s, ret=%d"
,
n
.
c_str
(),
ret
);
return
ret
;
}
}
}
if
(
true
)
{
SrsConfDirective
*
conf
=
get_pithy_print
();
for
(
int
i
=
0
;
conf
&&
i
<
(
int
)
conf
->
directives
.
size
();
i
++
)
{
string
n
=
conf
->
at
(
i
)
->
name
;
...
...
@@ -1427,10 +1438,14 @@ int SrsConfig::check_config()
get_heartbeat_interval
(),
ret
);
return
ret
;
}
if
(
get_heartbeat_device_index
()
<
0
)
{
////////////////////////////////////////////////////////////////////////
// check stats
////////////////////////////////////////////////////////////////////////
if
(
get_stats_network_device_index
()
<
0
)
{
ret
=
ERROR_SYSTEM_CONFIG_INVALID
;
srs_error
(
"directive heartbeat device_index invalid, device_index=%d, ret=%d"
,
get_heartbeat_device_index
(),
ret
);
srs_error
(
"directive stats network_device_index invalid, network_device_index=%d, ret=%d"
,
get_stats_network_device_index
(),
ret
);
return
ret
;
}
...
...
@@ -3142,36 +3157,41 @@ string SrsConfig::get_heartbeat_device_id()
return
conf
->
arg0
();
}
int
SrsConfig
::
get_heartbeat_device_index
()
bool
SrsConfig
::
get_heartbeat_summaries
()
{
SrsConfDirective
*
conf
=
get_heartbeart
();
if
(
!
conf
)
{
return
SRS_CONF_DEFAULT_HTTP_HEAETBEAT_
INDEX
;
return
SRS_CONF_DEFAULT_HTTP_HEAETBEAT_
SUMMARIES
;
}
conf
=
conf
->
get
(
"device_index"
);
if
(
!
conf
||
conf
->
arg0
().
empty
())
{
return
SRS_CONF_DEFAULT_HTTP_HEAETBEAT_INDEX
;
conf
=
conf
->
get
(
"summaries"
);
if
(
!
conf
||
conf
->
arg0
()
!=
"on"
)
{
return
SRS_CONF_DEFAULT_HTTP_HEAETBEAT_SUMMARIES
;
}
return
::
atoi
(
conf
->
arg0
().
c_str
())
;
return
true
;
}
bool
SrsConfig
::
get_heartbeat_summarie
s
()
SrsConfDirective
*
SrsConfig
::
get_stat
s
()
{
SrsConfDirective
*
conf
=
get_heartbeart
();
return
root
->
get
(
"stats"
);
}
int
SrsConfig
::
get_stats_network_device_index
()
{
SrsConfDirective
*
conf
=
get_stats
();
if
(
!
conf
)
{
return
SRS_CONF_DEFAULT_
HTTP_HEAETBEAT_SUMMARIES
;
return
SRS_CONF_DEFAULT_
STATS_NETWORK_DEVICE_INDEX
;
}
conf
=
conf
->
get
(
"summaries"
);
if
(
!
conf
||
conf
->
arg0
()
!=
"on"
)
{
return
SRS_CONF_DEFAULT_HTTP_HEAETBEAT_SUMMARIES
;
conf
=
conf
->
get
(
"network_device_index"
);
if
(
!
conf
||
conf
->
arg0
().
empty
())
{
return
SRS_CONF_DEFAULT_STATS_NETWORK_DEVICE_INDEX
;
}
return
true
;
return
::
atoi
(
conf
->
arg0
().
c_str
())
;
}
namespace
_srs_internal
...
...
trunk/src/app/srs_app_config.hpp
查看文件 @
e76036f
...
...
@@ -74,9 +74,10 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#define SRS_CONF_DEFAULT_HTTP_HEAETBEAT_ENABLED false
#define SRS_CONF_DEFAULT_HTTP_HEAETBEAT_INTERVAL 9.9
#define SRS_CONF_DEFAULT_HTTP_HEAETBEAT_URL "http://"SRS_CONSTS_LOCALHOST":8085/api/v1/servers"
#define SRS_CONF_DEFAULT_HTTP_HEAETBEAT_INDEX 0
#define SRS_CONF_DEFAULT_HTTP_HEAETBEAT_SUMMARIES false
#define SRS_CONF_DEFAULT_STATS_NETWORK_DEVICE_INDEX 0
#define SRS_CONF_DEFAULT_STAGE_PLAY_USER_INTERVAL_MS 10000
#define SRS_CONF_DEFAULT_STAGE_PUBLISH_USER_INTERVAL_MS 10000
#define SRS_CONF_DEFAULT_STAGE_FORWARDER_INTERVAL_MS 10000
...
...
@@ -926,14 +927,22 @@ public:
*/
virtual
std
::
string
get_heartbeat_device_id
();
/**
* get the network device index, to report to server.
* for example, 0 means the eth0 maybe.
*/
virtual
int
get_heartbeat_device_index
();
/**
* whether report with summaries of http api: /api/v1/summaries.
*/
virtual
bool
get_heartbeat_summaries
();
// stats section
private:
/**
* get the stats directive.
*/
virtual
SrsConfDirective
*
get_stats
();
public
:
/**
* get the network device index, used to retrieve the ip of device,
* for heartbeat to report to server, or to get the local ip.
* for example, 0 means the eth0 maybe.
*/
virtual
int
get_stats_network_device_index
();
};
namespace
_srs_internal
...
...
trunk/src/app/srs_app_heartbeat.cpp
查看文件 @
e76036f
...
...
@@ -61,7 +61,7 @@ void SrsHttpHeartbeat::heartbeat()
vector
<
string
>&
ips
=
srs_get_local_ipv4_ips
();
if
(
!
ips
.
empty
())
{
ip
=
ips
[
_srs_config
->
get_
heartbeat
_device_index
()
%
(
int
)
ips
.
size
()];
ip
=
ips
[
_srs_config
->
get_
stats_network
_device_index
()
%
(
int
)
ips
.
size
()];
}
std
::
stringstream
ss
;
...
...
trunk/src/app/srs_app_utility.cpp
查看文件 @
e76036f
...
...
@@ -367,7 +367,7 @@ SrsDiskStat* srs_get_disk_stat()
return
&
_srs_disk_stat
;
}
bool
srs_get_disk_stat
(
SrsDiskStat
&
r
)
bool
srs_get_disk_
vmstat_
stat
(
SrsDiskStat
&
r
)
{
FILE
*
f
=
fopen
(
"/proc/vmstat"
,
"r"
);
if
(
f
==
NULL
)
{
...
...
@@ -401,10 +401,15 @@ bool srs_get_disk_stat(SrsDiskStat& r)
return
true
;
}
bool
srs_get_disk_diskstats_stat
(
SrsDiskStat
&
r
)
{
return
true
;
}
void
srs_update_disk_stat
()
{
SrsDiskStat
r
;
if
(
!
srs_get_disk_stat
(
r
))
{
if
(
!
srs_get_disk_
vmstat_
stat
(
r
))
{
return
;
}
...
...
trunk/src/app/srs_app_utility.hpp
查看文件 @
e76036f
...
...
@@ -348,6 +348,8 @@ public:
// the out(write) page count, pgpgout*1024 is the write bytes.
// Total number of kilobytes the system paged out to disk per second.
unsigned
long
pgpgout
;
// @see: https://www.kernel.org/doc/Documentation/iostats.txt
public
:
SrsDiskStat
();
...
...
trunk/src/core/srs_core.hpp
查看文件 @
e76036f
...
...
@@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// current release version
#define VERSION_MAJOR "0"
#define VERSION_MINOR "9"
#define VERSION_REVISION "17
4
"
#define VERSION_REVISION "17
5
"
#define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION
// server info.
#define RTMP_SIG_SRS_KEY "SRS"
...
...
trunk/src/utest/srs_utest_config.cpp
查看文件 @
e76036f
...
...
@@ -96,10 +96,6 @@ std::string __full_conf = ""
" url http://127.0.0.1:8085/api/v1/servers;
\n
"
" # the id of devide.
\n
"
" device_id
\"
my-srs-device
\"
;
\n
"
" # the index of device ip.
\n
"
" # we may retrieve more than one network device.
\n
"
" # default: 0
\n
"
" device_index 0;
\n
"
" # whether report with summaries
\n
"
" # if true, put /api/v1/summaries to the request data:
\n
"
" # {
\n
"
...
...
@@ -149,6 +145,18 @@ std::string __full_conf = ""
" # default: ./objs/nginx/html
\n
"
" dir ./objs/nginx/html;
\n
"
"}
\n
"
"# system statistics section.
\n
"
"# the main cycle will retrieve the system stat,
\n
"
"# for example, the cpu/mem/network/disk-io data,
\n
"
"# the http api, for instance, /api/v1/summaries will show these data.
\n
"
"# @remark the heartbeat depends on the network_device_index,
\n
"
"# for example, the eth0 maybe the device which index is 0.
\n
"
"stats {
\n
"
" # the index of device ip.
\n
"
" # we may retrieve more than one network device.
\n
"
" # default: 0
\n
"
" network_device_index 0;
\n
"
"}
\n
"
"
\n
"
"#############################################################################################
\n
"
"# RTMP/HTTP VHOST sections
\n
"
...
...
@@ -1132,10 +1140,10 @@ VOID TEST(ConfigTest, CheckMacros)
#ifndef SRS_CONF_DEFAULT_HTTP_HEAETBEAT_URL
EXPECT_TRUE
(
false
);
#endif
#ifndef SRS_CONF_DEFAULT_HTTP_HEAETBEAT_
INDEX
#ifndef SRS_CONF_DEFAULT_HTTP_HEAETBEAT_
SUMMARIES
EXPECT_TRUE
(
false
);
#endif
#ifndef SRS_CONF_DEFAULT_
HTTP_HEAETBEAT_SUMMARIES
#ifndef SRS_CONF_DEFAULT_
STATS_NETWORK_DEVICE_INDEX
EXPECT_TRUE
(
false
);
#endif
#ifndef SRS_CONF_DEFAULT_STAGE_PLAY_USER_INTERVAL_MS
...
...
@@ -1831,7 +1839,7 @@ VOID TEST(ConfigMainTest, ParseFullConf)
EXPECT_EQ
(
9300
,
conf
.
get_heartbeat_interval
());
EXPECT_STREQ
(
"http://127.0.0.1:8085/api/v1/servers"
,
conf
.
get_heartbeat_url
().
c_str
());
EXPECT_STREQ
(
"my-srs-device"
,
conf
.
get_heartbeat_device_id
().
c_str
());
EXPECT_EQ
(
0
,
conf
.
get_
heartbeat
_device_index
());
EXPECT_EQ
(
0
,
conf
.
get_
stats_network
_device_index
());
EXPECT_FALSE
(
conf
.
get_heartbeat_summaries
());
EXPECT_TRUE
(
conf
.
get_http_api_enabled
());
...
...
请
注册
或
登录
后发表评论