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

add udp stat to nb_conn_sys as nb_conn_sys_udp

This commit is contained in:
winlin 2014-07-27 15:43:43 +08:00
parent abef029610
commit f53bfcea54
2 changed files with 92 additions and 6 deletions

View file

@ -680,6 +680,7 @@ SrsNetworkRtmpServer::SrsNetworkRtmpServer()
sample_time = rbytes = sbytes = 0; sample_time = rbytes = sbytes = 0;
nb_conn_sys = nb_conn_srs = 0; nb_conn_sys = nb_conn_srs = 0;
nb_conn_sys_et = nb_conn_sys_tw = nb_conn_sys_ls = 0; nb_conn_sys_et = nb_conn_sys_tw = nb_conn_sys_ls = 0;
nb_conn_sys_udp = 0;
} }
static SrsNetworkRtmpServer _srs_network_rtmp_server; static SrsNetworkRtmpServer _srs_network_rtmp_server;
@ -710,6 +711,9 @@ void srs_update_rtmp_server(int nb_conn, SrsKbps* kbps)
{ {
SrsNetworkRtmpServer& r = _srs_network_rtmp_server; SrsNetworkRtmpServer& r = _srs_network_rtmp_server;
// reset total.
r.nb_conn_sys = 0;
if (true) { if (true) {
FILE* f = fopen("/proc/net/tcp", "r"); FILE* f = fopen("/proc/net/tcp", "r");
if (f == NULL) { if (f == NULL) {
@ -725,13 +729,12 @@ void srs_update_rtmp_server(int nb_conn, SrsKbps* kbps)
int nb_conn_sys_time_wait = 0; int nb_conn_sys_time_wait = 0;
int nb_conn_sys_listen = 0; int nb_conn_sys_listen = 0;
int nb_conn_sys_other = 0; int nb_conn_sys_other = 0;
for (;;) {
// @see: http://tester-higkoo.googlecode.com/svn-history/r14/trunk/Tools/iostat/iostat.c
while (fgets(buf, sizeof(buf), f)) {
int st = 0; int st = 0;
int ret = sscanf(buf, "%*s %*s %*s %2x\n", &st);
int ret = fscanf(f, "%*s %*s %*s %2x\n", &st);
// ignore to end.
fgets(buf, sizeof(buf), f);
if (ret == 1) { if (ret == 1) {
if (st == SYS_TCP_ESTABLISHED) { if (st == SYS_TCP_ESTABLISHED) {
nb_conn_sys_established++; nb_conn_sys_established++;
@ -757,6 +760,38 @@ void srs_update_rtmp_server(int nb_conn, SrsKbps* kbps)
fclose(f); fclose(f);
} }
if (true) {
FILE* f = fopen("/proc/net/udp", "r");
if (f == NULL) {
srs_warn("open proc network udp failed, ignore");
return;
}
// ignore title.
static char buf[1024];
fgets(buf, sizeof(buf), f);
// all udp is close state.
int nb_conn_sys_close = 0;
// @see: http://tester-higkoo.googlecode.com/svn-history/r14/trunk/Tools/iostat/iostat.c
while (fgets(buf, sizeof(buf), f)) {
int st = 0;
int ret = sscanf(buf, "%*s %*s %*s %2x\n", &st);
if (ret == EOF) {
break;
}
nb_conn_sys_close++;
}
r.nb_conn_sys += nb_conn_sys_close;
r.nb_conn_sys_udp = nb_conn_sys_close;
fclose(f);
}
if (true) { if (true) {
r.ok = true; r.ok = true;
@ -973,6 +1008,7 @@ void srs_api_dump_summaries(std::stringstream& ss)
<< __SRS_JFIELD_ORG("conn_sys_et", nrs->nb_conn_sys_et) << __SRS_JFIELD_CONT << __SRS_JFIELD_ORG("conn_sys_et", nrs->nb_conn_sys_et) << __SRS_JFIELD_CONT
<< __SRS_JFIELD_ORG("conn_sys_tw", nrs->nb_conn_sys_tw) << __SRS_JFIELD_CONT << __SRS_JFIELD_ORG("conn_sys_tw", nrs->nb_conn_sys_tw) << __SRS_JFIELD_CONT
<< __SRS_JFIELD_ORG("conn_sys_ls", nrs->nb_conn_sys_ls) << __SRS_JFIELD_CONT << __SRS_JFIELD_ORG("conn_sys_ls", nrs->nb_conn_sys_ls) << __SRS_JFIELD_CONT
<< __SRS_JFIELD_ORG("conn_sys_udp", nrs->nb_conn_sys_udp) << __SRS_JFIELD_CONT
<< __SRS_JFIELD_ORG("conn_srs", nrs->nb_conn_srs) << __SRS_JFIELD_ORG("conn_srs", nrs->nb_conn_srs)
<< __SRS_JOBJECT_END << __SRS_JOBJECT_END
<< __SRS_JOBJECT_END << __SRS_JOBJECT_END

View file

@ -350,6 +350,55 @@ public:
unsigned long pgpgout; unsigned long pgpgout;
// @see: https://www.kernel.org/doc/Documentation/iostats.txt // @see: https://www.kernel.org/doc/Documentation/iostats.txt
// @see: cat /proc/diskstats
//
// Number of issued reads.
// This is the total number of reads completed successfully.
unsigned long long nb_read;
// Number of reads merged
unsigned long long nb_mread;
// Number of sectors read.
// This is the total number of sectors read successfully.
unsigned long long nb_sread;
// Number of milliseconds spent reading.
// This is the total number of milliseconds spent by all reads
// (as measured from __make_request() to end_that_request_last()).
unsigned long long ms_read;
//
// Number of writes completed.
// This is the total number of writes completed successfully
unsigned long long nb_write;
// Number of writes merged Reads and writes which are adjacent
// to each other may be merged for efficiency. Thus two 4K
// reads may become one 8K read before it is ultimately
// handed to the disk, and so it will be counted (and queued)
// as only one I/O. This field lets you know how often this was done.
unsigned long long nb_mwrite;
// Number of sectors written.
// This is the total number of sectors written successfully.
unsigned long long nb_swrite;
// Number of milliseconds spent writing .
// This is the total number of milliseconds spent by all writes
// (as measured from __make_request() to end_that_request_last()).
unsigned long long ms_write;
//
// Number of I/Os currently in progress.
// The only field that should go to zero.
// Incremented as requests are given to appropriate request_queue_t
// and decremented as they finish.
unsigned long long nb_current;
// Number of milliseconds spent doing I/Os.
// This field is increased so long as field 9 is nonzero.
unsigned long long ms_total;
// Number of milliseconds spent doing I/Os.
// This field is incremented at each I/O start, I/O completion,
// I/O merge, or read of these stats by the number of I/Os in
// progress (field 9) times the number of milliseconds spent
// doing I/O since the last update of this field. This can
// provide an easy measure of both I/O completion time and
// the backlog that may be accumulating.
// weighting total.
unsigned long long ms_wtotal;
public: public:
SrsDiskStat(); SrsDiskStat();
@ -529,6 +578,7 @@ public:
int nb_conn_sys_et; // established int nb_conn_sys_et; // established
int nb_conn_sys_tw; // time wait int nb_conn_sys_tw; // time wait
int nb_conn_sys_ls; // listen int nb_conn_sys_ls; // listen
int nb_conn_sys_udp; // udp
int nb_conn_srs; int nb_conn_srs;
public: public: