正在显示
2 个修改的文件
包含
92 行增加
和
6 行删除
| @@ -680,6 +680,7 @@ SrsNetworkRtmpServer::SrsNetworkRtmpServer() | @@ -680,6 +680,7 @@ SrsNetworkRtmpServer::SrsNetworkRtmpServer() | ||
| 680 | sample_time = rbytes = sbytes = 0; | 680 | sample_time = rbytes = sbytes = 0; |
| 681 | nb_conn_sys = nb_conn_srs = 0; | 681 | nb_conn_sys = nb_conn_srs = 0; |
| 682 | nb_conn_sys_et = nb_conn_sys_tw = nb_conn_sys_ls = 0; | 682 | nb_conn_sys_et = nb_conn_sys_tw = nb_conn_sys_ls = 0; |
| 683 | + nb_conn_sys_udp = 0; | ||
| 683 | } | 684 | } |
| 684 | 685 | ||
| 685 | static SrsNetworkRtmpServer _srs_network_rtmp_server; | 686 | static SrsNetworkRtmpServer _srs_network_rtmp_server; |
| @@ -710,6 +711,9 @@ void srs_update_rtmp_server(int nb_conn, SrsKbps* kbps) | @@ -710,6 +711,9 @@ void srs_update_rtmp_server(int nb_conn, SrsKbps* kbps) | ||
| 710 | { | 711 | { |
| 711 | SrsNetworkRtmpServer& r = _srs_network_rtmp_server; | 712 | SrsNetworkRtmpServer& r = _srs_network_rtmp_server; |
| 712 | 713 | ||
| 714 | + // reset total. | ||
| 715 | + r.nb_conn_sys = 0; | ||
| 716 | + | ||
| 713 | if (true) { | 717 | if (true) { |
| 714 | FILE* f = fopen("/proc/net/tcp", "r"); | 718 | FILE* f = fopen("/proc/net/tcp", "r"); |
| 715 | if (f == NULL) { | 719 | if (f == NULL) { |
| @@ -725,13 +729,12 @@ void srs_update_rtmp_server(int nb_conn, SrsKbps* kbps) | @@ -725,13 +729,12 @@ void srs_update_rtmp_server(int nb_conn, SrsKbps* kbps) | ||
| 725 | int nb_conn_sys_time_wait = 0; | 729 | int nb_conn_sys_time_wait = 0; |
| 726 | int nb_conn_sys_listen = 0; | 730 | int nb_conn_sys_listen = 0; |
| 727 | int nb_conn_sys_other = 0; | 731 | int nb_conn_sys_other = 0; |
| 728 | - for (;;) { | 732 | + |
| 733 | + // @see: http://tester-higkoo.googlecode.com/svn-history/r14/trunk/Tools/iostat/iostat.c | ||
| 734 | + while (fgets(buf, sizeof(buf), f)) { | ||
| 729 | int st = 0; | 735 | int st = 0; |
| 730 | - | ||
| 731 | - int ret = fscanf(f, "%*s %*s %*s %2x\n", &st); | ||
| 732 | - // ignore to end. | ||
| 733 | - fgets(buf, sizeof(buf), f); | ||
| 734 | - | 736 | + int ret = sscanf(buf, "%*s %*s %*s %2x\n", &st); |
| 737 | + | ||
| 735 | if (ret == 1) { | 738 | if (ret == 1) { |
| 736 | if (st == SYS_TCP_ESTABLISHED) { | 739 | if (st == SYS_TCP_ESTABLISHED) { |
| 737 | nb_conn_sys_established++; | 740 | nb_conn_sys_established++; |
| @@ -758,6 +761,38 @@ void srs_update_rtmp_server(int nb_conn, SrsKbps* kbps) | @@ -758,6 +761,38 @@ void srs_update_rtmp_server(int nb_conn, SrsKbps* kbps) | ||
| 758 | } | 761 | } |
| 759 | 762 | ||
| 760 | if (true) { | 763 | if (true) { |
| 764 | + FILE* f = fopen("/proc/net/udp", "r"); | ||
| 765 | + if (f == NULL) { | ||
| 766 | + srs_warn("open proc network udp failed, ignore"); | ||
| 767 | + return; | ||
| 768 | + } | ||
| 769 | + | ||
| 770 | + // ignore title. | ||
| 771 | + static char buf[1024]; | ||
| 772 | + fgets(buf, sizeof(buf), f); | ||
| 773 | + | ||
| 774 | + // all udp is close state. | ||
| 775 | + int nb_conn_sys_close = 0; | ||
| 776 | + | ||
| 777 | + // @see: http://tester-higkoo.googlecode.com/svn-history/r14/trunk/Tools/iostat/iostat.c | ||
| 778 | + while (fgets(buf, sizeof(buf), f)) { | ||
| 779 | + int st = 0; | ||
| 780 | + int ret = sscanf(buf, "%*s %*s %*s %2x\n", &st); | ||
| 781 | + | ||
| 782 | + if (ret == EOF) { | ||
| 783 | + break; | ||
| 784 | + } | ||
| 785 | + | ||
| 786 | + nb_conn_sys_close++; | ||
| 787 | + } | ||
| 788 | + | ||
| 789 | + r.nb_conn_sys += nb_conn_sys_close; | ||
| 790 | + r.nb_conn_sys_udp = nb_conn_sys_close; | ||
| 791 | + | ||
| 792 | + fclose(f); | ||
| 793 | + } | ||
| 794 | + | ||
| 795 | + if (true) { | ||
| 761 | r.ok = true; | 796 | r.ok = true; |
| 762 | 797 | ||
| 763 | r.nb_conn_srs = nb_conn; | 798 | r.nb_conn_srs = nb_conn; |
| @@ -973,6 +1008,7 @@ void srs_api_dump_summaries(std::stringstream& ss) | @@ -973,6 +1008,7 @@ void srs_api_dump_summaries(std::stringstream& ss) | ||
| 973 | << __SRS_JFIELD_ORG("conn_sys_et", nrs->nb_conn_sys_et) << __SRS_JFIELD_CONT | 1008 | << __SRS_JFIELD_ORG("conn_sys_et", nrs->nb_conn_sys_et) << __SRS_JFIELD_CONT |
| 974 | << __SRS_JFIELD_ORG("conn_sys_tw", nrs->nb_conn_sys_tw) << __SRS_JFIELD_CONT | 1009 | << __SRS_JFIELD_ORG("conn_sys_tw", nrs->nb_conn_sys_tw) << __SRS_JFIELD_CONT |
| 975 | << __SRS_JFIELD_ORG("conn_sys_ls", nrs->nb_conn_sys_ls) << __SRS_JFIELD_CONT | 1010 | << __SRS_JFIELD_ORG("conn_sys_ls", nrs->nb_conn_sys_ls) << __SRS_JFIELD_CONT |
| 1011 | + << __SRS_JFIELD_ORG("conn_sys_udp", nrs->nb_conn_sys_udp) << __SRS_JFIELD_CONT | ||
| 976 | << __SRS_JFIELD_ORG("conn_srs", nrs->nb_conn_srs) | 1012 | << __SRS_JFIELD_ORG("conn_srs", nrs->nb_conn_srs) |
| 977 | << __SRS_JOBJECT_END | 1013 | << __SRS_JOBJECT_END |
| 978 | << __SRS_JOBJECT_END | 1014 | << __SRS_JOBJECT_END |
| @@ -350,6 +350,55 @@ public: | @@ -350,6 +350,55 @@ public: | ||
| 350 | unsigned long pgpgout; | 350 | unsigned long pgpgout; |
| 351 | 351 | ||
| 352 | // @see: https://www.kernel.org/doc/Documentation/iostats.txt | 352 | // @see: https://www.kernel.org/doc/Documentation/iostats.txt |
| 353 | + // @see: cat /proc/diskstats | ||
| 354 | + // | ||
| 355 | + // Number of issued reads. | ||
| 356 | + // This is the total number of reads completed successfully. | ||
| 357 | + unsigned long long nb_read; | ||
| 358 | + // Number of reads merged | ||
| 359 | + unsigned long long nb_mread; | ||
| 360 | + // Number of sectors read. | ||
| 361 | + // This is the total number of sectors read successfully. | ||
| 362 | + unsigned long long nb_sread; | ||
| 363 | + // Number of milliseconds spent reading. | ||
| 364 | + // This is the total number of milliseconds spent by all reads | ||
| 365 | + // (as measured from __make_request() to end_that_request_last()). | ||
| 366 | + unsigned long long ms_read; | ||
| 367 | + // | ||
| 368 | + // Number of writes completed. | ||
| 369 | + // This is the total number of writes completed successfully | ||
| 370 | + unsigned long long nb_write; | ||
| 371 | + // Number of writes merged Reads and writes which are adjacent | ||
| 372 | + // to each other may be merged for efficiency. Thus two 4K | ||
| 373 | + // reads may become one 8K read before it is ultimately | ||
| 374 | + // handed to the disk, and so it will be counted (and queued) | ||
| 375 | + // as only one I/O. This field lets you know how often this was done. | ||
| 376 | + unsigned long long nb_mwrite; | ||
| 377 | + // Number of sectors written. | ||
| 378 | + // This is the total number of sectors written successfully. | ||
| 379 | + unsigned long long nb_swrite; | ||
| 380 | + // Number of milliseconds spent writing . | ||
| 381 | + // This is the total number of milliseconds spent by all writes | ||
| 382 | + // (as measured from __make_request() to end_that_request_last()). | ||
| 383 | + unsigned long long ms_write; | ||
| 384 | + // | ||
| 385 | + // Number of I/Os currently in progress. | ||
| 386 | + // The only field that should go to zero. | ||
| 387 | + // Incremented as requests are given to appropriate request_queue_t | ||
| 388 | + // and decremented as they finish. | ||
| 389 | + unsigned long long nb_current; | ||
| 390 | + // Number of milliseconds spent doing I/Os. | ||
| 391 | + // This field is increased so long as field 9 is nonzero. | ||
| 392 | + unsigned long long ms_total; | ||
| 393 | + // Number of milliseconds spent doing I/Os. | ||
| 394 | + // This field is incremented at each I/O start, I/O completion, | ||
| 395 | + // I/O merge, or read of these stats by the number of I/Os in | ||
| 396 | + // progress (field 9) times the number of milliseconds spent | ||
| 397 | + // doing I/O since the last update of this field. This can | ||
| 398 | + // provide an easy measure of both I/O completion time and | ||
| 399 | + // the backlog that may be accumulating. | ||
| 400 | + // weighting total. | ||
| 401 | + unsigned long long ms_wtotal; | ||
| 353 | 402 | ||
| 354 | public: | 403 | public: |
| 355 | SrsDiskStat(); | 404 | SrsDiskStat(); |
| @@ -529,6 +578,7 @@ public: | @@ -529,6 +578,7 @@ public: | ||
| 529 | int nb_conn_sys_et; // established | 578 | int nb_conn_sys_et; // established |
| 530 | int nb_conn_sys_tw; // time wait | 579 | int nb_conn_sys_tw; // time wait |
| 531 | int nb_conn_sys_ls; // listen | 580 | int nb_conn_sys_ls; // listen |
| 581 | + int nb_conn_sys_udp; // udp | ||
| 532 | int nb_conn_srs; | 582 | int nb_conn_srs; |
| 533 | 583 | ||
| 534 | public: | 584 | public: |
-
请 注册 或 登录 后发表评论