Attempting to collect queries for 1% of requests by using DEBUG.

This commit is contained in:
Samuel Clay 2021-01-04 10:22:04 -05:00
parent b3b705dfe8
commit a5cac63a74
2 changed files with 9 additions and 1 deletions

View file

@ -45,12 +45,14 @@ class DBProfilerMiddleware:
random.random() < .01):
request.activated_segments.append('db_profiler')
connection.use_debug_cursor = True
settings.DEBUG = True
def process_celery(self):
setattr(self, 'activated_segments', [])
if random.random() < .01:
self.activated_segments.append('db_profiler')
connection.use_debug_cursor = True
settings.DEBUG = True
return self
def process_exception(self, request, exception):
@ -134,10 +136,14 @@ class SQLLogToConsoleMiddleware:
'redis': sum([float(q['time']) for q in queries if q.get('redis')]),
}
setattr(request, 'sql_times_elapsed', times_elapsed)
settings.DEBUG = False
return response
def process_celery(self, profiler):
self.process_response(profiler, None)
settings.DEBUG = False
SIMPSONS_QUOTES = [
("Homer", "D'oh."),

View file

@ -184,7 +184,7 @@ class MStatistics(mongo.Document):
cls.objects(key=key).update_one(upsert=True, set__key=key, set__value=value)
@classmethod
def collect_statistics_for_db(cls):
def collect_statistics_for_db(cls, debug=False):
lag = db_functions.mongo_max_replication_lag(settings.MONGODB)
cls.set('mongodb_replication_lag', lag)
@ -202,6 +202,8 @@ class MStatistics(mongo.Document):
for m in range(60):
minute = start_hours_ago + datetime.timedelta(minutes=m)
key = "DB:%s:%s" % (db, minute.strftime('%s'))
if debug:
print(" -> %s:c" % key)
pipe.get("%s:c" % key)
pipe.get("%s:t" % key)