Refine server stat, extract to hybrid server stat

pull/2199/head
winlin 4 years ago
parent 6b260d6021
commit 2aa94c643c

@ -29,6 +29,7 @@
#include <srs_app_st.hpp>
#include <map>
#include <string>
class SrsCoroutine;
@ -70,6 +71,7 @@ public:
class SrsHourGlass : virtual public ISrsCoroutineHandler
{
private:
std::string label_;
SrsCoroutine* trd;
ISrsHourGlass* handler;
srs_utime_t _resolution;
@ -81,7 +83,8 @@ private:
// for each cycle, we increase it with a resolution.
srs_utime_t total_elapse;
public:
SrsHourGlass(ISrsHourGlass* h, srs_utime_t resolution);
// TODO: FIMXE: Refine to SrsHourGlass(std::string label);
SrsHourGlass(std::string label, ISrsHourGlass* h, srs_utime_t resolution);
virtual ~SrsHourGlass();
public:
// Start or stop the hourglass.

@ -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();

@ -28,6 +28,8 @@
#include <vector>
#include <srs_app_hourglass.hpp>
class SrsServer;
// The hibrid server interfaces, we could register many servers.
@ -62,10 +64,11 @@ public:
};
// The hybrid server manager.
class SrsHybridServer
class SrsHybridServer : public ISrsHourGlass
{
private:
std::vector<ISrsHybridServer*> servers;
SrsHourGlass* timer_;
public:
SrsHybridServer();
virtual ~SrsHybridServer();
@ -77,6 +80,10 @@ public:
virtual void stop();
public:
virtual SrsServerAdapter* srs();
// interface ISrsHourGlass
private:
virtual srs_error_t setup_ticks();
virtual srs_error_t notify(int event, srs_utime_t interval, srs_utime_t tick);
};
extern SrsHybridServer* _srs_hybrid;

@ -662,11 +662,6 @@ srs_error_t SrsRtcServer::notify(int type, srs_utime_t interval, srs_utime_t tic
return err;
}
// 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);
// Update the pps stat for UDP socket and adddresses.
_srs_pps_pkts->update(); _srs_pps_addrs->update(); _srs_pps_fast_addrs->update();
_srs_pps_ids->update(); _srs_pps_fids->update(); _srs_pps_fids_level0->update();
@ -676,12 +671,11 @@ srs_error_t SrsRtcServer::notify(int type, srs_utime_t interval, srs_utime_t tic
_srs_pps_rnack->update(); _srs_pps_rnack2->update();
// TODO: FIXME: Show more data for RTC server.
srs_trace("RTC: Server conns=%u, cpu=%.2f%%, rss=%dMB, pkts=%d, addrs=%d,%d, fid=%d,%d,%d, rtcp=%d,%d,%d, timer=%d,%d,%d, snk=%d,%d,%d,%d, rnk=%d,%d",
nn_rtc_conns, u->percent * 100, memory,
srs_trace("RTC: Server conns=%u, pkts=%d, addrs=%d,%d, fid=%d,%d,%d, rtcp=%d,%d,%d, snk=%d,%d,%d,%d, rnk=%d,%d",
nn_rtc_conns,
_srs_pps_pkts->r10s(), _srs_pps_addrs->r10s(), _srs_pps_fast_addrs->r10s(),
_srs_pps_ids->r10s(), _srs_pps_fids->r10s(), _srs_pps_fids_level0->r10s(),
_srs_pps_pli->r10s(), _srs_pps_twcc->r10s(), _srs_pps_rr->r10s(),
_srs_pps_timer->r10s(), _srs_pps_pub->r10s(), _srs_pps_conn->r10s(),
_srs_pps_snack->r10s(), _srs_pps_snack2->r10s(), _srs_pps_sanack->r10s(), _srs_pps_svnack->r10s(),
_srs_pps_rnack->r10s(), _srs_pps_rnack2->r10s()
);

Loading…
Cancel
Save