Skip to content

Commit a445364

Browse files
authored
Cache and re-use generated snapshot (#165)
1 parent baee7df commit a445364

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

instana/meter.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ class Meter(object):
114114
# We send Snapshot data every 10 minutes. This is the countdown variable.
115115
snapshot_countdown = 0
116116

117+
# Collect the Snapshot only once and store the resulting Snapshot object here.
118+
# We use this for every repeated snapshot send (every 10 minutes)
119+
cached_snapshot = None
120+
117121
last_usage = None
118122
last_collect = None
119123
last_metrics = None
@@ -240,6 +244,9 @@ def handle_agent_tasks(self, task):
240244
def collect_snapshot(self):
241245
""" Collects snapshot related information to this process and environment """
242246
try:
247+
if self.cached_snapshot is not None:
248+
return self.cached_snapshot
249+
243250
if "INSTANA_SERVICE_NAME" in os.environ:
244251
appname = os.environ["INSTANA_SERVICE_NAME"]
245252
elif "FLASK_APP" in os.environ:
@@ -260,6 +267,9 @@ def collect_snapshot(self):
260267
djmw=self.djmw)
261268
s.version = sys.version
262269
s.versions = self.collect_modules()
270+
271+
# Cache the snapshot
272+
self.cached_snapshot = s
263273
except Exception as e:
264274
logger.debug(e.message)
265275
else:

0 commit comments

Comments
 (0)