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

STAT: Add kbps for client.

This commit is contained in:
winlin 2022-08-24 12:42:21 +08:00
parent f9941a325b
commit 41155b7789
2 changed files with 24 additions and 0 deletions

View file

@ -186,10 +186,16 @@ SrsStatisticClient::SrsStatisticClient()
req = NULL; req = NULL;
type = SrsRtmpConnUnknown; type = SrsRtmpConnUnknown;
create = srs_get_system_time(); create = srs_get_system_time();
clk = new SrsWallClock();
kbps = new SrsKbps(clk);
kbps->set_io(NULL, NULL);
} }
SrsStatisticClient::~SrsStatisticClient() SrsStatisticClient::~SrsStatisticClient()
{ {
srs_freep(kbps);
srs_freep(clk);
srs_freep(req); srs_freep(req);
} }
@ -208,6 +214,12 @@ srs_error_t SrsStatisticClient::dumps(SrsJsonObject* obj)
obj->set("type", SrsJsonAny::str(srs_client_type_string(type).c_str())); obj->set("type", SrsJsonAny::str(srs_client_type_string(type).c_str()));
obj->set("publish", SrsJsonAny::boolean(srs_client_type_is_publish(type))); obj->set("publish", SrsJsonAny::boolean(srs_client_type_is_publish(type)));
obj->set("alive", SrsJsonAny::number(srsu2ms(srs_get_system_time() - create) / 1000.0)); obj->set("alive", SrsJsonAny::number(srsu2ms(srs_get_system_time() - create) / 1000.0));
SrsJsonObject* okbps = SrsJsonAny::object();
obj->set("kbps", okbps);
okbps->set("recv_30s", SrsJsonAny::integer(kbps->get_recv_kbps_30s()));
okbps->set("send_30s", SrsJsonAny::integer(kbps->get_send_kbps_30s()));
return err; return err;
} }
@ -446,6 +458,7 @@ void SrsStatistic::kbps_add_delta(std::string id, ISrsKbpsDelta* delta)
// add delta of connection to kbps. // add delta of connection to kbps.
// for next sample() of server kbps can get the stat. // for next sample() of server kbps can get the stat.
kbps->add_delta(in, out); kbps->add_delta(in, out);
client->kbps->add_delta(in, out);
client->stream->kbps->add_delta(in, out); client->stream->kbps->add_delta(in, out);
client->stream->vhost->kbps->add_delta(in, out); client->stream->vhost->kbps->add_delta(in, out);
} }
@ -467,6 +480,13 @@ SrsKbps* SrsStatistic::kbps_sample()
stream->kbps->sample(); stream->kbps->sample();
} }
} }
if (true) {
std::map<std::string, SrsStatisticClient*>::iterator it;
for (it = clients.begin(); it != clients.end(); it++) {
SrsStatisticClient* client = it->second;
client->kbps->sample();
}
}
return kbps; return kbps;
} }

View file

@ -100,6 +100,10 @@ public:
SrsRtmpConnType type; SrsRtmpConnType type;
std::string id; std::string id;
srs_utime_t create; srs_utime_t create;
public:
// The stream total kbps.
SrsKbps* kbps;
SrsWallClock* clk;
public: public:
SrsStatisticClient(); SrsStatisticClient();
virtual ~SrsStatisticClient(); virtual ~SrsStatisticClient();