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:
parent
da24de5ecb
commit
4e3ea99ccd
6 changed files with 17 additions and 15 deletions
|
@ -41,6 +41,7 @@ using namespace std;
|
||||||
#include <srs_protocol_amf0.hpp>
|
#include <srs_protocol_amf0.hpp>
|
||||||
#include <srs_app_utility.hpp>
|
#include <srs_app_utility.hpp>
|
||||||
#include <srs_app_st.hpp>
|
#include <srs_app_st.hpp>
|
||||||
|
#include <srs_app_statistic.hpp>
|
||||||
|
|
||||||
ISrsHttpConnOwner::ISrsHttpConnOwner()
|
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)
|
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,
|
// 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.
|
||||||
manager->remove(this);
|
manager->remove(this);
|
||||||
|
|
|
@ -57,6 +57,7 @@ public:
|
||||||
virtual srs_error_t on_conn_done(srs_error_t r0) = 0;
|
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.
|
// The http connection which request the static or stream content.
|
||||||
class SrsHttpConn : public ISrsStartableConneciton, public ISrsCoroutineHandler
|
class SrsHttpConn : public ISrsStartableConneciton, public ISrsCoroutineHandler
|
||||||
, public ISrsExpire
|
, public ISrsExpire
|
||||||
|
|
|
@ -591,7 +591,7 @@ srs_error_t SrsRtcPlayStream::start()
|
||||||
// update the statistic when client discoveried.
|
// update the statistic when client discoveried.
|
||||||
SrsStatistic* stat = SrsStatistic::instance();
|
SrsStatistic* stat = SrsStatistic::instance();
|
||||||
if ((err = stat->on_client(cid_.c_str(), req_, session_, SrsRtcConnPlay)) != srs_success) {
|
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;
|
is_started = true;
|
||||||
|
|
|
@ -1458,6 +1458,11 @@ srs_error_t SrsRtmpConn::cycle()
|
||||||
{
|
{
|
||||||
srs_error_t err = do_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.
|
// Notify manager to remove it.
|
||||||
// Note that we create this object, so we use manager to remove it.
|
// Note that we create this object, so we use manager to remove it.
|
||||||
manager->remove(this);
|
manager->remove(this);
|
||||||
|
|
|
@ -1298,12 +1298,8 @@ void SrsServer::resample_kbps()
|
||||||
stat->kbps_add_delta(c->get_id().c_str(), conn);
|
stat->kbps_add_delta(c->get_id().c_str(), conn);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: FXME: support all other connections.
|
// Update the global server level statistics.
|
||||||
|
stat->kbps_sample();
|
||||||
// sample the kbps, get the stat.
|
|
||||||
SrsKbps* kbps = stat->kbps_sample();
|
|
||||||
|
|
||||||
srs_update_rtmp_server((int)conn_manager->size(), kbps);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
srs_error_t SrsServer::accept_client(SrsListenerType type, srs_netfd_t stfd)
|
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)
|
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.
|
// use manager to free it async.
|
||||||
conn_manager->remove(c);
|
conn_manager->remove(c);
|
||||||
}
|
}
|
||||||
|
|
|
@ -195,12 +195,12 @@ string srs_generate_tc_url(string host, string vhost, string app, int port)
|
||||||
string tcUrl = "rtmp://";
|
string tcUrl = "rtmp://";
|
||||||
|
|
||||||
if (vhost == SRS_CONSTS_RTMP_DEFAULT_VHOST) {
|
if (vhost == SRS_CONSTS_RTMP_DEFAULT_VHOST) {
|
||||||
tcUrl += host;
|
tcUrl += host.empty() ? SRS_CONSTS_RTMP_DEFAULT_VHOST : host;
|
||||||
} else {
|
} else {
|
||||||
tcUrl += vhost;
|
tcUrl += vhost;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (port != SRS_CONSTS_RTMP_DEFAULT_PORT) {
|
if (port && port != SRS_CONSTS_RTMP_DEFAULT_PORT) {
|
||||||
tcUrl += ":" + srs_int2str(port);
|
tcUrl += ":" + srs_int2str(port);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue