<s> import re <EOL> import time <EOL> import base <EOL> import stats <EOL> from models . polling_stat import PollingStat <EOL> PAT_HOST = re . compile ( '<STR_LIT>' ) <EOL> REDIS_MAX_FIELDS = [ <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> ] <EOL> REDIS_AVG_FIELDS = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> PROXY_MAX_FIELDS = [ '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> PROXY_AVG_FIELDS = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> @ base . get ( '<STR_LIT>' ) <EOL> def pollings ( request ) : <EOL> return request . render ( '<STR_LIT>' , pollings = PollingStat . query . order_by ( <EOL> PollingStat . id . desc ( ) ) . limit ( <NUM_LIT> ) ) <EOL> if stats . client is not None : <EOL> @ base . get ( '<STR_LIT>' ) <EOL> def stats_redis_entry_page ( request ) : <EOL> return request . render ( '<STR_LIT>' , host = request . args [ '<STR_LIT:host>' ] , <EOL> port = int ( request . args [ '<STR_LIT:port>' ] ) ) <EOL> @ base . get ( '<STR_LIT>' ) <EOL> def stats_proxy_entry_page ( request ) : <EOL> return request . render ( '<STR_LIT>' , host = request . args [ '<STR_LIT:host>' ] , <EOL> port = int ( request . args [ '<STR_LIT:port>' ] ) ) <EOL> def _parse_args ( args ) : <EOL> host = args [ '<STR_LIT:host>' ] <EOL> if not PAT_HOST . match ( host ) : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> port = int ( args [ '<STR_LIT:port>' ] ) <EOL> limit = min ( int ( args . get ( '<STR_LIT>' , <NUM_LIT:100> ) ) , <NUM_LIT> ) <EOL> interval = max ( int ( args . get ( '<STR_LIT>' , <NUM_LIT:8> ) ) , <NUM_LIT:8> ) <EOL> return host , port , limit , interval , limit * interval * <NUM_LIT> <EOL> @ base . get_async ( '<STR_LIT>' ) <EOL> def fetch_proxy_stats ( request ) : <EOL> host , port , limit , interval , span = _parse_args ( request . args ) <EOL> now = int ( time . time ( ) ) <EOL> node = '<STR_LIT>' % ( host , port ) <EOL> result = { } <EOL> for field in PROXY_MAX_FIELDS : <EOL> result [ field ] = stats . client . query ( <EOL> node , field , '<STR_LIT>' , span , now , interval ) <EOL> for field in PROXY_AVG_FIELDS : <EOL> result [ field ] = stats . client . query ( <EOL> node , field , '<STR_LIT>' , span , now , interval ) <EOL> return base . json_result ( result ) <EOL> @ base . get_async ( '<STR_LIT>' ) <EOL> def fetch_stats ( request ) : <EOL> host , port , limit , interval , span = _parse_args ( request . args ) <EOL> now = int ( time . time ( ) ) <EOL> node = '<STR_LIT>' % ( host , port ) <EOL> result = { } <EOL> for field in REDIS_AVG_FIELDS : <EOL> result [ field ] = stats . client . query ( <EOL> node , field , '<STR_LIT>' , span , now , interval ) <EOL> for field in REDIS_MAX_FIELDS : <EOL> result [ field ] = stats . client . query ( <EOL> node , field , '<STR_LIT>' , span , now , interval ) <EOL> return base . json_result ( result ) </s>
