Skip to content

Commit 440ec9e

Browse files
committed
Use a dedicated metric collection thread.
1 parent 15a5f24 commit 440ec9e

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

instana/meter.py

+12-8
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import sys
77
import instana.agent_const as a
88
import copy
9+
import time
910

1011

1112
class Snapshot(object):
@@ -96,13 +97,18 @@ class Meter(object):
9697

9798
def __init__(self, sensor):
9899
self.sensor = sensor
99-
self.tick()
100+
self.run()
100101

101-
def tick(self):
102-
timer = t.Timer(1, self.process)
103-
timer.daemon = True
104-
timer.name = "Instana Metric Collection"
105-
timer.start()
102+
def run(self):
103+
self.timer = t.Thread(target=self.collect_and_report)
104+
self.timer.daemon = True
105+
self.timer.name = "Instana Metric Collection"
106+
self.timer.start()
107+
108+
def collect_and_report(self):
109+
while 1:
110+
self.process()
111+
time.sleep(1)
106112

107113
def process(self):
108114
if self.sensor.agent.can_send():
@@ -121,8 +127,6 @@ def process(self):
121127
self.sensor.agent.make_url(a.AGENT_DATA_URL), "POST", d)
122128
self.last_metrics = cm.__dict__
123129

124-
self.tick()
125-
126130
def collect_snapshot(self):
127131
try:
128132
s = Snapshot(name=self.sensor.service_name,

0 commit comments

Comments
 (0)