def evaluate_and_store_stat(name, stat): """Evaluates whether the given statistic is to be recorded and if so, records it.""" global filters summary = stats.stats_summary() if not summary: return try: f = filters[stat.filter] except KeyError: l.critical("Filter %s not registered", stat.filter) raise try: if f(**stat): l.debug("Storing stat %s", name) if stat.has_key("time"): graphite_stats.put(name, summary[stat.time]["time"] * 100) elif stat.has_key("count"): print "Storing count for key %s" % stat.count else: l.warning("No storage item specified for stat %s", name) except Exception, k: l.warning( "Error while storing stats (%s). Complete traceback follows" % k) l.warning(traceback.format_exc())
def stats_hook(): """web.py unload hook to add X-OL-Stats header. This info can be written to lighttpd access log for collecting """ try: if "stats-header" in web.ctx.features: web.header("X-OL-Stats", format_stats(stats.stats_summary())) except Exception, e: # don't let errors in stats collection break the app. print >> web.debug, str(e)
def stats_hook(): """web.py unload hook to add X-OL-Stats header. This info can be written to lighttpd access log for collecting Also, send stats to graphite using statsd """ update_all_stats() stats_summary = stats.stats_summary() try: if "stats-header" in web.ctx.features: web.header("X-OL-Stats", format_stats(stats_summary)) except Exception, e: # don't let errors in stats collection break the app. print >> web.debug, str(e)
def stats_hook(): """web.py unload hook to add X-OL-Stats header. This info can be written to lighttpd access log for collecting Also, send stats to graphite using statsd """ stats_summary = stats.stats_summary() update_all_stats(stats_summary) try: if "stats-header" in web.ctx.features: web.header("X-OL-Stats", format_stats(stats_summary)) except Exception as e: # don't let errors in stats collection break the app. print(str(e), file=web.debug) # This name is misleading. It gets incremented for more than just pages. # E.g. *.json requests (even ajax), image requests. Although I can't # see any *.js requests? So not sure exactly when we're called here. graphite_stats.increment('ol.pageviews') memcache_hits = 0 memcache_misses = 0 for s in web.ctx.get("stats", []): if s.name == 'memcache.get': if s.data['hit']: memcache_hits += 1 else: memcache_misses += 1 if memcache_hits: graphite_stats.increment('ol.memcache.hits', memcache_hits, rate=0.025) if memcache_misses: graphite_stats.increment('ol.memcache.misses', memcache_misses, rate=0.025) for name, value in stats_summary.items(): name = name.replace(".", "_") time = value.get("time", 0.0) * 1000 key = 'ol.' + name graphite_stats.put(key, time)
def readlinks(req, options): try: dbstr = 'debug|' if req.startswith(dbstr): options = { 'stats': True, 'show_exception': True, 'no_data': True, 'no_details': True, 'show_all_items': True } req = req[len(dbstr):] rp = ReadProcessor(options) if options.get('listofworks'): """ For load-testing, handle a special syntax """ wids = req.split('|') mapping = get_eids_for_wids(wids[:5]) req = '|'.join(('olid:' + k) for k in mapping.values()) result = rp.process(req) if options.get('stats'): summary = stats.stats_summary() s = {} result['stats'] = s s['summary'] = summary s['stats'] = web.ctx.get('stats', []) except: print >> sys.stderr, 'Error in processing Read API' if options.get('show_exception'): register_exception() result = {'success': False} else: register_exception() result = {} return result
def stats_hook(): """web.py unload hook to add X-OL-Stats header. This info can be written to lighttpd access log for collecting Also, send stats to graphite using statsd """ stats_summary = stats.stats_summary() update_all_stats(stats_summary) try: if "stats-header" in web.ctx.features: web.header("X-OL-Stats", format_stats(stats_summary)) except Exception as e: # don't let errors in stats collection break the app. print(str(e), file=web.debug) openlibrary.core.stats.increment('ol.pageviews') memcache_hits = 0 memcache_misses = 0 for s in web.ctx.get("stats", []): if s.name == 'memcache.get': if s.data['hit']: memcache_hits += 1 else: memcache_misses += 1 if memcache_hits: openlibrary.core.stats.increment('ol.memcache.hits', memcache_hits) if memcache_misses: openlibrary.core.stats.increment('ol.memcache.misses', memcache_misses) for name, value in stats_summary.items(): name = name.replace(".", "_") time = value.get("time", 0.0) * 1000 key = 'ol.'+name openlibrary.core.stats.put(key, time)
def evaluate_and_store_stat(name, stat): """Evaluates whether the given statistic is to be recorded and if so, records it.""" global filters summary = stats.stats_summary() if not summary: return try: f = filters[stat.filter] except KeyError: l.critical("Filter %s not registered", stat.filter) raise try: if f(**stat): l.debug("Storing stat %s", name) if stat.has_key("time"): graphite_stats.put(name, summary[stat.time]["time"] * 100) elif stat.has_key("count"): print "Storing count for key %s"%stat.count else: l.warning("No storage item specified for stat %s", name) except Exception, k: l.warning("Error while storing stats (%s). Complete traceback follows"%k) l.warning(traceback.format_exc())