mirror of
https://github.com/ossrs/srs.git
synced 2025-02-13 20:01:56 +00:00
Refine server stat, extract to hybrid server stat
This commit is contained in:
parent
6b260d6021
commit
2aa94c643c
4 changed files with 67 additions and 10 deletions
|
@ -29,6 +29,7 @@
|
||||||
#include <srs_app_st.hpp>
|
#include <srs_app_st.hpp>
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
class SrsCoroutine;
|
class SrsCoroutine;
|
||||||
|
|
||||||
|
@ -70,6 +71,7 @@ public:
|
||||||
class SrsHourGlass : virtual public ISrsCoroutineHandler
|
class SrsHourGlass : virtual public ISrsCoroutineHandler
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
std::string label_;
|
||||||
SrsCoroutine* trd;
|
SrsCoroutine* trd;
|
||||||
ISrsHourGlass* handler;
|
ISrsHourGlass* handler;
|
||||||
srs_utime_t _resolution;
|
srs_utime_t _resolution;
|
||||||
|
@ -81,7 +83,8 @@ private:
|
||||||
// for each cycle, we increase it with a resolution.
|
// for each cycle, we increase it with a resolution.
|
||||||
srs_utime_t total_elapse;
|
srs_utime_t total_elapse;
|
||||||
public:
|
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();
|
virtual ~SrsHourGlass();
|
||||||
public:
|
public:
|
||||||
// Start or stop the hourglass.
|
// Start or stop the hourglass.
|
||||||
|
|
|
@ -27,9 +27,18 @@
|
||||||
#include <srs_app_config.hpp>
|
#include <srs_app_config.hpp>
|
||||||
#include <srs_kernel_error.hpp>
|
#include <srs_kernel_error.hpp>
|
||||||
#include <srs_service_st.hpp>
|
#include <srs_service_st.hpp>
|
||||||
|
#include <srs_app_utility.hpp>
|
||||||
|
|
||||||
using namespace std;
|
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()
|
ISrsHybridServer::ISrsHybridServer()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -109,6 +118,7 @@ SrsServer* SrsServerAdapter::instance()
|
||||||
|
|
||||||
SrsHybridServer::SrsHybridServer()
|
SrsHybridServer::SrsHybridServer()
|
||||||
{
|
{
|
||||||
|
timer_ = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsHybridServer::~SrsHybridServer()
|
SrsHybridServer::~SrsHybridServer()
|
||||||
|
@ -135,6 +145,10 @@ srs_error_t SrsHybridServer::initialize()
|
||||||
return srs_error_wrap(err, "initialize st failed");
|
return srs_error_wrap(err, "initialize st failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((err = setup_ticks()) != srs_success) {
|
||||||
|
return srs_error_wrap(err, "tick");
|
||||||
|
}
|
||||||
|
|
||||||
vector<ISrsHybridServer*>::iterator it;
|
vector<ISrsHybridServer*>::iterator it;
|
||||||
for (it = servers.begin(); it != servers.end(); ++it) {
|
for (it = servers.begin(); it != servers.end(); ++it) {
|
||||||
ISrsHybridServer* server = *it;
|
ISrsHybridServer* server = *it;
|
||||||
|
@ -185,5 +199,44 @@ SrsServerAdapter* SrsHybridServer::srs()
|
||||||
return NULL;
|
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();
|
SrsHybridServer* _srs_hybrid = new SrsHybridServer();
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,8 @@
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include <srs_app_hourglass.hpp>
|
||||||
|
|
||||||
class SrsServer;
|
class SrsServer;
|
||||||
|
|
||||||
// The hibrid server interfaces, we could register many servers.
|
// The hibrid server interfaces, we could register many servers.
|
||||||
|
@ -62,10 +64,11 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
// The hybrid server manager.
|
// The hybrid server manager.
|
||||||
class SrsHybridServer
|
class SrsHybridServer : public ISrsHourGlass
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
std::vector<ISrsHybridServer*> servers;
|
std::vector<ISrsHybridServer*> servers;
|
||||||
|
SrsHourGlass* timer_;
|
||||||
public:
|
public:
|
||||||
SrsHybridServer();
|
SrsHybridServer();
|
||||||
virtual ~SrsHybridServer();
|
virtual ~SrsHybridServer();
|
||||||
|
@ -77,6 +80,10 @@ public:
|
||||||
virtual void stop();
|
virtual void stop();
|
||||||
public:
|
public:
|
||||||
virtual SrsServerAdapter* srs();
|
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;
|
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;
|
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.
|
// Update the pps stat for UDP socket and adddresses.
|
||||||
_srs_pps_pkts->update(); _srs_pps_addrs->update(); _srs_pps_fast_addrs->update();
|
_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_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();
|
_srs_pps_rnack->update(); _srs_pps_rnack2->update();
|
||||||
|
|
||||||
// TODO: FIXME: Show more data for RTC server.
|
// 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",
|
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, u->percent * 100, memory,
|
nn_rtc_conns,
|
||||||
_srs_pps_pkts->r10s(), _srs_pps_addrs->r10s(), _srs_pps_fast_addrs->r10s(),
|
_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_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_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_snack->r10s(), _srs_pps_snack2->r10s(), _srs_pps_sanack->r10s(), _srs_pps_svnack->r10s(),
|
||||||
_srs_pps_rnack->r10s(), _srs_pps_rnack2->r10s()
|
_srs_pps_rnack->r10s(), _srs_pps_rnack2->r10s()
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue