mirror of
https://github.com/viq/NewsBlur.git
synced 2025-04-13 09:38:09 +00:00
Attempting to collect queries for 1% of requests by using DEBUG.
This commit is contained in:
parent
b3b705dfe8
commit
a5cac63a74
2 changed files with 9 additions and 1 deletions
|
@ -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."),
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue