mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
RTC: Stat the drop of UDP packets.
This commit is contained in:
parent
b9352eac0c
commit
9ab12f9f2f
4 changed files with 140 additions and 1 deletions
|
@ -851,6 +851,94 @@ void srs_update_platform_info()
|
|||
r.ok = true;
|
||||
}
|
||||
|
||||
SrsSnmpUdpStat::SrsSnmpUdpStat()
|
||||
{
|
||||
ok = false;
|
||||
|
||||
in_datagrams = 0;
|
||||
no_ports = 0;
|
||||
in_errors = 0;
|
||||
out_datagrams = 0;
|
||||
rcv_buf_errors = 0;
|
||||
snd_buf_errors = 0;
|
||||
in_csum_errors = 0;
|
||||
|
||||
rcv_buf_errors_delta = 0;
|
||||
snd_buf_errors_delta = 0;
|
||||
}
|
||||
|
||||
SrsSnmpUdpStat::~SrsSnmpUdpStat()
|
||||
{
|
||||
}
|
||||
|
||||
static SrsSnmpUdpStat _srs_snmp_udp_stat;
|
||||
|
||||
bool get_udp_snmp_statistic(SrsSnmpUdpStat& r)
|
||||
{
|
||||
#ifndef SRS_OSX
|
||||
if (true) {
|
||||
FILE* f = fopen("/proc/net/snmp", "r");
|
||||
if (f == NULL) {
|
||||
srs_warn("open proc network snmp failed, ignore");
|
||||
return false;
|
||||
}
|
||||
|
||||
// ignore title.
|
||||
static char buf[1024];
|
||||
fgets(buf, sizeof(buf), f);
|
||||
|
||||
while (fgets(buf, sizeof(buf), f)) {
|
||||
// udp stat title
|
||||
if (strncmp(buf, "Udp: ", 5) == 0) {
|
||||
// read tcp stat data
|
||||
if (!fgets(buf, sizeof(buf), f)) {
|
||||
break;
|
||||
}
|
||||
// parse tcp stat data
|
||||
if (strncmp(buf, "Udp: ", 5) == 0) {
|
||||
sscanf(buf + 5, "%llu %llu %llu %llu %llu %llu %llu\n",
|
||||
&r.in_datagrams,
|
||||
&r.no_ports,
|
||||
&r.in_errors,
|
||||
&r.out_datagrams,
|
||||
&r.rcv_buf_errors,
|
||||
&r.snd_buf_errors,
|
||||
&r.in_csum_errors);
|
||||
}
|
||||
}
|
||||
}
|
||||
fclose(f);
|
||||
}
|
||||
#endif
|
||||
r.ok = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
SrsSnmpUdpStat* srs_get_udp_snmp_stat()
|
||||
{
|
||||
return &_srs_snmp_udp_stat;
|
||||
}
|
||||
|
||||
void srs_update_udp_snmp_statistic()
|
||||
{
|
||||
SrsSnmpUdpStat r;
|
||||
if (!get_udp_snmp_statistic(r)) {
|
||||
return;
|
||||
}
|
||||
|
||||
SrsSnmpUdpStat& o = _srs_snmp_udp_stat;
|
||||
if (o.rcv_buf_errors > 0) {
|
||||
r.rcv_buf_errors_delta = int(r.rcv_buf_errors - o.rcv_buf_errors);
|
||||
}
|
||||
|
||||
if (o.snd_buf_errors > 0) {
|
||||
r.snd_buf_errors_delta = int(r.snd_buf_errors - o.snd_buf_errors);
|
||||
}
|
||||
|
||||
_srs_snmp_udp_stat = r;
|
||||
}
|
||||
|
||||
SrsNetworkDevices::SrsNetworkDevices()
|
||||
{
|
||||
ok = false;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue