Skip to content

Commit 684d74b

Browse files
authored
Merge pull request #37 from instana/drop-psutil
Remove psutil dependency
2 parents 737ef80 + b2a3190 commit 684d74b

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

instana/fsm.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import subprocess
22
import os
3-
import psutil
3+
import sys
44
import socket
55
import threading as t
66
import fysom as f
@@ -107,18 +107,26 @@ def check_host(self, host):
107107

108108
def announce_sensor(self, e):
109109
l.debug("announcing sensor to the agent")
110-
p = psutil.Process(os.getpid())
111110
s = None
111+
pid = os.getpid()
112112

113-
d = Discovery(pid=p.pid,
114-
name=p.cmdline()[0],
115-
args=p.cmdline()[1:])
113+
if os.path.isfile("/proc/self/cmdline"):
114+
with open("/proc/self/cmdline") as cmd:
115+
cmdinfo = cmd.read()
116+
cmdline = cmdinfo.split('\x00')
117+
else:
118+
cmdline = [os.path.basename(sys.executable)]
119+
cmdline += sys.argv
120+
121+
d = Discovery(pid=pid,
122+
name=cmdline[0],
123+
args=cmdline[1:])
116124

117125
# If we're on a system with a procfs
118126
if os.path.exists("/proc/"):
119127
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
120128
s.connect((self.agent.host, 42699))
121-
path = "/proc/%d/fd/%d" % (p.pid, s.fileno())
129+
path = "/proc/%d/fd/%d" % (pid, s.fileno())
122130
d.fd = s.fileno()
123131
d.inode = os.readlink(path)
124132

@@ -127,7 +135,7 @@ def announce_sensor(self, e):
127135
if b:
128136
self.agent.set_from(b)
129137
self.fsm.ready()
130-
l.warn("Host agent available. We're in business. Announced pid: %i (true pid: %i)" % (p.pid, self.agent.from_.pid))
138+
l.warn("Host agent available. We're in business. Announced pid: %i (true pid: %i)" % (pid, self.agent.from_.pid))
131139
return True
132140
else:
133141
l.warn("Cannot announce sensor. Scheduling retry.")

requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@ nose>=1.0
22
fysom>=2.1.2
33
opentracing>=1.2.1
44
basictracer>=2.2.0
5-
psutil>=5.1.3
65
autowrapt>=1.0

setup.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
install_requires=['autowrapt>=1.0',
1616
'fysom>=2.1.2',
1717
'opentracing>=1.2.1,<1.3',
18-
'basictracer>=2.2.0',
19-
'psutil>=5.1.3'],
18+
'basictracer>=2.2.0'],
2019
entry_points={'django': ['django.core.handlers.base = instana.django:hook'],
2120
'django19': ['django.core.handlers.base = instana.django19:hook'],
2221
'flask': ['flask = instana.flaskana:hook'],

0 commit comments

Comments
 (0)