Skip to content

Commit

Permalink
Support override ip by env.
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Sep 5, 2024
1 parent b97968c commit 2e79d00
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions trunk/src/app/srs_app_heartbeat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,23 @@ 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<SrsIPAddress*>& 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<SrsIPAddress*>& ips = srs_get_local_ips();
if (!ips.empty()) {
ip = ips[_srs_config->get_stats_network() % (int) ips.size()]->ip;
}
}

SrsUniquePtr<SrsJsonObject> 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()));
Expand Down

0 comments on commit 2e79d00

Please sign in to comment.