From bc569d91a0750eefffdd7bd6c85c1fde5a8eb0f9 Mon Sep 17 00:00:00 2001 From: winlin Date: Mon, 29 Aug 2022 07:54:40 +0800 Subject: [PATCH] STAT: Ignore stat for API, only for HTTP streaming clients. --- trunk/src/app/srs_app_http_conn.cpp | 10 ++++++---- trunk/src/app/srs_app_statistic.cpp | 11 +++++------ trunk/src/app/srs_app_statistic.hpp | 2 +- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/trunk/src/app/srs_app_http_conn.cpp b/trunk/src/app/srs_app_http_conn.cpp index 5528d8902..c2408cf14 100644 --- a/trunk/src/app/srs_app_http_conn.cpp +++ b/trunk/src/app/srs_app_http_conn.cpp @@ -400,10 +400,12 @@ srs_error_t SrsHttpxConn::on_message_done(ISrsHttpMessage* r, SrsHttpResponseWri srs_error_t SrsHttpxConn::on_conn_done(srs_error_t r0) { - // Update statistic when done. - SrsStatistic* stat = SrsStatistic::instance(); - stat->kbps_add_delta(get_id().c_str(), this); - stat->on_disconnect(get_id().c_str()); + // Only stat the HTTP streaming clients, ignore all API clients. + bool exists = false; + SrsStatistic::instance()->on_disconnect(get_id().c_str(), &exists); + if (exists) { + SrsStatistic::instance()->kbps_add_delta(get_id().c_str(), this); + } // Because we use manager to manage this object, // not the http connection object, so we must remove it here. diff --git a/trunk/src/app/srs_app_statistic.cpp b/trunk/src/app/srs_app_statistic.cpp index f5a202f64..94052266b 100644 --- a/trunk/src/app/srs_app_statistic.cpp +++ b/trunk/src/app/srs_app_statistic.cpp @@ -425,13 +425,12 @@ srs_error_t SrsStatistic::on_client(std::string id, SrsRequest* req, ISrsExpire* return err; } -void SrsStatistic::on_disconnect(std::string id) +void SrsStatistic::on_disconnect(std::string id, bool* exists) { - std::map::iterator it; - if ((it = clients.find(id)) == clients.end()) { - return; - } - + std::map::iterator it = clients.find(id); + if (exists) *exists = (it != clients.end()); + if (it == clients.end()) return; + SrsStatisticClient* client = it->second; SrsStatisticStream* stream = client->stream; SrsStatisticVhost* vhost = stream->vhost; diff --git a/trunk/src/app/srs_app_statistic.hpp b/trunk/src/app/srs_app_statistic.hpp index 7c4ea5317..88ac4fc6a 100644 --- a/trunk/src/app/srs_app_statistic.hpp +++ b/trunk/src/app/srs_app_statistic.hpp @@ -179,7 +179,7 @@ public: // @remark the on_disconnect always call, while the on_client is call when // only got the request object, so the client specified by id maybe not // exists in stat. - virtual void on_disconnect(std::string id); + virtual void on_disconnect(std::string id, bool* exists = NULL); private: // Cleanup the stream if stream is not active and for the last client. void cleanup_stream(SrsStatisticStream* stream);