From 6ee2ba049b33f6005a468850bf72b1e30c2e72f9 Mon Sep 17 00:00:00 2001 From: winlin Date: Thu, 19 Jun 2014 15:28:05 +0800 Subject: [PATCH] add srs bytes and kbps to api summaries. 0.9.126 --- README.md | 1 + trunk/src/app/srs_app_conn.hpp | 5 ++- trunk/src/app/srs_app_edge.cpp | 8 ++-- trunk/src/app/srs_app_forward.cpp | 4 +- trunk/src/app/srs_app_http_api.cpp | 26 ++++++++++- trunk/src/app/srs_app_http_api.hpp | 6 +++ trunk/src/app/srs_app_http_conn.cpp | 17 +++++++ trunk/src/app/srs_app_http_conn.hpp | 6 +++ trunk/src/app/srs_app_kbps.cpp | 48 ++++++++++++++++---- trunk/src/app/srs_app_kbps.hpp | 69 ++++++++++++++++++++++++----- trunk/src/app/srs_app_rtmp_conn.cpp | 27 ++++++++--- trunk/src/app/srs_app_rtmp_conn.hpp | 8 +++- trunk/src/app/srs_app_server.cpp | 61 ++++++++++++++++++++++++- trunk/src/app/srs_app_server.hpp | 8 ++++ trunk/src/app/srs_app_utility.cpp | 33 ++++++++++++++ trunk/src/app/srs_app_utility.hpp | 32 +++++++++++++ trunk/src/core/srs_core.hpp | 2 +- 17 files changed, 325 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index 4024d0593..4ad9691c4 100755 --- a/README.md +++ b/README.md @@ -240,6 +240,7 @@ Supported operating systems and hardware: * 2013-10-17, Created.
## History +* v1.0, 2014-06-19, add srs bytes and kbps to api summaries. 0.9.126 * v1.0, 2014-06-18, add network bytes to api summaries. 0.9.125 * v1.0, 2014-06-14, fix [#98](https://github.com/winlinvip/simple-rtmp-server/issues/98), workaround for librtmp ping(fmt=1,cid=2 fresh stream). 0.9.124 * v1.0, 2014-05-29, support flv inject and flv http streaming with start=bytes. 0.9.122 diff --git a/trunk/src/app/srs_app_conn.hpp b/trunk/src/app/srs_app_conn.hpp index 96ac6c98a..c0eeaf2e4 100644 --- a/trunk/src/app/srs_app_conn.hpp +++ b/trunk/src/app/srs_app_conn.hpp @@ -34,9 +34,10 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include #include +#include class SrsServer; -class SrsConnection : public ISrsThreadHandler +class SrsConnection : public virtual ISrsThreadHandler, public virtual IKbpsDelta { private: SrsThread* pthread; @@ -52,6 +53,8 @@ public: virtual int start(); virtual int cycle(); virtual void on_thread_stop(); +public: + virtual void kbps_resample() = 0; protected: virtual int do_cycle() = 0; virtual void stop(); diff --git a/trunk/src/app/srs_app_edge.cpp b/trunk/src/app/srs_app_edge.cpp index edf52eb49..c50a7cea8 100644 --- a/trunk/src/app/srs_app_edge.cpp +++ b/trunk/src/app/srs_app_edge.cpp @@ -182,8 +182,8 @@ int SrsEdgeIngester::ingest() srs_trace("<- "SRS_LOG_ID_EDGE_PLAY " time=%"PRId64", okbps=%d,%d,%d, ikbps=%d,%d,%d", pithy_print.age(), - kbps->get_send_kbps(), kbps->get_send_kbps_sample_high(), kbps->get_send_kbps_sample_medium(), - kbps->get_recv_kbps(), kbps->get_recv_kbps_sample_high(), kbps->get_recv_kbps_sample_medium()); + kbps->get_send_kbps(), kbps->get_send_kbps_30s(), kbps->get_send_kbps_5m(), + kbps->get_recv_kbps(), kbps->get_recv_kbps_30s(), kbps->get_recv_kbps_5m()); } // read from client. @@ -479,8 +479,8 @@ int SrsEdgeForwarder::cycle() srs_trace("-> "SRS_LOG_ID_EDGE_PUBLISH " time=%"PRId64", msgs=%d, okbps=%d,%d,%d, ikbps=%d,%d,%d", pithy_print.age(), count, - kbps->get_send_kbps(), kbps->get_send_kbps_sample_high(), kbps->get_send_kbps_sample_medium(), - kbps->get_recv_kbps(), kbps->get_recv_kbps_sample_high(), kbps->get_recv_kbps_sample_medium()); + kbps->get_send_kbps(), kbps->get_send_kbps_30s(), kbps->get_send_kbps_5m(), + kbps->get_recv_kbps(), kbps->get_recv_kbps_30s(), kbps->get_recv_kbps_5m()); } // ignore when no messages. diff --git a/trunk/src/app/srs_app_forward.cpp b/trunk/src/app/srs_app_forward.cpp index df6d4499f..a9f71dea5 100644 --- a/trunk/src/app/srs_app_forward.cpp +++ b/trunk/src/app/srs_app_forward.cpp @@ -351,8 +351,8 @@ int SrsForwarder::forward() srs_trace("-> "SRS_LOG_ID_FOWARDER " time=%"PRId64", msgs=%d, okbps=%d,%d,%d, ikbps=%d,%d,%d", pithy_print.age(), count, - kbps->get_send_kbps(), kbps->get_send_kbps_sample_high(), kbps->get_send_kbps_sample_medium(), - kbps->get_recv_kbps(), kbps->get_recv_kbps_sample_high(), kbps->get_recv_kbps_sample_medium()); + kbps->get_send_kbps(), kbps->get_send_kbps_30s(), kbps->get_send_kbps_5m(), + kbps->get_recv_kbps(), kbps->get_recv_kbps_30s(), kbps->get_recv_kbps_5m()); } // ignore when no messages. diff --git a/trunk/src/app/srs_app_http_api.cpp b/trunk/src/app/srs_app_http_api.cpp index f38be42ac..0140dc983 100644 --- a/trunk/src/app/srs_app_http_api.cpp +++ b/trunk/src/app/srs_app_http_api.cpp @@ -390,6 +390,7 @@ int SrsApiSummaries::do_process_request(SrsSocket* skt, SrsHttpMessage* req) SrsMemInfo* m = srs_get_meminfo(); SrsPlatformInfo* p = srs_get_platform_info(); SrsNetworkDevices* n = srs_get_network_devices(); + SrsNetworkRtmpServer* nrs = srs_get_network_rtmp_server(); float self_mem_percent = 0; if (m->MemTotal > 0) { @@ -429,6 +430,7 @@ int SrsApiSummaries::do_process_request(SrsSocket* skt, SrsHttpMessage* req) << JFIELD_ORG("meminfo_ok", (m->ok? "true":"false")) << JFIELD_CONT << JFIELD_ORG("platform_ok", (p->ok? "true":"false")) << JFIELD_CONT << JFIELD_ORG("network_ok", (n_ok? "true":"false")) << JFIELD_CONT + << JFIELD_ORG("network_srs_ok", (nrs->ok? "true":"false")) << JFIELD_CONT << JFIELD_ORG("now_ms", now) << JFIELD_CONT << JFIELD_ORG("self", JOBJECT_START) << JFIELD_ORG("pid", getpid()) << JFIELD_CONT @@ -455,7 +457,12 @@ int SrsApiSummaries::do_process_request(SrsSocket* skt, SrsHttpMessage* req) << JFIELD_ORG("load_15m", p->load_fifteen_minutes) << JFIELD_CONT << JFIELD_ORG("net_sample_time", n_sample_time) << JFIELD_CONT << JFIELD_ORG("net_recv_bytes", nr_bytes) << JFIELD_CONT - << JFIELD_ORG("net_send_bytes", ns_bytes) + << JFIELD_ORG("net_send_bytes", ns_bytes) << JFIELD_CONT + << JFIELD_ORG("srs_sample_time", nrs->sample_time) << JFIELD_CONT + << JFIELD_ORG("srs_recv_bytes", nrs->rbytes) << JFIELD_CONT + << JFIELD_ORG("srs_recv_kbps", nrs->rkbps) << JFIELD_CONT + << JFIELD_ORG("srs_send_bytes", nrs->sbytes) << JFIELD_CONT + << JFIELD_ORG("srs_send_kbps", nrs->skbps) << JOBJECT_END << JOBJECT_END << JOBJECT_END; @@ -707,6 +714,23 @@ SrsHttpApi::~SrsHttpApi() srs_freep(parser); } +void SrsHttpApi::kbps_resample() +{ + // TODO: FIXME: implements it +} + +int64_t SrsHttpApi::get_send_bytes_delta() +{ + // TODO: FIXME: implements it + return 0; +} + +int64_t SrsHttpApi::get_recv_bytes_delta() +{ + // TODO: FIXME: implements it + return 0; +} + int SrsHttpApi::do_cycle() { int ret = ERROR_SUCCESS; diff --git a/trunk/src/app/srs_app_http_api.hpp b/trunk/src/app/srs_app_http_api.hpp index b94938b23..7bc6e26d2 100644 --- a/trunk/src/app/srs_app_http_api.hpp +++ b/trunk/src/app/srs_app_http_api.hpp @@ -196,6 +196,12 @@ private: public: SrsHttpApi(SrsServer* srs_server, st_netfd_t client_stfd, SrsHttpHandler* _handler); virtual ~SrsHttpApi(); +public: + virtual void kbps_resample(); +// interface IKbpsDelta +public: + virtual int64_t get_send_bytes_delta(); + virtual int64_t get_recv_bytes_delta(); protected: virtual int do_cycle(); private: diff --git a/trunk/src/app/srs_app_http_conn.cpp b/trunk/src/app/srs_app_http_conn.cpp index 5ff436f4c..d96138685 100644 --- a/trunk/src/app/srs_app_http_conn.cpp +++ b/trunk/src/app/srs_app_http_conn.cpp @@ -511,6 +511,23 @@ SrsHttpConn::~SrsHttpConn() srs_freep(parser); } +void SrsHttpConn::kbps_resample() +{ + // TODO: FIXME: implements it +} + +int64_t SrsHttpConn::get_send_bytes_delta() +{ + // TODO: FIXME: implements it + return 0; +} + +int64_t SrsHttpConn::get_recv_bytes_delta() +{ + // TODO: FIXME: implements it + return 0; +} + int SrsHttpConn::do_cycle() { int ret = ERROR_SUCCESS; diff --git a/trunk/src/app/srs_app_http_conn.hpp b/trunk/src/app/srs_app_http_conn.hpp index 439ff987e..0dc35d0da 100644 --- a/trunk/src/app/srs_app_http_conn.hpp +++ b/trunk/src/app/srs_app_http_conn.hpp @@ -90,6 +90,12 @@ private: public: SrsHttpConn(SrsServer* srs_server, st_netfd_t client_stfd, SrsHttpHandler* _handler); virtual ~SrsHttpConn(); +public: + virtual void kbps_resample(); +// interface IKbpsDelta +public: + virtual int64_t get_send_bytes_delta(); + virtual int64_t get_recv_bytes_delta(); protected: virtual int do_cycle(); private: diff --git a/trunk/src/app/srs_app_kbps.cpp b/trunk/src/app/srs_app_kbps.cpp index fb6a3e54a..3507227c7 100644 --- a/trunk/src/app/srs_app_kbps.cpp +++ b/trunk/src/app/srs_app_kbps.cpp @@ -38,7 +38,7 @@ SrsKbpsSlice::SrsKbpsSlice() { io.in = NULL; io.out = NULL; - last_bytes = io_bytes_base = starttime = bytes = 0; + last_bytes = io_bytes_base = starttime = bytes = delta_bytes = 0; } SrsKbpsSlice::~SrsKbpsSlice() @@ -98,6 +98,14 @@ void SrsKbpsSlice::sample() } } +IKbpsDelta::IKbpsDelta() +{ +} + +IKbpsDelta::~IKbpsDelta() +{ +} + SrsKbps::SrsKbps() { } @@ -165,22 +173,22 @@ int SrsKbps::get_recv_kbps() return bytes * 8 / duration; } -int SrsKbps::get_send_kbps_sample_high() +int SrsKbps::get_send_kbps_30s() { return os.sample_30s.kbps; } -int SrsKbps::get_recv_kbps_sample_high() +int SrsKbps::get_recv_kbps_30s() { return is.sample_30s.kbps; } -int SrsKbps::get_send_kbps_sample_medium() +int SrsKbps::get_send_kbps_5m() { return os.sample_5m.kbps; } -int SrsKbps::get_recv_kbps_sample_medium() +int SrsKbps::get_recv_kbps_5m() { return is.sample_5m.kbps; } @@ -195,20 +203,44 @@ int64_t SrsKbps::get_recv_bytes() return is.get_total_bytes(); } +int64_t SrsKbps::get_send_bytes_delta() +{ + int64_t delta = os.get_total_bytes() - os.delta_bytes; + os.delta_bytes = os.get_total_bytes(); + return delta; +} + +int64_t SrsKbps::get_recv_bytes_delta() +{ + int64_t delta = is.get_total_bytes() - is.delta_bytes; + is.delta_bytes = is.get_total_bytes(); + return delta; +} + +void SrsKbps::add_delta(IKbpsDelta* delta) +{ + srs_assert(delta); + + // update the total bytes + is.last_bytes += delta->get_recv_bytes_delta(); + os.last_bytes += delta->get_send_bytes_delta(); + + // we donot sample, please use sample() to do resample. +} + void SrsKbps::sample() { + // update the total bytes if (os.io.out) { os.last_bytes = os.io.out->get_send_bytes(); } - // resample - os.sample(); - if (is.io.in) { is.last_bytes = is.io.in->get_recv_bytes(); } // resample is.sample(); + os.sample(); } diff --git a/trunk/src/app/srs_app_kbps.hpp b/trunk/src/app/srs_app_kbps.hpp index daea8f5fc..e6aa257ea 100644 --- a/trunk/src/app/srs_app_kbps.hpp +++ b/trunk/src/app/srs_app_kbps.hpp @@ -30,8 +30,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include -class ISrsProtocolStatistic; -class ISrsProtocolStatistic; +#include /** * a kbps sample, for example, 1minute kbps, @@ -59,7 +58,8 @@ public: * send_bytes = bytes + last_bytes - io_bytes_base * so, the bytes sent duration current session is: * send_bytes = last_bytes - io_bytes_base -* @remark user use set_io to start new session. +* @remark use set_io to start new session. +* @remakr the slice is a data collection object driven by SrsKbps. */ class SrsKbpsSlice { @@ -69,6 +69,8 @@ private: ISrsProtocolStatistic* out; }; public: + // the slice io used for SrsKbps to invoke, + // the SrsKbpsSlice itself never use it. slice_io io; // session startup bytes // @remark, use total_bytes() to get the total bytes of slice. @@ -86,6 +88,9 @@ public: SrsKbpsSample sample_1m; SrsKbpsSample sample_5m; SrsKbpsSample sample_60m; +public: + // for the delta bytes. + int64_t delta_bytes; public: SrsKbpsSlice(); virtual ~SrsKbpsSlice(); @@ -101,9 +106,36 @@ public: }; /** -* to statistic the kbps of io. +* the interface which provices delta of bytes. */ -class SrsKbps +class IKbpsDelta +{ +public: + IKbpsDelta(); + virtual ~IKbpsDelta(); +public: + virtual int64_t get_send_bytes_delta() = 0; + virtual int64_t get_recv_bytes_delta() = 0; +}; + +/** +* to statistic the kbps of io. +* itself can be a statistic source, for example, used for SRS bytes stat. +* there are two usage scenarios: +* 1. connections to calc kbps: +* set_io(in, out) +* sample() +* get_xxx_kbps(). +* the connections know how many bytes already send/recv. +* 2. server to calc kbps: +* set_io(NULL, NULL) +* for each connection in connections: +* add_delta(connections) // where connection is a IKbpsDelta* +* sample() +* get_xxx_kbps(). +* the server never know how many bytes already send/recv, for the connection maybe closed. +*/ +class SrsKbps : public virtual ISrsProtocolStatistic, public virtual IKbpsDelta { private: SrsKbpsSlice is; @@ -130,11 +162,11 @@ public: virtual int get_send_kbps(); virtual int get_recv_kbps(); // 30s - virtual int get_send_kbps_sample_high(); - virtual int get_recv_kbps_sample_high(); + virtual int get_send_kbps_30s(); + virtual int get_recv_kbps_30s(); // 5m - virtual int get_send_kbps_sample_medium(); - virtual int get_recv_kbps_sample_medium(); + virtual int get_send_kbps_5m(); + virtual int get_recv_kbps_5m(); public: /** * get the total send/recv bytes, from the startup of the oldest io. @@ -142,9 +174,26 @@ public: */ virtual int64_t get_send_bytes(); virtual int64_t get_recv_bytes(); + /** + * get the delta of send/recv bytes. + * @remark, used for add_delta to calc the total system bytes/kbps. + */ + virtual int64_t get_send_bytes_delta(); + virtual int64_t get_recv_bytes_delta(); public: /** - * resample all samples. + * add delta to kbps clac mechenism. + * we donot know the total bytes, but know the delta, for instance, + * for rtmp server to calc total bytes and kbps. + * @remark user must invoke sample() when invoke this method. + * @param delta, assert should never be NULL. + */ + virtual void add_delta(IKbpsDelta* delta); + /** + * resample all samples, ignore if in/out is NULL. + * used for user to calc the kbps, to sample new kbps value. + * @remark if user, for instance, the rtmp server to calc the total bytes, + * use the add_delta() is better solutions. */ virtual void sample(); }; diff --git a/trunk/src/app/srs_app_rtmp_conn.cpp b/trunk/src/app/srs_app_rtmp_conn.cpp index a6622ff0c..615d7230d 100644 --- a/trunk/src/app/srs_app_rtmp_conn.cpp +++ b/trunk/src/app/srs_app_rtmp_conn.cpp @@ -94,6 +94,11 @@ SrsRtmpConn::~SrsRtmpConn() srs_freep(kbps); } +void SrsRtmpConn::kbps_resample() +{ + kbps->sample(); +} + // TODO: return detail message when error for client. int SrsRtmpConn::do_cycle() { @@ -168,6 +173,16 @@ int SrsRtmpConn::on_reload_vhost_removed(string vhost) return ret; } + +int64_t SrsRtmpConn::get_send_bytes_delta() +{ + return kbps->get_send_bytes_delta(); +} + +int64_t SrsRtmpConn::get_recv_bytes_delta() +{ + return kbps->get_recv_bytes_delta(); +} int SrsRtmpConn::service_cycle() { @@ -510,8 +525,8 @@ int SrsRtmpConn::playing(SrsSource* source) srs_trace("-> "SRS_LOG_ID_PLAY " time=%"PRId64", msgs=%d, okbps=%d,%d,%d, ikbps=%d,%d,%d", pithy_print.age(), count, - kbps->get_send_kbps(), kbps->get_send_kbps_sample_high(), kbps->get_send_kbps_sample_medium(), - kbps->get_recv_kbps(), kbps->get_recv_kbps_sample_high(), kbps->get_recv_kbps_sample_medium()); + kbps->get_send_kbps(), kbps->get_send_kbps_30s(), kbps->get_send_kbps_5m(), + kbps->get_recv_kbps(), kbps->get_recv_kbps_30s(), kbps->get_recv_kbps_5m()); } if (count <= 0) { @@ -601,8 +616,8 @@ int SrsRtmpConn::fmle_publish(SrsSource* source) kbps->sample(); srs_trace("<- "SRS_LOG_ID_CLIENT_PUBLISH " time=%"PRId64", okbps=%d,%d,%d, ikbps=%d,%d,%d", pithy_print.age(), - kbps->get_send_kbps(), kbps->get_send_kbps_sample_high(), kbps->get_send_kbps_sample_medium(), - kbps->get_recv_kbps(), kbps->get_recv_kbps_sample_high(), kbps->get_recv_kbps_sample_medium()); + kbps->get_send_kbps(), kbps->get_send_kbps_30s(), kbps->get_send_kbps_5m(), + kbps->get_recv_kbps(), kbps->get_recv_kbps_30s(), kbps->get_recv_kbps_5m()); } // process UnPublish event. @@ -683,8 +698,8 @@ int SrsRtmpConn::flash_publish(SrsSource* source) srs_trace("<- "SRS_LOG_ID_WEB_PUBLISH " time=%"PRId64", okbps=%d,%d,%d, ikbps=%d,%d,%d", pithy_print.age(), - kbps->get_send_kbps(), kbps->get_send_kbps_sample_high(), kbps->get_send_kbps_sample_medium(), - kbps->get_recv_kbps(), kbps->get_recv_kbps_sample_high(), kbps->get_recv_kbps_sample_medium()); + kbps->get_send_kbps(), kbps->get_send_kbps_30s(), kbps->get_send_kbps_5m(), + kbps->get_recv_kbps(), kbps->get_recv_kbps_30s(), kbps->get_recv_kbps_5m()); } // process UnPublish event. diff --git a/trunk/src/app/srs_app_rtmp_conn.hpp b/trunk/src/app/srs_app_rtmp_conn.hpp index d2e47a14a..2566f2b30 100644 --- a/trunk/src/app/srs_app_rtmp_conn.hpp +++ b/trunk/src/app/srs_app_rtmp_conn.hpp @@ -51,7 +51,7 @@ class SrsKbps; /** * the client provides the main logic control for RTMP clients. */ -class SrsRtmpConn : public SrsConnection, public ISrsReloadHandler +class SrsRtmpConn : public virtual SrsConnection, public virtual ISrsReloadHandler { private: SrsRequest* req; @@ -68,11 +68,17 @@ private: public: SrsRtmpConn(SrsServer* srs_server, st_netfd_t client_stfd); virtual ~SrsRtmpConn(); +public: + virtual void kbps_resample(); protected: virtual int do_cycle(); // interface ISrsReloadHandler public: virtual int on_reload_vhost_removed(std::string vhost); +// interface IKbpsDelta +public: + virtual int64_t get_send_bytes_delta(); + virtual int64_t get_recv_bytes_delta(); private: // when valid and connected to vhost/app, service the client. virtual int service_cycle(); diff --git a/trunk/src/app/srs_app_server.cpp b/trunk/src/app/srs_app_server.cpp index 76ac96a60..025aa1f81 100644 --- a/trunk/src/app/srs_app_server.cpp +++ b/trunk/src/app/srs_app_server.cpp @@ -45,6 +45,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include #include #include +#include // signal defines. #define SIGNAL_RELOAD SIGHUP @@ -82,6 +83,10 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // SRS_SYS_CYCLE_INTERVAL * SRS_SYS_NETWORK_DEVICE_RESOLUTION_TIMES #define SRS_SYS_NETWORK_DEVICE_RESOLUTION_TIMES 90 +// update network devices info interval: +// SRS_SYS_CYCLE_INTERVAL * SRS_SYS_NETWORK_RTMP_SERVER_RESOLUTION_TIMES +#define SRS_SYS_NETWORK_RTMP_SERVER_RESOLUTION_TIMES 90 + SrsListener::SrsListener(SrsServer* server, SrsListenerType type) { fd = -1; @@ -312,7 +317,8 @@ SrsServer::SrsServer() signal_gmc_stop = false; pid_fd = -1; - signal_manager = new SrsSignalManager(this); + signal_manager = NULL; + kbps = NULL; // donot new object in constructor, // for some global instance is not ready now, @@ -372,6 +378,7 @@ void SrsServer::destroy() } srs_freep(signal_manager); + srs_freep(kbps); for (std::vector::iterator it = conns.begin(); it != conns.end();) { SrsConnection* conn = *it; @@ -398,6 +405,13 @@ int SrsServer::initialize() srs_assert(_srs_config); _srs_config->subscribe(this); + srs_assert(!signal_manager); + signal_manager = new SrsSignalManager(this); + + srs_assert(!kbps); + kbps = new SrsKbps(); + kbps->set_io(NULL, NULL); + #ifdef SRS_AUTO_HTTP_API srs_assert(!http_api_handler); http_api_handler = SrsHttpHandler::create_http_api(); @@ -610,6 +624,9 @@ void SrsServer::remove(SrsConnection* conn) srs_info("conn removed. conns=%d", (int)conns.size()); + // resample the resource of specified connection. + resample_kbps(conn); + // all connections are created by server, // so we free it here. srs_freep(conn); @@ -651,11 +668,12 @@ int SrsServer::do_cycle() max = srs_max(max, SRS_SYS_MEMINFO_RESOLUTION_TIMES); max = srs_max(max, SRS_SYS_PLATFORM_INFO_RESOLUTION_TIMES); max = srs_max(max, SRS_SYS_NETWORK_DEVICE_RESOLUTION_TIMES); + max = srs_max(max, SRS_SYS_NETWORK_RTMP_SERVER_RESOLUTION_TIMES); // the deamon thread, update the time cache while (true) { // the interval in config. - int64_t heartbeat_max_resolution = _srs_config->get_heartbeat_interval() / 100; + int heartbeat_max_resolution = (int)(_srs_config->get_heartbeat_interval() / 100); // dynamic fetch the max. int __max = max; @@ -689,30 +707,43 @@ int SrsServer::do_cycle() // update the cache time or rusage. if ((i % SRS_SYS_TIME_RESOLUTION_MS_TIMES) == 0) { + srs_info("update current time cache."); srs_update_system_time_ms(); } if ((i % SRS_SYS_RUSAGE_RESOLUTION_TIMES) == 0) { + srs_info("update resource info, rss."); srs_update_system_rusage(); } if ((i % SRS_SYS_CPU_STAT_RESOLUTION_TIMES) == 0) { + srs_info("update cpu info, usage."); srs_update_proc_stat(); } if ((i % SRS_SYS_MEMINFO_RESOLUTION_TIMES) == 0) { + srs_info("update memory info, usage/free."); srs_update_meminfo(); } if ((i % SRS_SYS_PLATFORM_INFO_RESOLUTION_TIMES) == 0) { + srs_info("update platform info, uptime/load."); srs_update_platform_info(); } if ((i % SRS_SYS_NETWORK_DEVICE_RESOLUTION_TIMES) == 0) { + srs_info("update network devices info."); srs_update_network_devices(); } + if ((i % SRS_SYS_NETWORK_RTMP_SERVER_RESOLUTION_TIMES) == 0) { + srs_info("update network rtmp server info."); + resample_kbps(NULL); + srs_update_rtmp_server(kbps); + } #ifdef SRS_AUTO_HTTP_PARSER if (_srs_config->get_heartbeat_enabled()) { if ((i % heartbeat_max_resolution) == 0) { + srs_info("do http heartbeat, for internal server to report."); http_heartbeat->heartbeat(); } } #endif + srs_info("server main thread loop"); } } @@ -801,6 +832,32 @@ void SrsServer::close_listeners(SrsListenerType type) } } +void SrsServer::resample_kbps(SrsConnection* conn, bool do_resample) +{ + // resample all when conn is NULL. + if (!conn) { + for (std::vector::iterator it = conns.begin(); it != conns.end(); ++it) { + SrsConnection* client = *it; + srs_assert(client); + + // only resample, do resample when all finished. + resample_kbps(client, false); + } + + kbps->sample(); + return; + } + + // resample for connection. + conn->kbps_resample(); + + kbps->add_delta(conn); + + if (do_resample) { + kbps->sample(); + } +} + int SrsServer::accept_client(SrsListenerType type, st_netfd_t client_stfd) { int ret = ERROR_SUCCESS; diff --git a/trunk/src/app/srs_app_server.hpp b/trunk/src/app/srs_app_server.hpp index a9bc4a662..3f7dac932 100644 --- a/trunk/src/app/srs_app_server.hpp +++ b/trunk/src/app/srs_app_server.hpp @@ -41,6 +41,7 @@ class SrsConnection; class SrsHttpHandler; class SrsIngester; class SrsHttpHeartbeat; +class SrsKbps; // listener type for server to identify the connection, // that is, use different type to process the connection. @@ -107,6 +108,10 @@ private: static void sig_catcher(int signo); }; +/** +* SRS RTMP server, initialize and listen, +* start connection service thread, destroy client. +*/ class SrsServer : public ISrsReloadHandler { private: @@ -127,6 +132,7 @@ private: std::vector conns; std::vector listeners; SrsSignalManager* signal_manager; + SrsKbps* kbps; bool signal_reload; bool signal_gmc_stop; public: @@ -150,6 +156,8 @@ private: virtual int listen_http_api(); virtual int listen_http_stream(); virtual void close_listeners(SrsListenerType type); + // resample the server kbps. resample all when conn is NULL. + virtual void resample_kbps(SrsConnection* conn, bool do_resample = true); // internal only public: virtual int accept_client(SrsListenerType type, st_netfd_t client_stfd); diff --git a/trunk/src/app/srs_app_utility.cpp b/trunk/src/app/srs_app_utility.cpp index 023b94d72..23d658bd0 100644 --- a/trunk/src/app/srs_app_utility.cpp +++ b/trunk/src/app/srs_app_utility.cpp @@ -34,6 +34,7 @@ using namespace std; #include #include #include +#include #define SRS_LOCAL_LOOP_IP "127.0.0.1" @@ -523,6 +524,38 @@ void srs_update_network_devices() } } +SrsNetworkRtmpServer::SrsNetworkRtmpServer() +{ + ok = false; + sample_time = rbytes = sbytes = 0; +} + +static SrsNetworkRtmpServer _srs_network_rtmp_server; + +SrsNetworkRtmpServer* srs_get_network_rtmp_server() +{ + return &_srs_network_rtmp_server; +} + +void srs_update_rtmp_server(SrsKbps* kbps) +{ + SrsNetworkRtmpServer& r = _srs_network_rtmp_server; + + r.ok = true; + + r.sample_time = srs_get_system_time_ms(); + + r.rbytes = kbps->get_recv_bytes(); + r.rkbps = kbps->get_recv_kbps(); + r.rkbps_30s = kbps->get_recv_kbps_30s(); + r.rkbps_5m = kbps->get_recv_kbps_5m(); + + r.sbytes = kbps->get_send_bytes(); + r.skbps = kbps->get_send_kbps(); + r.skbps_30s = kbps->get_send_kbps_30s(); + r.skbps_5m = kbps->get_send_kbps_5m(); +} + vector _srs_system_ipv4_ips; void retrieve_local_ipv4_ips() diff --git a/trunk/src/app/srs_app_utility.hpp b/trunk/src/app/srs_app_utility.hpp index a7fec02a4..dedfc6a53 100644 --- a/trunk/src/app/srs_app_utility.hpp +++ b/trunk/src/app/srs_app_utility.hpp @@ -35,6 +35,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include +class SrsKbps; + /** * convert level in string to log level in int. * @return the log level defined in SrsLogLevel. @@ -390,6 +392,36 @@ extern int srs_get_network_devices_count(); // the deamon st-thread will update it. extern void srs_update_network_devices(); +// srs rtmp network summary +class SrsNetworkRtmpServer +{ +public: + // whether the network device is ok. + bool ok; + + // the sample time in ms. + int64_t sample_time; + + // data for receive. + int64_t rbytes; + int rkbps; + int rkbps_30s; + int rkbps_5m; + + // data for transmit + int64_t sbytes; + int skbps; + int skbps_30s; + int skbps_5m; + + SrsNetworkRtmpServer(); +}; + +// get network devices info, use cache to avoid performance problem. +extern SrsNetworkRtmpServer* srs_get_network_rtmp_server(); +// the deamon st-thread will update it. +extern void srs_update_rtmp_server(SrsKbps* kbps); + // get local ip, fill to @param ips extern void srs_retrieve_local_ipv4_ips(); extern std::vector& srs_get_local_ipv4_ips(); diff --git a/trunk/src/core/srs_core.hpp b/trunk/src/core/srs_core.hpp index 0b346bd63..9bc6d3c57 100644 --- a/trunk/src/core/srs_core.hpp +++ b/trunk/src/core/srs_core.hpp @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // current release version #define VERSION_MAJOR "0" #define VERSION_MINOR "9" -#define VERSION_REVISION "125" +#define VERSION_REVISION "126" #define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION // server info. #define RTMP_SIG_SRS_KEY "SRS"