diff --git a/instana/agent.py b/instana/agent.py index f4d1571e..cb84c38c 100644 --- a/instana/agent.py +++ b/instana/agent.py @@ -35,14 +35,13 @@ class Agent(object): host = a.AGENT_DEFAULT_HOST port = a.AGENT_DEFAULT_PORT fsm = None - from_ = None + from_ = From() def __init__(self, sensor): log.debug("initializing agent") self.sensor = sensor self.fsm = f.Fsm(self) - self.reset() def to_json(self, o): try: diff --git a/instana/fsm.py b/instana/fsm.py index 85cd38ad..dc2fa706 100644 --- a/instana/fsm.py +++ b/instana/fsm.py @@ -1,7 +1,7 @@ -import subprocess -import os import sys +import os import socket +import subprocess import threading as t import fysom as f from instana import log @@ -41,7 +41,7 @@ def __init__(self, agent): self.agent = agent self.fsm = f.Fysom({ - "initial": "lostandalone", + "initial": {'state': "lostandalone", 'event': 'init', 'defer': True}, "events": [ ("startup", "*", "lostandalone"), ("lookup", "lostandalone", "found"), @@ -52,10 +52,19 @@ def __init__(self, agent): "onannounce": self.announce_sensor, "onchangestate": self.printstatechange}}) + timer = t.Timer(2, self.boot) + timer.daemon = True + timer.name = "Startup" + timer.start() + def printstatechange(self, e): log.debug('========= (%i#%s) FSM event: %s, src: %s, dst: %s ==========' % (os.getpid(), t.current_thread().name, e.event, e.src, e.dst)) + def boot(self): + self.fsm.init() + self.fsm.lookup() + def reset(self): self.fsm.lookup() @@ -110,6 +119,7 @@ def announce_sensor(self, e): log.debug("announcing sensor to the agent") s = None pid = os.getpid() + cmdline = [] if os.path.isfile("/proc/self/cmdline"): with open("/proc/self/cmdline") as cmd: