Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions instana/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
16 changes: 13 additions & 3 deletions instana/fsm.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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"),
Expand All @@ -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()

Expand Down Expand Up @@ -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:
Expand Down