mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +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
|
@ -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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue