@ -18,6 +18,8 @@ using namespace std;
# include <srs_core_autofree.hpp>
# include <srs_core_autofree.hpp>
# include <srs_app_http_conn.hpp>
# include <srs_app_http_conn.hpp>
# include <srs_protocol_amf0.hpp>
# include <srs_protocol_amf0.hpp>
# include <srs_kernel_utility.hpp>
# include <srs_app_statistic.hpp>
SrsHttpHeartbeat : : SrsHttpHeartbeat ( )
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 ( ) ) ;
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 ( ) ;
std : : string device_id = _srs_config - > get_heartbeat_device_id ( ) ;
// 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 ( ) ;
vector < SrsIPAddress * > & ips = srs_get_local_ips ( ) ;
if ( ! ips . empty ( ) ) {
if ( ! ips . empty ( ) ) {
ip = ips [ _srs_config - > get_stats_network ( ) % ( int ) ips . size ( ) ] ;
ip = ips [ _srs_config - > get_stats_network ( ) % ( int ) ips . size ( ) ] - > ip ;
}
}
}
SrsUniquePtr < SrsJsonObject > obj ( SrsJsonAny : : object ( ) ) ;
SrsUniquePtr < SrsJsonObject > obj ( SrsJsonAny : : object ( ) ) ;
obj - > set ( " device_id " , SrsJsonAny : : str ( device_id . c_str ( ) ) ) ;
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 ( ) ) {
if ( _srs_config - > get_heartbeat_summaries ( ) ) {
SrsJsonObject * summaries = SrsJsonAny : : object ( ) ;
SrsJsonObject * summaries = SrsJsonAny : : object ( ) ;
@ -68,6 +80,60 @@ srs_error_t SrsHttpHeartbeat::do_heartbeat()
srs_api_dump_summaries ( summaries ) ;
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 < string > 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 ;
SrsHttpClient http ;
if ( ( err = http . initialize ( uri . get_schema ( ) , uri . get_host ( ) , uri . get_port ( ) ) ) ! = srs_success ) {
if ( ( err = http . initialize ( uri . get_schema ( ) , uri . get_host ( ) , uri . get_port ( ) ) ) ! = srs_success ) {
return srs_error_wrap ( err , " init uri=%s " , uri . get_url ( ) . c_str ( ) ) ;
return srs_error_wrap ( err , " init uri=%s " , uri . get_url ( ) . c_str ( ) ) ;