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 16:52:00 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
b3340218367371131fbac193e61e298a9c69ad57
b3340218
1 parent
7c1dd975
add config item for the stat disk device name
隐藏空白字符变更
内嵌
并排对比
正在显示
5 个修改的文件
包含
73 行增加
和
11 行删除
trunk/conf/full.conf
trunk/src/app/srs_app_config.cpp
trunk/src/app/srs_app_config.hpp
trunk/src/app/srs_app_utility.cpp
trunk/src/utest/srs_utest_config.cpp
trunk/conf/full.conf
查看文件 @
b334021
...
...
@@ -88,6 +88,9 @@ stats {
# we may retrieve more than one network device.
# default: 0
network_device_index
0
;
# the device name to stat the disk iops.
# ignore the device of /proc/diskstats if not configed.
disk_device_name
sda
sdb
xvda
xvdb
;
}
#############################################################################################
...
...
trunk/src/app/srs_app_config.cpp
查看文件 @
b334021
...
...
@@ -1249,7 +1249,7 @@ int SrsConfig::check_config()
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"
)
{
if
(
n
!=
"network_device_index"
&&
n
!=
"disk_device_name"
)
{
ret
=
ERROR_SYSTEM_CONFIG_INVALID
;
srs_error
(
"unsupported stats directive %s, ret=%d"
,
n
.
c_str
(),
ret
);
return
ret
;
...
...
@@ -3194,6 +3194,22 @@ int SrsConfig::get_stats_network_device_index()
return
::
atoi
(
conf
->
arg0
().
c_str
());
}
SrsConfDirective
*
SrsConfig
::
get_stats_disk_device
()
{
SrsConfDirective
*
conf
=
get_stats
();
if
(
!
conf
)
{
return
NULL
;
}
conf
=
conf
->
get
(
"disk_device_name"
);
if
(
!
conf
||
conf
->
args
.
size
()
==
0
)
{
return
NULL
;
}
return
conf
;
}
namespace
_srs_internal
{
SrsConfigBuffer
::
SrsConfigBuffer
()
...
...
trunk/src/app/srs_app_config.hpp
查看文件 @
b334021
...
...
@@ -943,6 +943,12 @@ public:
* for example, 0 means the eth0 maybe.
*/
virtual
int
get_stats_network_device_index
();
/**
* get the disk stat device name list.
* the device name configed in args of directive.
* @return the disk device name to stat. NULL if not configed.
*/
virtual
SrsConfDirective
*
get_stats_disk_device
();
};
namespace
_srs_internal
...
...
trunk/src/app/srs_app_utility.cpp
查看文件 @
b334021
...
...
@@ -415,15 +415,22 @@ bool srs_get_disk_vmstat_stat(SrsDiskStat& r)
bool
srs_get_disk_diskstats_stat
(
SrsDiskStat
&
r
)
{
r
.
ok
=
false
;
r
.
sample_time
=
srs_get_system_time_ms
();
// if disabled, ignore all devices.
SrsConfDirective
*
conf
=
_srs_config
->
get_stats_disk_device
();
if
(
conf
==
NULL
)
{
r
.
ok
=
true
;
return
true
;
}
FILE
*
f
=
fopen
(
"/proc/diskstats"
,
"r"
);
if
(
f
==
NULL
)
{
srs_warn
(
"open vmstat failed, ignore"
);
return
false
;
}
r
.
ok
=
false
;
r
.
sample_time
=
srs_get_system_time_ms
();
static
char
buf
[
1024
];
while
(
fgets
(
buf
,
sizeof
(
buf
),
f
))
{
unsigned
int
major
=
0
;
...
...
@@ -447,9 +454,14 @@ bool srs_get_disk_diskstats_stat(SrsDiskStat& r)
&
rd_sectors
,
&
rd_ticks
,
&
wr_ios
,
&
wr_merges
,
&
wr_sectors
,
&
wr_ticks
,
&
nb_current
,
&
ticks
,
&
aveq
);
srs_assert
(
ret
==
14
);
// TODO: FIMXE: config it.
if
(
strcmp
(
"sda"
,
name
)
==
0
)
{
for
(
int
i
=
0
;
i
<
(
int
)
conf
->
args
.
size
();
i
++
)
{
string
name_ok
=
conf
->
args
.
at
(
i
);
if
(
strcmp
(
name_ok
.
c_str
(),
name
)
!=
0
)
{
continue
;
}
r
.
rd_ios
+=
rd_ios
;
r
.
rd_merges
+=
rd_merges
;
r
.
rd_sectors
+=
rd_sectors
;
...
...
@@ -461,6 +473,8 @@ bool srs_get_disk_diskstats_stat(SrsDiskStat& r)
r
.
nb_current
+=
nb_current
;
r
.
ticks
+=
ticks
;
r
.
aveq
+=
aveq
;
break
;
}
}
...
...
@@ -477,9 +491,18 @@ void srs_update_disk_stat()
if
(
!
srs_get_disk_vmstat_stat
(
r
))
{
return
;
}
if
(
!
srs_get_disk_diskstats_stat
(
r
))
{
return
;
}
SrsDiskStat
&
o
=
_srs_disk_stat
;
if
(
o
.
ok
)
{
if
(
!
o
.
ok
)
{
_srs_disk_stat
=
r
;
return
;
}
// vmstat
if
(
true
)
{
int64_t
duration_ms
=
r
.
sample_time
-
o
.
sample_time
;
if
(
o
.
pgpgin
>
0
&&
r
.
pgpgin
>
o
.
pgpgin
&&
duration_ms
>
0
)
{
...
...
@@ -492,8 +515,6 @@ void srs_update_disk_stat()
r
.
out_KBps
=
(
r
.
pgpgout
-
o
.
pgpgout
)
*
1000
/
duration_ms
;
}
}
_srs_disk_stat
=
r
;
}
SrsMemInfo
::
SrsMemInfo
()
...
...
trunk/src/utest/srs_utest_config.cpp
查看文件 @
b334021
...
...
@@ -156,6 +156,9 @@ std::string __full_conf = ""
" # we may retrieve more than one network device.
\n
"
" # default: 0
\n
"
" network_device_index 0;
\n
"
" # the device name to stat the disk iops.
\n
"
" # ignore the device of /proc/diskstats if not configed.
\n
"
" disk_device_name sda sdb xvda xvdb;
\n
"
"}
\n
"
"
\n
"
"#############################################################################################
\n
"
...
...
@@ -1839,8 +1842,11 @@ 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_stats_network_device_index
());
EXPECT_FALSE
(
conf
.
get_heartbeat_summaries
());
EXPECT_EQ
(
0
,
conf
.
get_stats_network_device_index
());
ASSERT_TRUE
(
conf
.
get_stats_disk_device
()
!=
NULL
);
EXPECT_EQ
(
4
,
(
int
)
conf
.
get_stats_disk_device
()
->
args
.
size
());
EXPECT_TRUE
(
conf
.
get_http_api_enabled
());
EXPECT_EQ
(
1985
,
conf
.
get_http_api_listen
());
...
...
@@ -4633,6 +4639,16 @@ VOID TEST(ConfigMainTest, CheckConf_stats)
MockSrsConfig
conf
;
EXPECT_TRUE
(
ERROR_SUCCESS
!=
conf
.
parse
(
_MIN_OK_CONF
"stats{network_device_index -1;}"
));
}
if
(
true
)
{
MockSrsConfig
conf
;
EXPECT_TRUE
(
ERROR_SUCCESS
==
conf
.
parse
(
_MIN_OK_CONF
"stats{disk_device_name sda;}"
));
}
if
(
true
)
{
MockSrsConfig
conf
;
EXPECT_TRUE
(
ERROR_SUCCESS
!=
conf
.
parse
(
_MIN_OK_CONF
"stats{disk_device_names sda;}"
));
}
}
VOID
TEST
(
ConfigMainTest
,
CheckConf_http_stream
)
...
...
请
注册
或
登录
后发表评论