Skip to content

Instantly share code, notes, and snippets.

@elephantum
Created October 25, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elephantum/134a257f0e2392ed51f4 to your computer and use it in GitHub Desktop.
Save elephantum/134a257f0e2392ed51f4 to your computer and use it in GitHub Desktop.
def prepare_data(data):
data['service'] = None
data['service'][data['upstream_addr'] == '-'] = 'static'
data['service'][data['upstream_addr'] == '127.0.0.1:4091'] = 'backend'
data['service'][data['upstream_addr'] == '127.0.0.1:4092'] = 'screenshot'
data['service'][data['upstream_addr'] == '127.0.0.1:9000'] = 'frontend'
data['request_time_xx'] = '-'
data['request_time_xx'][data['request_time'].between(0, 0.5)] = '0-500ms'
data['request_time_xx'][data['request_time'].between(0.5, 1)] = '500ms-1s'
data['request_time_xx'][data['request_time'] > 1] = '1s-inf'
data['status_xx'] = '-'
data['status_xx'][data['status'].between(100,199)] = '1xx'
data['status_xx'][data['status'].between(200,299)] = '2xx'
data['status_xx'][data['status'].between(300,399)] = '3xx'
data['status_xx'][data['status'].between(400,499)] = '4xx'
data['status_xx'][data['status'].between(500,599)] = '5xx'
data['domain'] = 'custom'
data['domain'][data['http_host'] == 'readymag.com'] = 'readymag'
data['domain'][data['http_host'] == 'embed.readymag.com'] = 'readymag'
data['domain'][data['http_host'] == 'readymag.local'] = 'readymag'
data['domain'][data['http_host'].str.endswith(':8080')] = 'readymag'
return data
def aggregate_data():
aggregate_qps('total', data.groupby([lambda x: 'total']))
aggregate_latency('total', data.groupby([lambda x: 'total']))
aggregate_qps('total.latency_xx.{1}', data.groupby([lambda x: 'total', 'request_time_xx']))
aggregate_qps('total.status_xx.{1}', data.groupby([lambda x: 'total', 'status_xx']))
aggregate_qps('total.cache_status.{1}', data.groupby([lambda x: 'total', 'upstream_cache_status']))
aggregate_qps('service.{0}', data.groupby(['service']))
aggregate_latency('service.{0}', data.groupby(['service']))
aggregate_qps('service.{0}.cache_status.{1}', data.groupby(['service', 'upstream_cache_status']))
aggregate_qps('service.{0}.latency_xx.{1}', data.groupby(['service', 'request_time_xx']))
aggregate_qps('domain.{0}', data.groupby(['domain']))
aggregate_latency('domain.{0}', data.groupby(['domain']))
aggregate_qps('domain.{0}.latency_xx.{1}', data.groupby(['domain', 'request_time_xx']))
aggregate_qps('domain.{0}.cache_status.{1}', data.groupby(['domain', 'upstream_cache_status']))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment