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

STAT: Refine stat for global server.

This commit is contained in:
winlin 2022-08-27 18:50:13 +08:00
parent da24de5ecb
commit 4e3ea99ccd
6 changed files with 17 additions and 15 deletions

View file

@ -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()
{
@ -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);

View file

@ -57,6 +57,7 @@ public:
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

View file

@ -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;

View file

@ -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);

View file

@ -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)
@ -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);
}

View file

@ -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);
}