Skip to content

Commit

Permalink
Merge pull request #37 from instana/drop-psutil
Browse files Browse the repository at this point in the history
Remove psutil dependency
  • Loading branch information
pglombardo authored Dec 8, 2017
2 parents 737ef80 + b2a3190 commit 684d74b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
22 changes: 15 additions & 7 deletions instana/fsm.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import subprocess
import os
import psutil
import sys
import socket
import threading as t
import fysom as f
Expand Down Expand Up @@ -107,18 +107,26 @@ def check_host(self, host):

def announce_sensor(self, e):
l.debug("announcing sensor to the agent")
p = psutil.Process(os.getpid())
s = None
pid = os.getpid()

d = Discovery(pid=p.pid,
name=p.cmdline()[0],
args=p.cmdline()[1:])
if os.path.isfile("/proc/self/cmdline"):
with open("/proc/self/cmdline") as cmd:
cmdinfo = cmd.read()
cmdline = cmdinfo.split('\x00')
else:
cmdline = [os.path.basename(sys.executable)]
cmdline += sys.argv

d = Discovery(pid=pid,
name=cmdline[0],
args=cmdline[1:])

# If we're on a system with a procfs
if os.path.exists("/proc/"):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((self.agent.host, 42699))
path = "/proc/%d/fd/%d" % (p.pid, s.fileno())
path = "/proc/%d/fd/%d" % (pid, s.fileno())
d.fd = s.fileno()
d.inode = os.readlink(path)

Expand All @@ -127,7 +135,7 @@ def announce_sensor(self, e):
if b:
self.agent.set_from(b)
self.fsm.ready()
l.warn("Host agent available. We're in business. Announced pid: %i (true pid: %i)" % (p.pid, self.agent.from_.pid))
l.warn("Host agent available. We're in business. Announced pid: %i (true pid: %i)" % (pid, self.agent.from_.pid))
return True
else:
l.warn("Cannot announce sensor. Scheduling retry.")
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ nose>=1.0
fysom>=2.1.2
opentracing>=1.2.1
basictracer>=2.2.0
psutil>=5.1.3
autowrapt>=1.0
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
install_requires=['autowrapt>=1.0',
'fysom>=2.1.2',
'opentracing>=1.2.1,<1.3',
'basictracer>=2.2.0',
'psutil>=5.1.3'],
'basictracer>=2.2.0'],
entry_points={'django': ['django.core.handlers.base = instana.django:hook'],
'django19': ['django.core.handlers.base = instana.django19:hook'],
'flask': ['flask = instana.flaskana:hook'],
Expand Down

0 comments on commit 684d74b

Please sign in to comment.