1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

STAT: Ignore stat for API, only for HTTP streaming clients.

This commit is contained in:
winlin 2022-08-29 07:54:40 +08:00
parent 28154e820c
commit bc569d91a0
3 changed files with 12 additions and 11 deletions

View file

@ -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) srs_error_t SrsHttpxConn::on_conn_done(srs_error_t r0)
{ {
// Update statistic when done. // Only stat the HTTP streaming clients, ignore all API clients.
SrsStatistic* stat = SrsStatistic::instance(); bool exists = false;
stat->kbps_add_delta(get_id().c_str(), this); SrsStatistic::instance()->on_disconnect(get_id().c_str(), &exists);
stat->on_disconnect(get_id().c_str()); if (exists) {
SrsStatistic::instance()->kbps_add_delta(get_id().c_str(), this);
}
// Because we use manager to manage this object, // Because we use manager to manage this object,
// not the http connection object, so we must remove it here. // not the http connection object, so we must remove it here.

View file

@ -425,12 +425,11 @@ srs_error_t SrsStatistic::on_client(std::string id, SrsRequest* req, ISrsExpire*
return err; return err;
} }
void SrsStatistic::on_disconnect(std::string id) void SrsStatistic::on_disconnect(std::string id, bool* exists)
{ {
std::map<std::string, SrsStatisticClient*>::iterator it; std::map<std::string, SrsStatisticClient*>::iterator it = clients.find(id);
if ((it = clients.find(id)) == clients.end()) { if (exists) *exists = (it != clients.end());
return; if (it == clients.end()) return;
}
SrsStatisticClient* client = it->second; SrsStatisticClient* client = it->second;
SrsStatisticStream* stream = client->stream; SrsStatisticStream* stream = client->stream;

View file

@ -179,7 +179,7 @@ public:
// @remark the on_disconnect always call, while the on_client is call when // @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 // only got the request object, so the client specified by id maybe not
// exists in stat. // exists in stat.
virtual void on_disconnect(std::string id); virtual void on_disconnect(std::string id, bool* exists = NULL);
private: private:
// Cleanup the stream if stream is not active and for the last client. // Cleanup the stream if stream is not active and for the last client.
void cleanup_stream(SrsStatisticStream* stream); void cleanup_stream(SrsStatisticStream* stream);