正在显示
8 个修改的文件
包含
525 行增加
和
152 行删除
| @@ -389,7 +389,7 @@ if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then | @@ -389,7 +389,7 @@ if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then | ||
| 389 | "srs_app_pithy_print" "srs_app_reload" "srs_app_http_api" "srs_app_http_conn" "srs_app_http_hooks" | 389 | "srs_app_pithy_print" "srs_app_reload" "srs_app_http_api" "srs_app_http_conn" "srs_app_http_hooks" |
| 390 | "srs_app_json" "srs_app_ingest" "srs_app_ffmpeg" "srs_app_utility" "srs_app_dvr" "srs_app_edge" | 390 | "srs_app_json" "srs_app_ingest" "srs_app_ffmpeg" "srs_app_utility" "srs_app_dvr" "srs_app_edge" |
| 391 | "srs_app_kbps" "srs_app_heartbeat" "srs_app_empty" "srs_app_http_client" "srs_app_avc_aac" | 391 | "srs_app_kbps" "srs_app_heartbeat" "srs_app_empty" "srs_app_http_client" "srs_app_avc_aac" |
| 392 | - "srs_app_recv_thread" "srs_app_security") | 392 | + "srs_app_recv_thread" "srs_app_security" "srs_app_statistic") |
| 393 | APP_INCS="src/app"; MODULE_DIR=${APP_INCS} . auto/modules.sh | 393 | APP_INCS="src/app"; MODULE_DIR=${APP_INCS} . auto/modules.sh |
| 394 | APP_OBJS="${MODULE_OBJS[@]}" | 394 | APP_OBJS="${MODULE_OBJS[@]}" |
| 395 | fi | 395 | fi |
| @@ -35,6 +35,8 @@ using namespace std; | @@ -35,6 +35,8 @@ using namespace std; | ||
| 35 | #include <srs_app_json.hpp> | 35 | #include <srs_app_json.hpp> |
| 36 | #include <srs_kernel_utility.hpp> | 36 | #include <srs_kernel_utility.hpp> |
| 37 | #include <srs_app_utility.hpp> | 37 | #include <srs_app_utility.hpp> |
| 38 | +#include <srs_app_statistic.hpp> | ||
| 39 | +#include <srs_protocol_rtmp.hpp> | ||
| 38 | 40 | ||
| 39 | SrsApiRoot::SrsApiRoot() | 41 | SrsApiRoot::SrsApiRoot() |
| 40 | { | 42 | { |
| @@ -122,6 +124,8 @@ SrsApiV1::SrsApiV1() | @@ -122,6 +124,8 @@ SrsApiV1::SrsApiV1() | ||
| 122 | handlers.push_back(new SrsApiMemInfos()); | 124 | handlers.push_back(new SrsApiMemInfos()); |
| 123 | handlers.push_back(new SrsApiAuthors()); | 125 | handlers.push_back(new SrsApiAuthors()); |
| 124 | handlers.push_back(new SrsApiRequests()); | 126 | handlers.push_back(new SrsApiRequests()); |
| 127 | + handlers.push_back(new SrsApiVhosts()); | ||
| 128 | + handlers.push_back(new SrsApiStreams()); | ||
| 125 | } | 129 | } |
| 126 | 130 | ||
| 127 | SrsApiV1::~SrsApiV1() | 131 | SrsApiV1::~SrsApiV1() |
| @@ -147,7 +151,9 @@ int SrsApiV1::do_process_request(SrsStSocket* skt, SrsHttpMessage* req) | @@ -147,7 +151,9 @@ int SrsApiV1::do_process_request(SrsStSocket* skt, SrsHttpMessage* req) | ||
| 147 | << __SRS_JFIELD_STR("system_proc_stats", "the system process stats") << __SRS_JFIELD_CONT | 151 | << __SRS_JFIELD_STR("system_proc_stats", "the system process stats") << __SRS_JFIELD_CONT |
| 148 | << __SRS_JFIELD_STR("meminfos", "the meminfo of system") << __SRS_JFIELD_CONT | 152 | << __SRS_JFIELD_STR("meminfos", "the meminfo of system") << __SRS_JFIELD_CONT |
| 149 | << __SRS_JFIELD_STR("authors", "the primary authors and contributors") << __SRS_JFIELD_CONT | 153 | << __SRS_JFIELD_STR("authors", "the primary authors and contributors") << __SRS_JFIELD_CONT |
| 150 | - << __SRS_JFIELD_STR("requests", "the request itself, for http debug") | 154 | + << __SRS_JFIELD_STR("requests", "the request itself, for http debug") << __SRS_JFIELD_CONT |
| 155 | + << __SRS_JFIELD_STR("vhosts", "dumps vhost to json") << __SRS_JFIELD_CONT | ||
| 156 | + << __SRS_JFIELD_STR("streams", "dumps streams to json") | ||
| 151 | << __SRS_JOBJECT_END | 157 | << __SRS_JOBJECT_END |
| 152 | << __SRS_JOBJECT_END; | 158 | << __SRS_JOBJECT_END; |
| 153 | 159 | ||
| @@ -500,6 +506,70 @@ int SrsApiAuthors::do_process_request(SrsStSocket* skt, SrsHttpMessage* req) | @@ -500,6 +506,70 @@ int SrsApiAuthors::do_process_request(SrsStSocket* skt, SrsHttpMessage* req) | ||
| 500 | return res_json(skt, req, ss.str()); | 506 | return res_json(skt, req, ss.str()); |
| 501 | } | 507 | } |
| 502 | 508 | ||
| 509 | +SrsApiVhosts::SrsApiVhosts() | ||
| 510 | +{ | ||
| 511 | +} | ||
| 512 | + | ||
| 513 | +SrsApiVhosts::~SrsApiVhosts() | ||
| 514 | +{ | ||
| 515 | +} | ||
| 516 | + | ||
| 517 | +bool SrsApiVhosts::can_handle(const char* path, int length, const char** /*pchild*/) | ||
| 518 | +{ | ||
| 519 | + return srs_path_equals("/vhosts", path, length); | ||
| 520 | +} | ||
| 521 | + | ||
| 522 | +int SrsApiVhosts::do_process_request(SrsStSocket* skt, SrsHttpMessage* req) | ||
| 523 | +{ | ||
| 524 | + std::stringstream data; | ||
| 525 | + SrsStatistic* stat = SrsStatistic::instance(); | ||
| 526 | + int ret = stat->dumps_vhosts(data); | ||
| 527 | + | ||
| 528 | + std::stringstream ss; | ||
| 529 | + | ||
| 530 | + ss << __SRS_JOBJECT_START | ||
| 531 | + << __SRS_JFIELD_ERROR(ret) << __SRS_JFIELD_CONT | ||
| 532 | + << __SRS_JFIELD_ORG("server", stat->server_id()) << __SRS_JFIELD_CONT | ||
| 533 | + << __SRS_JFIELD_ORG("vhosts", __SRS_JARRAY_START) | ||
| 534 | + << data.str() | ||
| 535 | + << __SRS_JARRAY_END | ||
| 536 | + << __SRS_JOBJECT_END; | ||
| 537 | + | ||
| 538 | + return res_json(skt, req, ss.str()); | ||
| 539 | +} | ||
| 540 | + | ||
| 541 | +SrsApiStreams::SrsApiStreams() | ||
| 542 | +{ | ||
| 543 | +} | ||
| 544 | + | ||
| 545 | +SrsApiStreams::~SrsApiStreams() | ||
| 546 | +{ | ||
| 547 | +} | ||
| 548 | + | ||
| 549 | +bool SrsApiStreams::can_handle(const char* path, int length, const char** /*pchild*/) | ||
| 550 | +{ | ||
| 551 | + return srs_path_equals("/streams", path, length); | ||
| 552 | +} | ||
| 553 | + | ||
| 554 | +int SrsApiStreams::do_process_request(SrsStSocket* skt, SrsHttpMessage* req) | ||
| 555 | +{ | ||
| 556 | + std::stringstream data; | ||
| 557 | + SrsStatistic* stat = SrsStatistic::instance(); | ||
| 558 | + int ret = stat->dumps_streams(data); | ||
| 559 | + | ||
| 560 | + std::stringstream ss; | ||
| 561 | + | ||
| 562 | + ss << __SRS_JOBJECT_START | ||
| 563 | + << __SRS_JFIELD_ERROR(ret) << __SRS_JFIELD_CONT | ||
| 564 | + << __SRS_JFIELD_ORG("server", stat->server_id()) << __SRS_JFIELD_CONT | ||
| 565 | + << __SRS_JFIELD_ORG("streams", __SRS_JARRAY_START) | ||
| 566 | + << data.str() | ||
| 567 | + << __SRS_JARRAY_END | ||
| 568 | + << __SRS_JOBJECT_END; | ||
| 569 | + | ||
| 570 | + return res_json(skt, req, ss.str()); | ||
| 571 | +} | ||
| 572 | + | ||
| 503 | SrsHttpApi::SrsHttpApi(SrsServer* srs_server, st_netfd_t client_stfd, SrsHttpHandler* _handler) | 573 | SrsHttpApi::SrsHttpApi(SrsServer* srs_server, st_netfd_t client_stfd, SrsHttpHandler* _handler) |
| 504 | : SrsConnection(srs_server, client_stfd) | 574 | : SrsConnection(srs_server, client_stfd) |
| 505 | { | 575 | { |
| @@ -164,6 +164,28 @@ protected: | @@ -164,6 +164,28 @@ protected: | ||
| 164 | virtual int do_process_request(SrsStSocket* skt, SrsHttpMessage* req); | 164 | virtual int do_process_request(SrsStSocket* skt, SrsHttpMessage* req); |
| 165 | }; | 165 | }; |
| 166 | 166 | ||
| 167 | +class SrsApiVhosts : public SrsHttpHandler | ||
| 168 | +{ | ||
| 169 | +public: | ||
| 170 | + SrsApiVhosts(); | ||
| 171 | + virtual ~SrsApiVhosts(); | ||
| 172 | +public: | ||
| 173 | + virtual bool can_handle(const char* path, int length, const char** pchild); | ||
| 174 | +protected: | ||
| 175 | + virtual int do_process_request(SrsStSocket* skt, SrsHttpMessage* req); | ||
| 176 | +}; | ||
| 177 | + | ||
| 178 | +class SrsApiStreams : public SrsHttpHandler | ||
| 179 | +{ | ||
| 180 | +public: | ||
| 181 | + SrsApiStreams(); | ||
| 182 | + virtual ~SrsApiStreams(); | ||
| 183 | +public: | ||
| 184 | + virtual bool can_handle(const char* path, int length, const char** pchild); | ||
| 185 | +protected: | ||
| 186 | + virtual int do_process_request(SrsStSocket* skt, SrsHttpMessage* req); | ||
| 187 | +}; | ||
| 188 | + | ||
| 167 | class SrsHttpApi : public SrsConnection | 189 | class SrsHttpApi : public SrsConnection |
| 168 | { | 190 | { |
| 169 | private: | 191 | private: |
| @@ -52,6 +52,7 @@ using namespace std; | @@ -52,6 +52,7 @@ using namespace std; | ||
| 52 | #include <srs_core_performance.hpp> | 52 | #include <srs_core_performance.hpp> |
| 53 | #include <srs_kernel_utility.hpp> | 53 | #include <srs_kernel_utility.hpp> |
| 54 | #include <srs_app_security.hpp> | 54 | #include <srs_app_security.hpp> |
| 55 | +#include <srs_app_statistic.hpp> | ||
| 55 | 56 | ||
| 56 | // when stream is busy, for example, streaming is already | 57 | // when stream is busy, for example, streaming is already |
| 57 | // publishing, when a new client to request to publish, | 58 | // publishing, when a new client to request to publish, |
| @@ -395,6 +396,13 @@ int SrsRtmpConn::stream_service_cycle() | @@ -395,6 +396,13 @@ int SrsRtmpConn::stream_service_cycle() | ||
| 395 | } | 396 | } |
| 396 | srs_assert(source != NULL); | 397 | srs_assert(source != NULL); |
| 397 | 398 | ||
| 399 | + // update the statistic when source disconveried. | ||
| 400 | + SrsStatistic* stat = SrsStatistic::instance(); | ||
| 401 | + if ((ret = stat->on_client(_srs_context->get_id(), req)) != ERROR_SUCCESS) { | ||
| 402 | + srs_error("stat client failed. ret=%d", ret); | ||
| 403 | + return ret; | ||
| 404 | + } | ||
| 405 | + | ||
| 398 | // check ASAP, to fail it faster if invalid. | 406 | // check ASAP, to fail it faster if invalid. |
| 399 | if (type != SrsRtmpConnPlay && !vhost_is_edge) { | 407 | if (type != SrsRtmpConnPlay && !vhost_is_edge) { |
| 400 | // check publish available | 408 | // check publish available |
trunk/src/app/srs_app_statistic.cpp
0 → 100644
| 1 | +/* | ||
| 2 | +The MIT License (MIT) | ||
| 3 | + | ||
| 4 | +Copyright (c) 2013-2015 winlin | ||
| 5 | + | ||
| 6 | +Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
| 7 | +this software and associated documentation files (the "Software"), to deal in | ||
| 8 | +the Software without restriction, including without limitation the rights to | ||
| 9 | +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
| 10 | +the Software, and to permit persons to whom the Software is furnished to do so, | ||
| 11 | +subject to the following conditions: | ||
| 12 | + | ||
| 13 | +The above copyright notice and this permission notice shall be included in all | ||
| 14 | +copies or substantial portions of the Software. | ||
| 15 | + | ||
| 16 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| 17 | +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
| 18 | +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
| 19 | +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
| 20 | +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
| 21 | +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 22 | +*/ | ||
| 23 | + | ||
| 24 | +#include <srs_app_statistic.hpp> | ||
| 25 | + | ||
| 26 | +#include <unistd.h> | ||
| 27 | +#include <sstream> | ||
| 28 | +using namespace std; | ||
| 29 | + | ||
| 30 | +#include <srs_protocol_rtmp.hpp> | ||
| 31 | +#include <srs_app_json.hpp> | ||
| 32 | + | ||
| 33 | +int64_t __srs_gvid = getpid(); | ||
| 34 | + | ||
| 35 | +int64_t __srs_generate_id() | ||
| 36 | +{ | ||
| 37 | + return __srs_gvid++; | ||
| 38 | +} | ||
| 39 | + | ||
| 40 | +SrsStatisticVhost::SrsStatisticVhost() | ||
| 41 | +{ | ||
| 42 | + id = __srs_generate_id(); | ||
| 43 | +} | ||
| 44 | + | ||
| 45 | +SrsStatisticVhost::~SrsStatisticVhost() | ||
| 46 | +{ | ||
| 47 | +} | ||
| 48 | + | ||
| 49 | +SrsStatisticStream::SrsStatisticStream() | ||
| 50 | +{ | ||
| 51 | + id = __srs_generate_id(); | ||
| 52 | + vhost = NULL; | ||
| 53 | +} | ||
| 54 | + | ||
| 55 | +SrsStatisticStream::~SrsStatisticStream() | ||
| 56 | +{ | ||
| 57 | +} | ||
| 58 | + | ||
| 59 | +SrsStatistic* SrsStatistic::_instance = new SrsStatistic(); | ||
| 60 | + | ||
| 61 | +SrsStatistic::SrsStatistic() | ||
| 62 | +{ | ||
| 63 | + _server_id = __srs_generate_id(); | ||
| 64 | +} | ||
| 65 | + | ||
| 66 | +SrsStatistic::~SrsStatistic() | ||
| 67 | +{ | ||
| 68 | + if (true) { | ||
| 69 | + std::map<std::string, SrsStatisticVhost*>::iterator it; | ||
| 70 | + for (it = vhosts.begin(); it != vhosts.end(); it++) { | ||
| 71 | + SrsStatisticVhost* vhost = it->second; | ||
| 72 | + srs_freep(vhost); | ||
| 73 | + } | ||
| 74 | + } | ||
| 75 | + if (true) { | ||
| 76 | + std::map<std::string, SrsStatisticStream*>::iterator it; | ||
| 77 | + for (it = streams.begin(); it != streams.end(); it++) { | ||
| 78 | + SrsStatisticStream* stream = it->second; | ||
| 79 | + srs_freep(stream); | ||
| 80 | + } | ||
| 81 | + } | ||
| 82 | + if (true) { | ||
| 83 | + std::map<int, SrsStatisticClient*>::iterator it; | ||
| 84 | + for (it = clients.begin(); it != clients.end(); it++) { | ||
| 85 | + SrsStatisticClient* client = it->second; | ||
| 86 | + srs_freep(client); | ||
| 87 | + } | ||
| 88 | + } | ||
| 89 | +} | ||
| 90 | + | ||
| 91 | +SrsStatistic* SrsStatistic::instance() | ||
| 92 | +{ | ||
| 93 | + return _instance; | ||
| 94 | +} | ||
| 95 | + | ||
| 96 | +int SrsStatistic::on_client(int id, SrsRequest* req) | ||
| 97 | +{ | ||
| 98 | + int ret = ERROR_SUCCESS; | ||
| 99 | + | ||
| 100 | + // create vhost if not exists. | ||
| 101 | + SrsStatisticVhost* vhost = NULL; | ||
| 102 | + if (vhosts.find(req->vhost) == vhosts.end()) { | ||
| 103 | + vhost = new SrsStatisticVhost(); | ||
| 104 | + vhost->vhost = req->vhost; | ||
| 105 | + vhosts[req->vhost] = vhost; | ||
| 106 | + } else { | ||
| 107 | + vhost = vhosts[req->vhost]; | ||
| 108 | + } | ||
| 109 | + | ||
| 110 | + // the url to identify the stream. | ||
| 111 | + std::string url = req->get_stream_url(); | ||
| 112 | + | ||
| 113 | + // create stream if not exists. | ||
| 114 | + SrsStatisticStream* stream = NULL; | ||
| 115 | + if (streams.find(url) == streams.end()) { | ||
| 116 | + stream = new SrsStatisticStream(); | ||
| 117 | + stream->vhost = vhost; | ||
| 118 | + stream->stream = req->stream; | ||
| 119 | + stream->url = url; | ||
| 120 | + streams[url] = stream; | ||
| 121 | + } else { | ||
| 122 | + stream = streams[url]; | ||
| 123 | + } | ||
| 124 | + | ||
| 125 | + return ret; | ||
| 126 | +} | ||
| 127 | + | ||
| 128 | +int64_t SrsStatistic::server_id() | ||
| 129 | +{ | ||
| 130 | + return _server_id; | ||
| 131 | +} | ||
| 132 | + | ||
| 133 | +int SrsStatistic::dumps_vhosts(stringstream& ss) | ||
| 134 | +{ | ||
| 135 | + int ret = ERROR_SUCCESS; | ||
| 136 | + | ||
| 137 | + std::map<std::string, SrsStatisticVhost*>::iterator it; | ||
| 138 | + for (it = vhosts.begin(); it != vhosts.end(); it++) { | ||
| 139 | + SrsStatisticVhost* vhost = it->second; | ||
| 140 | + ss << __SRS_JOBJECT_START | ||
| 141 | + << __SRS_JFIELD_ORG("id", vhost->id) << __SRS_JFIELD_CONT | ||
| 142 | + << __SRS_JFIELD_STR("name", vhost->vhost) | ||
| 143 | + << __SRS_JOBJECT_END; | ||
| 144 | + } | ||
| 145 | + | ||
| 146 | + return ret; | ||
| 147 | +} | ||
| 148 | + | ||
| 149 | +int SrsStatistic::dumps_streams(stringstream& ss) | ||
| 150 | +{ | ||
| 151 | + int ret = ERROR_SUCCESS; | ||
| 152 | + | ||
| 153 | + std::map<std::string, SrsStatisticStream*>::iterator it; | ||
| 154 | + for (it = streams.begin(); it != streams.end(); it++) { | ||
| 155 | + SrsStatisticStream* stream = it->second; | ||
| 156 | + ss << __SRS_JOBJECT_START | ||
| 157 | + << __SRS_JFIELD_ORG("id", stream->id) << __SRS_JFIELD_CONT | ||
| 158 | + << __SRS_JFIELD_STR("name", stream->stream) << __SRS_JFIELD_CONT | ||
| 159 | + << __SRS_JFIELD_ORG("vhost", stream->vhost->id) | ||
| 160 | + << __SRS_JOBJECT_END; | ||
| 161 | + } | ||
| 162 | + | ||
| 163 | + return ret; | ||
| 164 | +} |
trunk/src/app/srs_app_statistic.hpp
0 → 100644
| 1 | +/* | ||
| 2 | +The MIT License (MIT) | ||
| 3 | + | ||
| 4 | +Copyright (c) 2013-2015 winlin | ||
| 5 | + | ||
| 6 | +Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
| 7 | +this software and associated documentation files (the "Software"), to deal in | ||
| 8 | +the Software without restriction, including without limitation the rights to | ||
| 9 | +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
| 10 | +the Software, and to permit persons to whom the Software is furnished to do so, | ||
| 11 | +subject to the following conditions: | ||
| 12 | + | ||
| 13 | +The above copyright notice and this permission notice shall be included in all | ||
| 14 | +copies or substantial portions of the Software. | ||
| 15 | + | ||
| 16 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| 17 | +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
| 18 | +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
| 19 | +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
| 20 | +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
| 21 | +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 22 | +*/ | ||
| 23 | + | ||
| 24 | +#ifndef SRS_APP_STATISTIC_HPP | ||
| 25 | +#define SRS_APP_STATISTIC_HPP | ||
| 26 | + | ||
| 27 | +/* | ||
| 28 | +#include <srs_app_statistic.hpp> | ||
| 29 | +*/ | ||
| 30 | + | ||
| 31 | +#include <srs_core.hpp> | ||
| 32 | + | ||
| 33 | +#include <map> | ||
| 34 | +#include <string> | ||
| 35 | + | ||
| 36 | +class SrsRequest; | ||
| 37 | + | ||
| 38 | +struct SrsStatisticVhost | ||
| 39 | +{ | ||
| 40 | +public: | ||
| 41 | + int64_t id; | ||
| 42 | + std::string vhost; | ||
| 43 | +public: | ||
| 44 | + SrsStatisticVhost(); | ||
| 45 | + virtual ~SrsStatisticVhost(); | ||
| 46 | +}; | ||
| 47 | + | ||
| 48 | +struct SrsStatisticStream | ||
| 49 | +{ | ||
| 50 | +public: | ||
| 51 | + int64_t id; | ||
| 52 | + SrsStatisticVhost* vhost; | ||
| 53 | + std::string app; | ||
| 54 | + std::string stream; | ||
| 55 | + std::string url; | ||
| 56 | +public: | ||
| 57 | + SrsStatisticStream(); | ||
| 58 | + virtual ~SrsStatisticStream(); | ||
| 59 | +}; | ||
| 60 | + | ||
| 61 | +struct SrsStatisticClient | ||
| 62 | +{ | ||
| 63 | +public: | ||
| 64 | + SrsStatisticStream* stream; | ||
| 65 | + int id; | ||
| 66 | +}; | ||
| 67 | + | ||
| 68 | +class SrsStatistic | ||
| 69 | +{ | ||
| 70 | +private: | ||
| 71 | + static SrsStatistic *_instance; | ||
| 72 | + // the id to identify the sever. | ||
| 73 | + int64_t _server_id; | ||
| 74 | + // key: vhost name, value: vhost object. | ||
| 75 | + std::map<std::string, SrsStatisticVhost*> vhosts; | ||
| 76 | + // key: stream name, value: stream object. | ||
| 77 | + std::map<std::string, SrsStatisticStream*> streams; | ||
| 78 | + // key: client id, value: stream object. | ||
| 79 | + std::map<int, SrsStatisticClient*> clients; | ||
| 80 | +private: | ||
| 81 | + SrsStatistic(); | ||
| 82 | + virtual ~SrsStatistic(); | ||
| 83 | +public: | ||
| 84 | + static SrsStatistic* instance(); | ||
| 85 | +public: | ||
| 86 | + /** | ||
| 87 | + * when got a client to publish/play stream, | ||
| 88 | + * @param id, the client srs id. | ||
| 89 | + * @param req, the client request object. | ||
| 90 | + */ | ||
| 91 | + virtual int on_client(int id, SrsRequest* req); | ||
| 92 | +public: | ||
| 93 | + /** | ||
| 94 | + * get the server id, used to identify the server. | ||
| 95 | + * for example, when restart, the server id must changed. | ||
| 96 | + */ | ||
| 97 | + virtual int64_t server_id(); | ||
| 98 | + /** | ||
| 99 | + * dumps the vhosts to sstream in json. | ||
| 100 | + */ | ||
| 101 | + virtual int dumps_vhosts(std::stringstream& ss); | ||
| 102 | + /** | ||
| 103 | + * dumps the streams to sstream in json. | ||
| 104 | + */ | ||
| 105 | + virtual int dumps_streams(std::stringstream& ss); | ||
| 106 | +}; | ||
| 107 | + | ||
| 108 | +#endif |
| 1 | file | 1 | file |
| 2 | - main readonly separator, | ||
| 3 | - ..\main\srs_main_server.cpp, | ||
| 4 | - auto readonly separator, | ||
| 5 | - ..\..\objs\srs_auto_headers.hpp, | ||
| 6 | - libs readonly separator, | ||
| 7 | - ..\libs\srs_librtmp.hpp, | ||
| 8 | - ..\libs\srs_librtmp.cpp, | ||
| 9 | - ..\libs\srs_lib_bandwidth.hpp, | ||
| 10 | - ..\libs\srs_lib_bandwidth.cpp, | ||
| 11 | - ..\libs\srs_lib_simple_socket.hpp, | ||
| 12 | - ..\libs\srs_lib_simple_socket.cpp, | ||
| 13 | - core readonly separator, | ||
| 14 | - ..\core\srs_core.hpp, | ||
| 15 | - ..\core\srs_core.cpp, | ||
| 16 | - ..\core\srs_core_autofree.hpp, | ||
| 17 | - ..\core\srs_core_autofree.cpp, | ||
| 18 | - ..\core\srs_core_performance.hpp, | ||
| 19 | - ..\core\srs_core_performance.cpp, | ||
| 20 | - kernel readonly separator, | ||
| 21 | - ..\kernel\srs_kernel_codec.hpp, | ||
| 22 | - ..\kernel\srs_kernel_codec.cpp, | ||
| 23 | - ..\kernel\srs_kernel_consts.hpp, | ||
| 24 | - ..\kernel\srs_kernel_consts.cpp, | ||
| 25 | - ..\kernel\srs_kernel_error.hpp, | ||
| 26 | - ..\kernel\srs_kernel_error.cpp, | ||
| 27 | - ..\kernel\srs_kernel_file.hpp, | ||
| 28 | - ..\kernel\srs_kernel_file.cpp, | ||
| 29 | - ..\kernel\srs_kernel_flv.hpp, | ||
| 30 | - ..\kernel\srs_kernel_flv.cpp, | ||
| 31 | - ..\kernel\srs_kernel_log.hpp, | ||
| 32 | - ..\kernel\srs_kernel_log.cpp, | ||
| 33 | - ..\kernel\srs_kernel_stream.hpp, | ||
| 34 | - ..\kernel\srs_kernel_stream.cpp, | ||
| 35 | - ..\kernel\srs_kernel_utility.hpp, | ||
| 36 | - ..\kernel\srs_kernel_utility.cpp, | ||
| 37 | - rtmp-protocol readonly separator, | ||
| 38 | - ..\rtmp\srs_protocol_amf0.hpp, | ||
| 39 | - ..\rtmp\srs_protocol_amf0.cpp, | ||
| 40 | - ..\rtmp\srs_protocol_buffer.hpp, | ||
| 41 | - ..\rtmp\srs_protocol_buffer.cpp, | ||
| 42 | - ..\rtmp\srs_protocol_handshake.hpp, | ||
| 43 | - ..\rtmp\srs_protocol_handshake.cpp, | ||
| 44 | - ..\rtmp\srs_protocol_io.hpp, | ||
| 45 | - ..\rtmp\srs_protocol_io.cpp, | ||
| 46 | - ..\rtmp\srs_protocol_msg_array.hpp, | ||
| 47 | - ..\rtmp\srs_protocol_msg_array.cpp, | ||
| 48 | - ..\rtmp\srs_protocol_rtmp.hpp, | ||
| 49 | - ..\rtmp\srs_protocol_rtmp.cpp, | ||
| 50 | - ..\rtmp\srs_protocol_stack.hpp, | ||
| 51 | - ..\rtmp\srs_protocol_stack.cpp, | ||
| 52 | - ..\rtmp\srs_protocol_utility.hpp, | ||
| 53 | - ..\rtmp\srs_protocol_utility.cpp, | ||
| 54 | - app readonly separator, | ||
| 55 | - ..\app\srs_app_avc_aac.hpp, | ||
| 56 | - ..\app\srs_app_avc_aac.cpp, | ||
| 57 | - ..\app\srs_app_bandwidth.hpp, | ||
| 58 | - ..\app\srs_app_bandwidth.cpp, | ||
| 59 | - ..\app\srs_app_conn.hpp, | ||
| 60 | - ..\app\srs_app_conn.cpp, | ||
| 61 | - ..\app\srs_app_config.hpp, | ||
| 62 | - ..\app\srs_app_config.cpp, | ||
| 63 | - ..\app\srs_app_dvr.hpp, | ||
| 64 | - ..\app\srs_app_dvr.cpp, | ||
| 65 | - ..\app\srs_app_edge.hpp, | ||
| 66 | - ..\app\srs_app_edge.cpp, | ||
| 67 | - ..\app\srs_app_empty.hpp, | ||
| 68 | - ..\app\srs_app_empty.cpp, | ||
| 69 | - ..\app\srs_app_encoder.hpp, | ||
| 70 | - ..\app\srs_app_encoder.cpp, | ||
| 71 | - ..\app\srs_app_ffmpeg.hpp, | ||
| 72 | - ..\app\srs_app_ffmpeg.cpp, | ||
| 73 | - ..\app\srs_app_forward.hpp, | ||
| 74 | - ..\app\srs_app_forward.cpp, | ||
| 75 | - ..\app\srs_app_heartbeat.hpp, | ||
| 76 | - ..\app\srs_app_heartbeat.cpp, | ||
| 77 | - ..\app\srs_app_hls.hpp, | ||
| 78 | - ..\app\srs_app_hls.cpp, | ||
| 79 | - ..\app\srs_app_http.hpp, | ||
| 80 | - ..\app\srs_app_http.cpp, | ||
| 81 | - ..\app\srs_app_http_api.hpp, | ||
| 82 | - ..\app\srs_app_http_api.cpp, | ||
| 83 | - ..\app\srs_app_http_client.hpp, | ||
| 84 | - ..\app\srs_app_http_client.cpp, | ||
| 85 | - ..\app\srs_app_http_conn.hpp, | ||
| 86 | - ..\app\srs_app_http_conn.cpp, | ||
| 87 | - ..\app\srs_app_http_hooks.hpp, | ||
| 88 | - ..\app\srs_app_http_hooks.cpp, | ||
| 89 | - ..\app\srs_app_ingest.hpp, | ||
| 90 | - ..\app\srs_app_ingest.cpp, | ||
| 91 | - ..\app\srs_app_json.hpp, | ||
| 92 | - ..\app\srs_app_json.cpp, | ||
| 93 | - ..\app\srs_app_kbps.hpp, | ||
| 94 | - ..\app\srs_app_kbps.cpp, | ||
| 95 | - ..\app\srs_app_log.hpp, | ||
| 96 | - ..\app\srs_app_log.cpp, | ||
| 97 | - ..\app\srs_app_recv_thread.hpp, | ||
| 98 | - ..\app\srs_app_recv_thread.cpp, | ||
| 99 | - ..\app\srs_app_refer.hpp, | ||
| 100 | - ..\app\srs_app_refer.cpp, | ||
| 101 | - ..\app\srs_app_reload.hpp, | ||
| 102 | - ..\app\srs_app_reload.cpp, | ||
| 103 | - ..\app\srs_app_rtmp_conn.hpp, | ||
| 104 | - ..\app\srs_app_rtmp_conn.cpp, | ||
| 105 | - ..\app\srs_app_pithy_print.hpp, | ||
| 106 | - ..\app\srs_app_pithy_print.cpp, | ||
| 107 | - ..\app\srs_app_security.hpp, | ||
| 108 | - ..\app\srs_app_security.cpp, | ||
| 109 | - ..\app\srs_app_server.hpp, | ||
| 110 | - ..\app\srs_app_server.cpp, | ||
| 111 | - ..\app\srs_app_st.hpp, | ||
| 112 | - ..\app\srs_app_st.cpp, | ||
| 113 | - ..\app\srs_app_st_socket.hpp, | ||
| 114 | - ..\app\srs_app_st_socket.cpp, | ||
| 115 | - ..\app\srs_app_source.hpp, | ||
| 116 | - ..\app\srs_app_source.cpp, | ||
| 117 | - ..\app\srs_app_thread.hpp, | ||
| 118 | - ..\app\srs_app_thread.cpp, | ||
| 119 | - ..\app\srs_app_utility.hpp, | ||
| 120 | - ..\app\srs_app_utility.cpp, | ||
| 121 | - utest readonly separator, | ||
| 122 | - ..\utest\srs_utest.hpp, | ||
| 123 | - ..\utest\srs_utest.cpp, | ||
| 124 | - ..\utest\srs_utest_amf0.hpp, | ||
| 125 | - ..\utest\srs_utest_amf0.cpp, | ||
| 126 | - ..\utest\srs_utest_config.hpp, | ||
| 127 | - ..\utest\srs_utest_config.cpp, | ||
| 128 | - ..\utest\srs_utest_core.hpp, | ||
| 129 | - ..\utest\srs_utest_core.cpp, | ||
| 130 | - ..\utest\srs_utest_kernel.hpp, | ||
| 131 | - ..\utest\srs_utest_kernel.cpp, | ||
| 132 | - ..\utest\srs_utest_protocol.hpp, | ||
| 133 | - ..\utest\srs_utest_protocol.cpp, | ||
| 134 | - ..\utest\srs_utest_reload.hpp, | ||
| 135 | - ..\utest\srs_utest_reload.cpp, | ||
| 136 | - research readonly separator, | ||
| 137 | - ..\..\research\librtmp\srs_aac_raw_publish.c, | ||
| 138 | - ..\..\research\librtmp\srs_audio_raw_publish.c, | ||
| 139 | - ..\..\research\librtmp\srs_bandwidth_check.c, | ||
| 140 | - ..\..\research\librtmp\srs_detect_rtmp.c, | ||
| 141 | - ..\..\research\librtmp\srs_flv_injecter.c, | ||
| 142 | - ..\..\research\librtmp\srs_flv_parser.c, | ||
| 143 | - ..\..\research\librtmp\srs_h264_raw_publish.c, | ||
| 144 | - ..\..\research\librtmp\srs_ingest_flv.c, | ||
| 145 | - ..\..\research\librtmp\srs_ingest_rtmp.c, | ||
| 146 | - ..\..\research\librtmp\srs_play.c, | ||
| 147 | - ..\..\research\librtmp\srs_publish.c, | ||
| 148 | - ..\..\research\librtmp\srs_rtmp_dump.c, | ||
| 149 | - ..\..\research\hls\ts_info.cc; | 2 | + main readonly separator, |
| 3 | + ..\main\srs_main_server.cpp, | ||
| 4 | + auto readonly separator, | ||
| 5 | + ..\..\objs\srs_auto_headers.hpp, | ||
| 6 | + libs readonly separator, | ||
| 7 | + ..\libs\srs_librtmp.hpp, | ||
| 8 | + ..\libs\srs_librtmp.cpp, | ||
| 9 | + ..\libs\srs_lib_bandwidth.hpp, | ||
| 10 | + ..\libs\srs_lib_bandwidth.cpp, | ||
| 11 | + ..\libs\srs_lib_simple_socket.hpp, | ||
| 12 | + ..\libs\srs_lib_simple_socket.cpp, | ||
| 13 | + core readonly separator, | ||
| 14 | + ..\core\srs_core.hpp, | ||
| 15 | + ..\core\srs_core.cpp, | ||
| 16 | + ..\core\srs_core_autofree.hpp, | ||
| 17 | + ..\core\srs_core_autofree.cpp, | ||
| 18 | + ..\core\srs_core_performance.hpp, | ||
| 19 | + ..\core\srs_core_performance.cpp, | ||
| 20 | + kernel readonly separator, | ||
| 21 | + ..\kernel\srs_kernel_codec.hpp, | ||
| 22 | + ..\kernel\srs_kernel_codec.cpp, | ||
| 23 | + ..\kernel\srs_kernel_consts.hpp, | ||
| 24 | + ..\kernel\srs_kernel_consts.cpp, | ||
| 25 | + ..\kernel\srs_kernel_error.hpp, | ||
| 26 | + ..\kernel\srs_kernel_error.cpp, | ||
| 27 | + ..\kernel\srs_kernel_file.hpp, | ||
| 28 | + ..\kernel\srs_kernel_file.cpp, | ||
| 29 | + ..\kernel\srs_kernel_flv.hpp, | ||
| 30 | + ..\kernel\srs_kernel_flv.cpp, | ||
| 31 | + ..\kernel\srs_kernel_log.hpp, | ||
| 32 | + ..\kernel\srs_kernel_log.cpp, | ||
| 33 | + ..\kernel\srs_kernel_stream.hpp, | ||
| 34 | + ..\kernel\srs_kernel_stream.cpp, | ||
| 35 | + ..\kernel\srs_kernel_utility.hpp, | ||
| 36 | + ..\kernel\srs_kernel_utility.cpp, | ||
| 37 | + rtmp-protocol readonly separator, | ||
| 38 | + ..\rtmp\srs_protocol_amf0.hpp, | ||
| 39 | + ..\rtmp\srs_protocol_amf0.cpp, | ||
| 40 | + ..\rtmp\srs_protocol_buffer.hpp, | ||
| 41 | + ..\rtmp\srs_protocol_buffer.cpp, | ||
| 42 | + ..\rtmp\srs_protocol_handshake.hpp, | ||
| 43 | + ..\rtmp\srs_protocol_handshake.cpp, | ||
| 44 | + ..\rtmp\srs_protocol_io.hpp, | ||
| 45 | + ..\rtmp\srs_protocol_io.cpp, | ||
| 46 | + ..\rtmp\srs_protocol_msg_array.hpp, | ||
| 47 | + ..\rtmp\srs_protocol_msg_array.cpp, | ||
| 48 | + ..\rtmp\srs_protocol_rtmp.hpp, | ||
| 49 | + ..\rtmp\srs_protocol_rtmp.cpp, | ||
| 50 | + ..\rtmp\srs_protocol_stack.hpp, | ||
| 51 | + ..\rtmp\srs_protocol_stack.cpp, | ||
| 52 | + ..\rtmp\srs_protocol_utility.hpp, | ||
| 53 | + ..\rtmp\srs_protocol_utility.cpp, | ||
| 54 | + app readonly separator, | ||
| 55 | + ..\app\srs_app_avc_aac.hpp, | ||
| 56 | + ..\app\srs_app_avc_aac.cpp, | ||
| 57 | + ..\app\srs_app_bandwidth.hpp, | ||
| 58 | + ..\app\srs_app_bandwidth.cpp, | ||
| 59 | + ..\app\srs_app_conn.hpp, | ||
| 60 | + ..\app\srs_app_conn.cpp, | ||
| 61 | + ..\app\srs_app_config.hpp, | ||
| 62 | + ..\app\srs_app_config.cpp, | ||
| 63 | + ..\app\srs_app_dvr.hpp, | ||
| 64 | + ..\app\srs_app_dvr.cpp, | ||
| 65 | + ..\app\srs_app_edge.hpp, | ||
| 66 | + ..\app\srs_app_edge.cpp, | ||
| 67 | + ..\app\srs_app_empty.hpp, | ||
| 68 | + ..\app\srs_app_empty.cpp, | ||
| 69 | + ..\app\srs_app_encoder.hpp, | ||
| 70 | + ..\app\srs_app_encoder.cpp, | ||
| 71 | + ..\app\srs_app_ffmpeg.hpp, | ||
| 72 | + ..\app\srs_app_ffmpeg.cpp, | ||
| 73 | + ..\app\srs_app_forward.hpp, | ||
| 74 | + ..\app\srs_app_forward.cpp, | ||
| 75 | + ..\app\srs_app_heartbeat.hpp, | ||
| 76 | + ..\app\srs_app_heartbeat.cpp, | ||
| 77 | + ..\app\srs_app_hls.hpp, | ||
| 78 | + ..\app\srs_app_hls.cpp, | ||
| 79 | + ..\app\srs_app_http.hpp, | ||
| 80 | + ..\app\srs_app_http.cpp, | ||
| 81 | + ..\app\srs_app_http_api.hpp, | ||
| 82 | + ..\app\srs_app_http_api.cpp, | ||
| 83 | + ..\app\srs_app_http_client.hpp, | ||
| 84 | + ..\app\srs_app_http_client.cpp, | ||
| 85 | + ..\app\srs_app_http_conn.hpp, | ||
| 86 | + ..\app\srs_app_http_conn.cpp, | ||
| 87 | + ..\app\srs_app_http_hooks.hpp, | ||
| 88 | + ..\app\srs_app_http_hooks.cpp, | ||
| 89 | + ..\app\srs_app_ingest.hpp, | ||
| 90 | + ..\app\srs_app_ingest.cpp, | ||
| 91 | + ..\app\srs_app_json.hpp, | ||
| 92 | + ..\app\srs_app_json.cpp, | ||
| 93 | + ..\app\srs_app_kbps.hpp, | ||
| 94 | + ..\app\srs_app_kbps.cpp, | ||
| 95 | + ..\app\srs_app_log.hpp, | ||
| 96 | + ..\app\srs_app_log.cpp, | ||
| 97 | + ..\app\srs_app_recv_thread.hpp, | ||
| 98 | + ..\app\srs_app_recv_thread.cpp, | ||
| 99 | + ..\app\srs_app_refer.hpp, | ||
| 100 | + ..\app\srs_app_refer.cpp, | ||
| 101 | + ..\app\srs_app_reload.hpp, | ||
| 102 | + ..\app\srs_app_reload.cpp, | ||
| 103 | + ..\app\srs_app_rtmp_conn.hpp, | ||
| 104 | + ..\app\srs_app_rtmp_conn.cpp, | ||
| 105 | + ..\app\srs_app_pithy_print.hpp, | ||
| 106 | + ..\app\srs_app_pithy_print.cpp, | ||
| 107 | + ..\app\srs_app_security.hpp, | ||
| 108 | + ..\app\srs_app_security.cpp, | ||
| 109 | + ..\app\srs_app_server.hpp, | ||
| 110 | + ..\app\srs_app_server.cpp, | ||
| 111 | + ..\app\srs_app_st.hpp, | ||
| 112 | + ..\app\srs_app_st.cpp, | ||
| 113 | + ..\app\srs_app_st_socket.hpp, | ||
| 114 | + ..\app\srs_app_st_socket.cpp, | ||
| 115 | + ..\app\srs_app_statistic.hpp, | ||
| 116 | + ..\app\srs_app_statistic.cpp, | ||
| 117 | + ..\app\srs_app_source.hpp, | ||
| 118 | + ..\app\srs_app_source.cpp, | ||
| 119 | + ..\app\srs_app_thread.hpp, | ||
| 120 | + ..\app\srs_app_thread.cpp, | ||
| 121 | + ..\app\srs_app_utility.hpp, | ||
| 122 | + ..\app\srs_app_utility.cpp, | ||
| 123 | + utest readonly separator, | ||
| 124 | + ..\utest\srs_utest.hpp, | ||
| 125 | + ..\utest\srs_utest.cpp, | ||
| 126 | + ..\utest\srs_utest_amf0.hpp, | ||
| 127 | + ..\utest\srs_utest_amf0.cpp, | ||
| 128 | + ..\utest\srs_utest_config.hpp, | ||
| 129 | + ..\utest\srs_utest_config.cpp, | ||
| 130 | + ..\utest\srs_utest_core.hpp, | ||
| 131 | + ..\utest\srs_utest_core.cpp, | ||
| 132 | + ..\utest\srs_utest_kernel.hpp, | ||
| 133 | + ..\utest\srs_utest_kernel.cpp, | ||
| 134 | + ..\utest\srs_utest_protocol.hpp, | ||
| 135 | + ..\utest\srs_utest_protocol.cpp, | ||
| 136 | + ..\utest\srs_utest_reload.hpp, | ||
| 137 | + ..\utest\srs_utest_reload.cpp, | ||
| 138 | + research readonly separator, | ||
| 139 | + ..\..\research\librtmp\srs_aac_raw_publish.c, | ||
| 140 | + ..\..\research\librtmp\srs_audio_raw_publish.c, | ||
| 141 | + ..\..\research\librtmp\srs_bandwidth_check.c, | ||
| 142 | + ..\..\research\librtmp\srs_detect_rtmp.c, | ||
| 143 | + ..\..\research\librtmp\srs_flv_injecter.c, | ||
| 144 | + ..\..\research\librtmp\srs_flv_parser.c, | ||
| 145 | + ..\..\research\librtmp\srs_h264_raw_publish.c, | ||
| 146 | + ..\..\research\librtmp\srs_ingest_flv.c, | ||
| 147 | + ..\..\research\librtmp\srs_ingest_rtmp.c, | ||
| 148 | + ..\..\research\librtmp\srs_play.c, | ||
| 149 | + ..\..\research\librtmp\srs_publish.c, | ||
| 150 | + ..\..\research\librtmp\srs_rtmp_dump.c, | ||
| 151 | + ..\..\research\hls\ts_info.cc; | ||
| 150 | 152 | ||
| 151 | mainconfig | 153 | mainconfig |
| 152 | - "" = "MAIN"; | 154 | + "" = "MAIN"; |
| 153 | 155 |
-
请 注册 或 登录 后发表评论