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

RTC: Stat the UDP packets and addresses

This commit is contained in:
winlin 2021-02-07 20:12:54 +08:00
parent 2b73c1c7e6
commit ca3ac467a3
2 changed files with 25 additions and 1 deletions

View file

@ -43,6 +43,12 @@ using namespace std;
#include <srs_kernel_utility.hpp> #include <srs_kernel_utility.hpp>
#include <srs_kernel_buffer.hpp> #include <srs_kernel_buffer.hpp>
#include <srs_protocol_kbps.hpp>
SrsPps* _srs_pps_pkts = new SrsPps(_srs_clock);
SrsPps* _srs_pps_addrs = new SrsPps(_srs_clock);
SrsPps* _srs_pps_fast_addrs = new SrsPps(_srs_clock);
// set the max packet size. // set the max packet size.
#define SRS_UDP_MAX_PACKET_SIZE 65535 #define SRS_UDP_MAX_PACKET_SIZE 65535
@ -332,6 +338,9 @@ int SrsUdpMuxSocket::recvfrom(srs_utime_t timeout)
// We will regenerate the peer_ip, peer_port and peer_id. // We will regenerate the peer_ip, peer_port and peer_id.
address_changed_ = true; address_changed_ = true;
// Update the stat.
++_srs_pps_pkts->sugar;
return nread; return nread;
} }
@ -429,6 +438,9 @@ std::string SrsUdpMuxSocket::peer_id()
static char id_buf[128]; static char id_buf[128];
int len = snprintf(id_buf, sizeof(id_buf), "%s:%d", peer_ip.c_str(), peer_port); int len = snprintf(id_buf, sizeof(id_buf), "%s:%d", peer_ip.c_str(), peer_port);
peer_id_ = string(id_buf, len); peer_id_ = string(id_buf, len);
// Update the stat.
++_srs_pps_addrs->sugar;
} }
return peer_id_; return peer_id_;
@ -436,6 +448,7 @@ std::string SrsUdpMuxSocket::peer_id()
uint64_t SrsUdpMuxSocket::fast_id() uint64_t SrsUdpMuxSocket::fast_id()
{ {
++_srs_pps_fast_addrs->sugar;
return fast_id_; return fast_id_;
} }

View file

@ -45,6 +45,10 @@ using namespace std;
#include <srs_app_rtc_api.hpp> #include <srs_app_rtc_api.hpp>
#include <srs_protocol_utility.hpp> #include <srs_protocol_utility.hpp>
extern SrsPps* _srs_pps_pkts;
extern SrsPps* _srs_pps_addrs;
extern SrsPps* _srs_pps_fast_addrs;
SrsRtcBlackhole::SrsRtcBlackhole() SrsRtcBlackhole::SrsRtcBlackhole()
{ {
blackhole = false; blackhole = false;
@ -637,8 +641,15 @@ srs_error_t SrsRtcServer::notify(int type, srs_utime_t interval, srs_utime_t tic
SrsProcSelfStat* u = srs_get_self_proc_stat(); SrsProcSelfStat* u = srs_get_self_proc_stat();
// Resident Set Size: number of pages the process has in real memory. // Resident Set Size: number of pages the process has in real memory.
int memory = (int)(u->rss * 4 / 1024); int memory = (int)(u->rss * 4 / 1024);
// Update the pps stat for UDP socket and adddresses.
_srs_pps_pkts->update(); _srs_pps_addrs->update(); _srs_pps_fast_addrs->update();
// TODO: FIXME: Show more data for RTC server. // TODO: FIXME: Show more data for RTC server.
srs_trace("RTC: Server conns=%u, cpu=%.2f%%, rss=%dMB", nn_rtc_conns, u->percent * 100, memory); srs_trace("RTC: Server conns=%u, cpu=%.2f%%, rss=%dMB, pkts=%d, addrs=%d,%d",
nn_rtc_conns, u->percent * 100, memory,
_srs_pps_pkts->r10s(), _srs_pps_addrs->r10s(), _srs_pps_fast_addrs->r10s()
);
return err; return err;
} }