diff --git a/.run/private.run.xml b/.run/private.run.xml index 458dabc613..5f46184622 100644 --- a/.run/private.run.xml +++ b/.run/private.run.xml @@ -1,7 +1,6 @@ - diff --git a/trunk/conf/full.conf b/trunk/conf/full.conf index 0579788fac..a84309c226 100644 --- a/trunk/conf/full.conf +++ b/trunk/conf/full.conf @@ -907,6 +907,14 @@ heartbeat { # Overwrite by env SRS_HEARTBEAT_SUMMARIES # default: off summaries off; + # Whether report with listen ports. + # if on, request with the ports of SRS: + # { + # "rtmp": ["1935"], "http": ["8080"], "api": ["1985"], "srt": ["10080"], "rtc": ["8000"] + # } + # Overwrite by env SRS_HEARTBEAT_PORTS + # default: off + ports off; } # system statistics section. diff --git a/trunk/doc/CHANGELOG.md b/trunk/doc/CHANGELOG.md index c6eae0b8fc..2772c0bf21 100644 --- a/trunk/doc/CHANGELOG.md +++ b/trunk/doc/CHANGELOG.md @@ -7,6 +7,7 @@ The changelog for SRS. ## SRS 7.0 Changelog +* v7.0, 2024-09-09, Merge [#4171](https://github.com/ossrs/srs/pull/4171): Heartbeat: Report ports for proxy server. v7.0.15 (#4171) * v7.0, 2024-09-01, Merge [#4165](https://github.com/ossrs/srs/pull/4165): FLV: Refine source and http handler. v7.0.14 (#4165) * v7.0, 2024-09-01, Merge [#4166](https://github.com/ossrs/srs/pull/4166): Edge: Fix flv edge crash when http unmount. v7.0.13 (#4166) * v7.0, 2024-08-31, Merge [#4162](https://github.com/ossrs/srs/pull/4162): Fix #3767: RTMP: Do not response empty data packet. v7.0.12 (#4162) @@ -26,6 +27,7 @@ The changelog for SRS. ## SRS 6.0 Changelog +* v6.0, 2024-09-09, Merge [#4171](https://github.com/ossrs/srs/pull/4171): Heartbeat: Report ports for proxy server. v6.0.156 (#4171) * v6.0, 2024-09-01, Merge [#4165](https://github.com/ossrs/srs/pull/4165): FLV: Refine source and http handler. v6.0.155 (#4165) * v6.0, 2024-09-01, Merge [#4166](https://github.com/ossrs/srs/pull/4166): Edge: Fix flv edge crash when http unmount. v6.0.154 (#4166) * v6.0, 2024-08-31, Merge [#4162](https://github.com/ossrs/srs/pull/4162): Fix #3767: RTMP: Do not response empty data packet. v6.0.153 (#4162) @@ -185,6 +187,7 @@ The changelog for SRS. ## SRS 5.0 Changelog +* v5.0, 2024-09-09, Merge [#4171](https://github.com/ossrs/srs/pull/4171): Heartbeat: Report ports for proxy server. v5.0.215 (#4171) * v5.0, 2024-07-24, Merge [#4126](https://github.com/ossrs/srs/pull/4126): Edge: Improve stability for state and fd closing. v5.0.214 (#4126) * v5.0, 2024-06-03, Merge [#4057](https://github.com/ossrs/srs/pull/4057): RTC: Support dropping h.264 SEI from NALUs. v5.0.213 (#4057) * v5.0, 2024-04-23, Merge [#4038](https://github.com/ossrs/srs/pull/4038): RTMP: Do not response publish start message if hooks fail. v5.0.212 (#4038) diff --git a/trunk/src/app/srs_app_config.cpp b/trunk/src/app/srs_app_config.cpp index 0731f3cd2b..eeae92ef16 100644 --- a/trunk/src/app/srs_app_config.cpp +++ b/trunk/src/app/srs_app_config.cpp @@ -2409,7 +2409,7 @@ srs_error_t SrsConfig::check_normal_config() for (int i = 0; conf && i < (int)conf->directives.size(); i++) { string n = conf->at(i)->name; if (n != "enabled" && n != "interval" && n != "url" - && n != "device_id" && n != "summaries") { + && n != "device_id" && n != "summaries" && n != "ports") { return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "illegal heartbeat.%s", n.c_str()); } } @@ -8794,17 +8794,36 @@ bool SrsConfig::get_heartbeat_summaries() SRS_OVERWRITE_BY_ENV_BOOL("srs.heartbeat.summaries"); // SRS_HEARTBEAT_SUMMARIES static bool DEFAULT = false; - + SrsConfDirective* conf = get_heartbeart(); if (!conf) { return DEFAULT; } - + conf = conf->get("summaries"); if (!conf || conf->arg0().empty()) { return DEFAULT; } - + + return SRS_CONF_PREFER_FALSE(conf->arg0()); +} + +bool SrsConfig::get_heartbeat_ports() +{ + SRS_OVERWRITE_BY_ENV_BOOL("srs.heartbeat.ports"); // SRS_HEARTBEAT_PORTS + + static bool DEFAULT = false; + + SrsConfDirective* conf = get_heartbeart(); + if (!conf) { + return DEFAULT; + } + + conf = conf->get("ports"); + if (!conf || conf->arg0().empty()) { + return DEFAULT; + } + return SRS_CONF_PREFER_FALSE(conf->arg0()); } diff --git a/trunk/src/app/srs_app_config.hpp b/trunk/src/app/srs_app_config.hpp index 28aec179db..e7432d14cf 100644 --- a/trunk/src/app/srs_app_config.hpp +++ b/trunk/src/app/srs_app_config.hpp @@ -1119,6 +1119,7 @@ class SrsConfig virtual std::string get_heartbeat_device_id(); // Whether report with summaries of http api: /api/v1/summaries. virtual bool get_heartbeat_summaries(); + bool get_heartbeat_ports(); // stats section private: // Get the stats directive. diff --git a/trunk/src/app/srs_app_heartbeat.cpp b/trunk/src/app/srs_app_heartbeat.cpp index 819075a687..c57ee37571 100644 --- a/trunk/src/app/srs_app_heartbeat.cpp +++ b/trunk/src/app/srs_app_heartbeat.cpp @@ -18,6 +18,8 @@ using namespace std; #include #include #include +#include +#include SrsHttpHeartbeat::SrsHttpHeartbeat() { @@ -48,18 +50,28 @@ srs_error_t SrsHttpHeartbeat::do_heartbeat() return srs_error_wrap(err, "http uri parse hartbeart url failed. url=%s", url.c_str()); } - SrsIPAddress* ip = NULL; + string ip; std::string device_id = _srs_config->get_heartbeat_device_id(); - - vector& ips = srs_get_local_ips(); - if (!ips.empty()) { - ip = ips[_srs_config->get_stats_network() % (int)ips.size()]; + + // Try to load the ip from the environment variable. + ip = srs_getenv("srs.device.ip"); // SRS_DEVICE_IP + if (ip.empty()) { + // Use the local ip address specified by the stats.network config. + vector& ips = srs_get_local_ips(); + if (!ips.empty()) { + ip = ips[_srs_config->get_stats_network() % (int) ips.size()]->ip; + } } SrsUniquePtr obj(SrsJsonAny::object()); obj->set("device_id", SrsJsonAny::str(device_id.c_str())); - obj->set("ip", SrsJsonAny::str(ip->ip.c_str())); + obj->set("ip", SrsJsonAny::str(ip.c_str())); + + SrsStatistic* stat = SrsStatistic::instance(); + obj->set("server", SrsJsonAny::str(stat->server_id().c_str())); + obj->set("service", SrsJsonAny::str(stat->service_id().c_str())); + obj->set("pid", SrsJsonAny::str(stat->service_pid().c_str())); if (_srs_config->get_heartbeat_summaries()) { SrsJsonObject* summaries = SrsJsonAny::object(); @@ -67,6 +79,60 @@ srs_error_t SrsHttpHeartbeat::do_heartbeat() srs_api_dump_summaries(summaries); } + + if (_srs_config->get_heartbeat_ports()) { + // For RTMP listen endpoints. + if (true) { + SrsJsonArray* o = SrsJsonAny::array(); + obj->set("rtmp", o); + + vector endpoints = _srs_config->get_listens(); + for (int i = 0; i < (int) endpoints.size(); i++) { + o->append(SrsJsonAny::str(endpoints.at(i).c_str())); + } + } + + // For HTTP Stream listen endpoints. + if (_srs_config->get_http_stream_enabled()) { + SrsJsonArray* o = SrsJsonAny::array(); + obj->set("http", o); + + string endpoint = _srs_config->get_http_stream_listen(); + o->append(SrsJsonAny::str(endpoint.c_str())); + } + + // For HTTP API listen endpoints. + if (_srs_config->get_http_api_enabled()) { + SrsJsonArray* o = SrsJsonAny::array(); + obj->set("api", o); + + string endpoint = _srs_config->get_http_api_listen(); + o->append(SrsJsonAny::str(endpoint.c_str())); + } + + // For SRT listen endpoints. + if (_srs_config->get_srt_enabled()) { + SrsJsonArray* o = SrsJsonAny::array(); + obj->set("srt", o); + + uint16_t endpoint = _srs_config->get_srt_listen_port(); + o->append(SrsJsonAny::str(srs_fmt("udp://0.0.0.0:%d", endpoint).c_str())); + } + + // For WebRTC listen endpoints. + if (_srs_config->get_rtc_server_enabled()) { + SrsJsonArray* o = SrsJsonAny::array(); + obj->set("rtc", o); + + int endpoint = _srs_config->get_rtc_server_listen(); + o->append(SrsJsonAny::str(srs_fmt("udp://0.0.0.0:%d", endpoint).c_str())); + + if (_srs_config->get_rtc_server_tcp_enabled()) { + endpoint = _srs_config->get_rtc_server_tcp_listen(); + o->append(SrsJsonAny::str(srs_fmt("tcp://0.0.0.0:%d", endpoint).c_str())); + } + } + } SrsHttpClient http; if ((err = http.initialize(uri.get_schema(), uri.get_host(), uri.get_port())) != srs_success) { diff --git a/trunk/src/core/srs_core_version5.hpp b/trunk/src/core/srs_core_version5.hpp index ef74aa44d3..791b3ae6ed 100644 --- a/trunk/src/core/srs_core_version5.hpp +++ b/trunk/src/core/srs_core_version5.hpp @@ -9,6 +9,6 @@ #define VERSION_MAJOR 5 #define VERSION_MINOR 0 -#define VERSION_REVISION 214 +#define VERSION_REVISION 215 #endif diff --git a/trunk/src/core/srs_core_version6.hpp b/trunk/src/core/srs_core_version6.hpp index 32328d99a8..69725cd535 100644 --- a/trunk/src/core/srs_core_version6.hpp +++ b/trunk/src/core/srs_core_version6.hpp @@ -9,6 +9,6 @@ #define VERSION_MAJOR 6 #define VERSION_MINOR 0 -#define VERSION_REVISION 155 +#define VERSION_REVISION 156 #endif diff --git a/trunk/src/core/srs_core_version7.hpp b/trunk/src/core/srs_core_version7.hpp index ee85bc8206..fed95c499b 100644 --- a/trunk/src/core/srs_core_version7.hpp +++ b/trunk/src/core/srs_core_version7.hpp @@ -9,6 +9,6 @@ #define VERSION_MAJOR 7 #define VERSION_MINOR 0 -#define VERSION_REVISION 14 +#define VERSION_REVISION 15 #endif \ No newline at end of file