mirror of
https://github.com/ossrs/srs.git
synced 2025-02-12 19:31:53 +00:00
refine config heartbeat, add new stats. 0.9.175
This commit is contained in:
parent
02f7c85710
commit
e76036f40b
9 changed files with 102 additions and 42 deletions
|
@ -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
|
||||
#############################################################################################
|
||||
|
|
|
@ -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__ {
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
@ -1245,6 +1245,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++) {
|
||||
|
@ -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,22 +3157,6 @@ string SrsConfig::get_heartbeat_device_id()
|
|||
return conf->arg0();
|
||||
}
|
||||
|
||||
int SrsConfig::get_heartbeat_device_index()
|
||||
{
|
||||
SrsConfDirective* conf = get_heartbeart();
|
||||
|
||||
if (!conf) {
|
||||
return SRS_CONF_DEFAULT_HTTP_HEAETBEAT_INDEX;
|
||||
}
|
||||
|
||||
conf = conf->get("device_index");
|
||||
if (!conf || conf->arg0().empty()) {
|
||||
return SRS_CONF_DEFAULT_HTTP_HEAETBEAT_INDEX;
|
||||
}
|
||||
|
||||
return ::atoi(conf->arg0().c_str());
|
||||
}
|
||||
|
||||
bool SrsConfig::get_heartbeat_summaries()
|
||||
{
|
||||
SrsConfDirective* conf = get_heartbeart();
|
||||
|
@ -3174,6 +3173,27 @@ bool SrsConfig::get_heartbeat_summaries()
|
|||
return true;
|
||||
}
|
||||
|
||||
SrsConfDirective* SrsConfig::get_stats()
|
||||
{
|
||||
return root->get("stats");
|
||||
}
|
||||
|
||||
int SrsConfig::get_stats_network_device_index()
|
||||
{
|
||||
SrsConfDirective* conf = get_stats();
|
||||
|
||||
if (!conf) {
|
||||
return SRS_CONF_DEFAULT_STATS_NETWORK_DEVICE_INDEX;
|
||||
}
|
||||
|
||||
conf = conf->get("network_device_index");
|
||||
if (!conf || conf->arg0().empty()) {
|
||||
return SRS_CONF_DEFAULT_STATS_NETWORK_DEVICE_INDEX;
|
||||
}
|
||||
|
||||
return ::atoi(conf->arg0().c_str());
|
||||
}
|
||||
|
||||
namespace _srs_internal
|
||||
{
|
||||
SrsConfigBuffer::SrsConfigBuffer()
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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 "174"
|
||||
#define VERSION_REVISION "175"
|
||||
#define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION
|
||||
// server info.
|
||||
#define RTMP_SIG_SRS_KEY "SRS"
|
||||
|
|
|
@ -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());
|
||||
|
|
Loading…
Reference in a new issue