@@ -67,22 +67,32 @@ def start_metric_reporting(self, e):
6767 self .agent .sensor .meter .run ()
6868
6969 def lookup_agent_host (self , e ):
70- if self .agent .sensor .options .agent_host != "" :
70+ host = a .AGENT_DEFAULT_HOST
71+ port = a .AGENT_DEFAULT_PORT
72+
73+ if "INSTANA_AGENT_IP" in os .environ :
74+ host = os .environ ["INSTANA_AGENT_IP" ]
75+ if "INSTANA_AGENT_PORT" in os .environ :
76+ port = int (os .environ ["INSTANA_AGENT_PORT" ])
77+
78+ elif self .agent .sensor .options .agent_host != "" :
7179 host = self .agent .sensor .options .agent_host
72- else :
73- host = a . AGENT_DEFAULT_HOST
80+ if self . agent . sensor . options . agent_port != 0 :
81+ port = self . agent . sensor . options . agent_port
7482
75- h = self .check_host (host )
83+ h = self .check_host (host , port )
7684 if h == a .AGENT_HEADER :
7785 self .agent .set_host (host )
86+ self .agent .set_port (port )
7887 self .fsm .announce ()
7988 return True
8089 elif os .path .exists ("/proc/" ):
8190 host = self .get_default_gateway ()
8291 if host :
83- h = self .check_host (host )
92+ h = self .check_host (host , port )
8493 if h == a .AGENT_HEADER :
8594 self .agent .set_host (host )
95+ self .agent .set_port (port )
8696 self .fsm .announce ()
8797 return True
8898
@@ -105,8 +115,8 @@ def get_default_gateway(self):
105115
106116 return None
107117
108- def check_host (self , host ):
109- log .debug ("checking host" , host )
118+ def check_host (self , host , port ):
119+ log .debug ("checking %s:%d" % ( host , port ) )
110120
111121 (_ , h ) = self .agent .request_header (
112122 self .agent .make_host_url (host , "/" ), "GET" , "Server" )
0 commit comments