mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
* API: support metrics for prometheus. * Metrics: optimize metrics statistics info. * Refine: remove redundant code. * Refine: fix metrics srs_streams param. * Metrics: add major param. * Metrics: refine params and metric comments. * For #2899: API: Support exporter for Prometheus. v5.0.67 Co-authored-by: winlin <winlin@vip.126.com>
This commit is contained in:
parent
e31f3b0e64
commit
981cab40d3
17 changed files with 236 additions and 10 deletions
|
@ -241,6 +241,9 @@ SrsStatistic* SrsStatistic::_instance = NULL;
|
|||
SrsStatistic::SrsStatistic()
|
||||
{
|
||||
kbps = new SrsKbps();
|
||||
|
||||
nb_clients_ = 0;
|
||||
nb_errs_ = 0;
|
||||
}
|
||||
|
||||
SrsStatistic::~SrsStatistic()
|
||||
|
@ -421,11 +424,13 @@ srs_error_t SrsStatistic::on_client(std::string id, SrsRequest* req, ISrsExpire*
|
|||
// @see https://github.com/ossrs/srs/issues/2311
|
||||
srs_freep(client->req);
|
||||
client->req = req->copy();
|
||||
|
||||
nb_clients_++;
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
void SrsStatistic::on_disconnect(std::string id)
|
||||
void SrsStatistic::on_disconnect(std::string id, srs_error_t err)
|
||||
{
|
||||
std::map<std::string, SrsStatisticClient*>::iterator it = clients.find(id);
|
||||
if (it == clients.end()) return;
|
||||
|
@ -440,6 +445,10 @@ void SrsStatistic::on_disconnect(std::string id)
|
|||
stream->nb_clients--;
|
||||
vhost->nb_clients--;
|
||||
|
||||
if (srs_error_code(err) != ERROR_SUCCESS) {
|
||||
nb_errs_++;
|
||||
}
|
||||
|
||||
cleanup_stream(stream);
|
||||
}
|
||||
|
||||
|
@ -721,3 +730,19 @@ SrsStatisticStream* SrsStatistic::create_stream(SrsStatisticVhost* vhost, SrsReq
|
|||
return stream;
|
||||
}
|
||||
|
||||
srs_error_t SrsStatistic::dumps_metrics(int64_t& send_bytes, int64_t& recv_bytes, int64_t& nstreams, int64_t& nclients, int64_t& total_nclients, int64_t& nerrs)
|
||||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
send_bytes = kbps->get_send_bytes();
|
||||
recv_bytes = kbps->get_recv_bytes();
|
||||
|
||||
nstreams = streams.size();
|
||||
nclients = clients.size();
|
||||
|
||||
total_nclients = nb_clients_;
|
||||
nerrs = nb_errs_;
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue