mirror of
https://github.com/ossrs/srs.git
synced 2025-02-15 04:42:04 +00:00
Refine server stat, extract to hybrid server stat
This commit is contained in:
parent
152c161de3
commit
e776e0eca7
4 changed files with 65 additions and 21 deletions
|
@ -83,6 +83,7 @@ private:
|
|||
// for each cycle, we increase it with a resolution.
|
||||
srs_utime_t total_elapse;
|
||||
public:
|
||||
// TODO: FIMXE: Refine to SrsHourGlass(std::string label);
|
||||
SrsHourGlass(std::string label, ISrsHourGlass* h, srs_utime_t resolution);
|
||||
virtual ~SrsHourGlass();
|
||||
public:
|
||||
|
@ -90,6 +91,7 @@ public:
|
|||
virtual srs_error_t start();
|
||||
virtual void stop();
|
||||
public:
|
||||
// TODO: FIXME: Refine to tick with handler. Remove the tick(interval).
|
||||
// Add a pair of tick(event, interval).
|
||||
// @param event the event of tick, default is 0.
|
||||
// @param interval the interval in srs_utime_t of tick.
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -53,18 +53,10 @@ extern SrsPps* _srs_pps_ids;
|
|||
extern SrsPps* _srs_pps_fids;
|
||||
extern SrsPps* _srs_pps_fids_level0;
|
||||
|
||||
extern SrsPps* _srs_pps_cids_get;
|
||||
extern SrsPps* _srs_pps_cids_set;
|
||||
|
||||
extern SrsPps* _srs_pps_pli;
|
||||
extern SrsPps* _srs_pps_twcc;
|
||||
extern SrsPps* _srs_pps_rr;
|
||||
|
||||
extern SrsPps* _srs_pps_timer;
|
||||
extern SrsPps* _srs_pps_pub;
|
||||
extern SrsPps* _srs_pps_conn;
|
||||
extern SrsPps* _srs_pps_dispose;
|
||||
|
||||
extern SrsPps* _srs_pps_snack;
|
||||
extern SrsPps* _srs_pps_snack2;
|
||||
extern SrsPps* _srs_pps_sanack;
|
||||
|
@ -666,29 +658,19 @@ 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();
|
||||
_srs_pps_cids_get->update(); _srs_pps_cids_set->update();
|
||||
_srs_pps_pli->update(); _srs_pps_twcc->update(); _srs_pps_rr->update();
|
||||
_srs_pps_timer->update(); _srs_pps_pub->update(); _srs_pps_conn->update(); _srs_pps_dispose->update();
|
||||
_srs_pps_snack->update(); _srs_pps_snack2->update(); _srs_pps_sanack->update(); _srs_pps_svnack->update();
|
||||
_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, cid=%d,%d, rtcp=%d,%d,%d, timer=%d,%d,%d, free=%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_cids_get->r10s(), _srs_pps_cids_set->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_dispose->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…
Reference in a new issue