1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

Refine server stat, extract to hybrid server stat

This commit is contained in:
winlin 2021-02-10 13:07:26 +08:00
parent 152c161de3
commit e776e0eca7
4 changed files with 65 additions and 21 deletions

View file

@ -27,9 +27,18 @@
#include <srs_app_config.hpp>
#include <srs_kernel_error.hpp>
#include <srs_service_st.hpp>
#include <srs_app_utility.hpp>
using namespace std;
extern SrsPps* _srs_pps_cids_get;
extern SrsPps* _srs_pps_cids_set;
extern SrsPps* _srs_pps_timer;
extern SrsPps* _srs_pps_pub;
extern SrsPps* _srs_pps_conn;
extern SrsPps* _srs_pps_dispose;
ISrsHybridServer::ISrsHybridServer()
{
}
@ -109,6 +118,7 @@ SrsServer* SrsServerAdapter::instance()
SrsHybridServer::SrsHybridServer()
{
timer_ = NULL;
}
SrsHybridServer::~SrsHybridServer()
@ -135,6 +145,10 @@ srs_error_t SrsHybridServer::initialize()
return srs_error_wrap(err, "initialize st failed");
}
if ((err = setup_ticks()) != srs_success) {
return srs_error_wrap(err, "tick");
}
vector<ISrsHybridServer*>::iterator it;
for (it = servers.begin(); it != servers.end(); ++it) {
ISrsHybridServer* server = *it;
@ -185,5 +199,44 @@ SrsServerAdapter* SrsHybridServer::srs()
return NULL;
}
srs_error_t SrsHybridServer::setup_ticks()
{
srs_error_t err = srs_success;
timer_ = new SrsHourGlass("hybrid", this, 1 * SRS_UTIME_SECONDS);
if ((err = timer_->tick(1, 5 * SRS_UTIME_SECONDS)) != srs_success) {
return srs_error_wrap(err, "tick");
}
if ((err = timer_->start()) != srs_success) {
return srs_error_wrap(err, "start");
}
return err;
}
srs_error_t SrsHybridServer::notify(int event, srs_utime_t interval, srs_utime_t tick)
{
srs_error_t err = srs_success;
// Show statistics for RTC server.
SrsProcSelfStat* u = srs_get_self_proc_stat();
// Resident Set Size: number of pages the process has in real memory.
int memory = (int)(u->rss * 4 / 1024);
_srs_pps_cids_get->update(); _srs_pps_cids_set->update();
_srs_pps_timer->update(); _srs_pps_pub->update(); _srs_pps_conn->update(); _srs_pps_dispose->update();
srs_trace("Hybrid cpu=%.2f%%,%dMB, cid=%d,%d, timer=%d,%d,%d, free=%d",
u->percent * 100, memory,
_srs_pps_cids_get->r10s(), _srs_pps_cids_set->r10s(),
_srs_pps_timer->r10s(), _srs_pps_pub->r10s(), _srs_pps_conn->r10s(),
_srs_pps_dispose->r10s()
);
return err;
}
SrsHybridServer* _srs_hybrid = new SrsHybridServer();