Skip to content

Commit

Permalink
STAT: Refine stat for global server.
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Aug 27, 2022
1 parent 7577a2d commit 76c825e
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 15 deletions.
6 changes: 6 additions & 0 deletions trunk/src/app/srs_app_http_conn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ using namespace std;
#include <srs_protocol_amf0.hpp>
#include <srs_app_utility.hpp>
#include <srs_app_st.hpp>
#include <srs_app_statistic.hpp>

ISrsHttpConnOwner::ISrsHttpConnOwner()
{
Expand Down Expand Up @@ -411,6 +412,11 @@ srs_error_t SrsResponseOnlyHttpConn::on_message_done(ISrsHttpMessage* r, SrsHttp

srs_error_t SrsResponseOnlyHttpConn::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());

// Because we use manager to manage this object,
// not the http connection object, so we must remove it here.
manager->remove(this);
Expand Down
1 change: 1 addition & 0 deletions trunk/src/app/srs_app_http_conn.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class ISrsHttpConnOwner
virtual srs_error_t on_conn_done(srs_error_t r0) = 0;
};

// TODO: FIXME: Should rename to roundtrip or responder, not connection.
// The http connection which request the static or stream content.
class SrsHttpConn : public ISrsStartableConneciton, public ISrsCoroutineHandler
, public ISrsExpire
Expand Down
2 changes: 1 addition & 1 deletion trunk/src/app/srs_app_rtc_conn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ srs_error_t SrsRtcPlayStream::start()
// update the statistic when client discoveried.
SrsStatistic* stat = SrsStatistic::instance();
if ((err = stat->on_client(cid_.c_str(), req_, session_, SrsRtcConnPlay)) != srs_success) {
return srs_error_wrap(err, "rtc: stat client");
return srs_error_wrap(err, "rtc: stat client");
}

is_started = true;
Expand Down
5 changes: 5 additions & 0 deletions trunk/src/app/srs_app_rtmp_conn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1458,6 +1458,11 @@ srs_error_t SrsRtmpConn::cycle()
{
srs_error_t err = do_cycle();

// Update statistic when done.
SrsStatistic* stat = SrsStatistic::instance();
stat->kbps_add_delta(get_id().c_str(), this);
stat->on_disconnect(get_id().c_str());

// Notify manager to remove it.
// Note that we create this object, so we use manager to remove it.
manager->remove(this);
Expand Down
14 changes: 2 additions & 12 deletions trunk/src/app/srs_app_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1298,12 +1298,8 @@ void SrsServer::resample_kbps()
stat->kbps_add_delta(c->get_id().c_str(), conn);
}

// TODO: FXME: support all other connections.

// sample the kbps, get the stat.
SrsKbps* kbps = stat->kbps_sample();

srs_update_rtmp_server((int)conn_manager->size(), kbps);
// Update the global server level statistics.
stat->kbps_sample();
}

srs_error_t SrsServer::accept_client(SrsListenerType type, srs_netfd_t stfd)
Expand Down Expand Up @@ -1401,12 +1397,6 @@ srs_error_t SrsServer::fd_to_resource(SrsListenerType type, srs_netfd_t stfd, IS

void SrsServer::remove(ISrsResource* c)
{
ISrsStartableConneciton* conn = dynamic_cast<ISrsStartableConneciton*>(c);

SrsStatistic* stat = SrsStatistic::instance();
stat->kbps_add_delta(c->get_id().c_str(), conn);
stat->on_disconnect(c->get_id().c_str());

// use manager to free it async.
conn_manager->remove(c);
}
Expand Down
4 changes: 2 additions & 2 deletions trunk/src/protocol/srs_protocol_utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,12 @@ string srs_generate_tc_url(string host, string vhost, string app, int port)
string tcUrl = "rtmp://";

if (vhost == SRS_CONSTS_RTMP_DEFAULT_VHOST) {
tcUrl += host;
tcUrl += host.empty() ? SRS_CONSTS_RTMP_DEFAULT_VHOST : host;
} else {
tcUrl += vhost;
}

if (port != SRS_CONSTS_RTMP_DEFAULT_PORT) {
if (port && port != SRS_CONSTS_RTMP_DEFAULT_PORT) {
tcUrl += ":" + srs_int2str(port);
}

Expand Down

0 comments on commit 76c825e

Please sign in to comment.