def handle(self, *args, **options): purchased = defaultdict(int) used = defaultdict(int) for row in fact_query.trailing_days(9): if row.get('metric') == 'shop_sticker_purchased': sticker = stickers.get(row.get('type_id')) if sticker.name not in purchased: purchased[sticker.name] = defaultdict(int) purchased[sticker.name]["quantity"] += 1 purchased[sticker.name]["total_spent"] += sticker.cost if row.get('metric') == 'shop_sticker_used': sticker = stickers.get(row.get('type_id')) if sticker.name not in used: used[sticker.name] = defaultdict(int) used[sticker.name]["quantity"] += 1 used[sticker.name]["total_spent"] += sticker.cost print "Purchased:", purchased print "Used:", used
def print_page_timings(): if settings.PROJECT == 'canvas': SLOW_PAGE_THRESHOLD = 9000 elif settings.PROJECT == 'drawquest': SLOW_PAGE_THRESHOLD = 5000 elapsed_times = [] elapsed_api_times = [] slow_pages = [] slow_apis = [] redis = [] sql = [] for row in fact_query.trailing_days(1): if row.get('metric') not in ('view', 'logged_out_view', 'api_call'): continue if 'sql' in row: sql.append(row['sql']) if 'redis' in row: redis.append(row['redis']) elapsed = row.get('e') if elapsed: if row.get('metric') == 'api_call': elapsed_api_times.append(elapsed) else: elapsed_times.append(elapsed) if elapsed > SLOW_PAGE_THRESHOLD: entry = (elapsed, row.get('path')) if row.get('metric') == 'api_call': if (settings.PROJECT == 'drawquest' and 'upload' in row.get('path') or 'activity_stream' in row.get('path')): continue slow_apis.append(entry) else: slow_pages.append(entry) slow_count = len(slow_pages) slow_api_count = len(slow_apis) if settings.PROJECT == 'canvas': print "SLOW PAGES" print "Slow count (>%s): %s" % (SLOW_PAGE_THRESHOLD, slow_count) if slow_count: print "Slow pages:" for elapsed, path in sorted(slow_pages, key=lambda x: int(x[0])): print "Slow page (%sms) %s" % (int(elapsed), path) print "Slow pages per hour", slow_count / 24.0 print print "Overall (pages)" stats.pp_percentiles(elapsed_times) print print "SLOW API CALLS" print "Slow count (>%s): %s" % (SLOW_PAGE_THRESHOLD, slow_api_count) if slow_api_count: print "Slow pages:" for elapsed, path in sorted(slow_apis, key=lambda x: int(x[0])): print "Slow page (%sms) %s" % (int(elapsed), path) print "Slow API calls per hour", slow_api_count / 24.0 print print "Overall (API calls)" stats.pp_percentiles(elapsed_api_times) print print "MySQL" print "Total Query Count:", sum(c[0] for c in sql) print "Total Query Time:", sum(c[1] for c in sql) // 1000, 's' print print "Redis" print "Total Command Count:", sum(c[0] for c in redis) print "Total Command Time:", sum(c[1] for c in redis) // 1000, 's' print
def print_page_timings(): if settings.PROJECT == 'canvas': SLOW_PAGE_THRESHOLD = 9000 elif settings.PROJECT == 'drawquest': SLOW_PAGE_THRESHOLD = 275 elapsed_times = [] elapsed_api_times = [] slow_pages = [] slow_apis = [] redis = [] sql = [] for row in fact_query.trailing_days(1): if row.get('metric') not in ('view', 'logged_out_view', 'api_call'): continue if 'sql' in row: sql.append(row['sql']) if 'redis' in row: redis.append(row['redis']) elapsed = row.get('e') if elapsed: if row.get('metric') == 'api_call': elapsed_api_times.append(elapsed) else: elapsed_times.append(elapsed) if elapsed > SLOW_PAGE_THRESHOLD: entry = (elapsed, row.get('path')) if row.get('metric') == 'api_call': if (settings.PROJECT == 'drawquest' and 'upload' in row.get('path') or 'activity_stream' in row.get('path')): continue slow_apis.append(entry) else: slow_pages.append(entry) slow_count = len(slow_pages) slow_api_count = len(slow_apis) if settings.PROJECT == 'canvas': print "SLOW PAGES" print "Slow count (>%s): %s" % (SLOW_PAGE_THRESHOLD, slow_count) if slow_count: print "Slow pages:" for elapsed, path in sorted(slow_pages, key=lambda x: int(x[0])): print "Slow page (%sms) %s" % (int(elapsed), path) print "Slow pages per hour", slow_count / 24.0 print print "Overall (pages)" stats.pp_percentiles(elapsed_times) print print "SLOW API CALLS" print "Slow count (>%s): %s" % (SLOW_PAGE_THRESHOLD, slow_api_count) if slow_api_count: print "Slow pages:" for elapsed, path in sorted(slow_apis, key=lambda x: int(x[0])): print "Slow page (%sms) %s" % (int(elapsed), path) print "Slow API calls per hour", slow_api_count / 24.0 print print "Overall (API calls)" stats.pp_percentiles(elapsed_api_times) print print "MySQL" print "Total Query Count:", sum(c[0] for c in sql) print "Total Query Time:", sum(c[1] for c in sql) // 1000, 's' print print "Redis" print "Total Command Count:", sum(c[0] for c in redis) print "Total Command Time:", sum(c[1] for c in redis) // 1000, 's' print
def trailing_days(cls, *args, **kwargs): obj = cls() obj.fact_iter = lambda: _wrapped_iter(fact_query.trailing_days(*args, **kwargs)) return obj