From f53bfcea5436c9a78ce59322b485925f1d04ed2d Mon Sep 17 00:00:00 2001 From: winlin Date: Sun, 27 Jul 2014 15:43:43 +0800 Subject: [PATCH] add udp stat to nb_conn_sys as nb_conn_sys_udp --- trunk/src/app/srs_app_utility.cpp | 48 +++++++++++++++++++++++++---- trunk/src/app/srs_app_utility.hpp | 50 +++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+), 6 deletions(-) diff --git a/trunk/src/app/srs_app_utility.cpp b/trunk/src/app/srs_app_utility.cpp index 1493b0d6a..6122eaa8e 100644 --- a/trunk/src/app/srs_app_utility.cpp +++ b/trunk/src/app/srs_app_utility.cpp @@ -680,6 +680,7 @@ SrsNetworkRtmpServer::SrsNetworkRtmpServer() sample_time = rbytes = sbytes = 0; nb_conn_sys = nb_conn_srs = 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; @@ -710,6 +711,9 @@ void srs_update_rtmp_server(int nb_conn, SrsKbps* kbps) { SrsNetworkRtmpServer& r = _srs_network_rtmp_server; + // reset total. + r.nb_conn_sys = 0; + if (true) { FILE* f = fopen("/proc/net/tcp", "r"); 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_listen = 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 ret = fscanf(f, "%*s %*s %*s %2x\n", &st); - // ignore to end. - fgets(buf, sizeof(buf), f); - + int ret = sscanf(buf, "%*s %*s %*s %2x\n", &st); + if (ret == 1) { if (st == SYS_TCP_ESTABLISHED) { nb_conn_sys_established++; @@ -757,6 +760,38 @@ void srs_update_rtmp_server(int nb_conn, SrsKbps* kbps) 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) { 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_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_udp", nrs->nb_conn_sys_udp) << __SRS_JFIELD_CONT << __SRS_JFIELD_ORG("conn_srs", nrs->nb_conn_srs) << __SRS_JOBJECT_END << __SRS_JOBJECT_END diff --git a/trunk/src/app/srs_app_utility.hpp b/trunk/src/app/srs_app_utility.hpp index dafaae15e..f0d51a5c4 100644 --- a/trunk/src/app/srs_app_utility.hpp +++ b/trunk/src/app/srs_app_utility.hpp @@ -350,6 +350,55 @@ public: unsigned long pgpgout; // @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: SrsDiskStat(); @@ -529,6 +578,7 @@ public: int nb_conn_sys_et; // established int nb_conn_sys_tw; // time wait int nb_conn_sys_ls; // listen + int nb_conn_sys_udp; // udp int nb_conn_srs; public: