本文整理汇总了Python中target.Target.get_agg_key方法的典型用法代码示例。如果您正苦于以下问题:Python Target.get_agg_key方法的具体用法?Python Target.get_agg_key怎么用?Python Target.get_agg_key使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类target.Target
的用法示例。
在下文中一共展示了Target.get_agg_key方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_agg_key
# 需要导入模块: from target import Target [as 别名]
# 或者: from target.Target import get_agg_key [as 别名]
def test_agg_key():
t = Target({
'variables': {
'foo': 'bar',
'target_type': 'rate',
'region': 'us-east-1'
}})
# catchall bucket
assert t.get_agg_key({'foo': ['']}) == 'foo:__region=us-east-1,target_type=rate'
# non catchall bucket
assert t.get_agg_key({'foo': ['ba', ''], 'bar': ['']}) == 'foo:ba__region=us-east-1,target_type=rate'
struct = {
'n3': ['bucketmatch1', 'bucketmatch2'],
'othertag': ['']
}
# none of the structs applies
assert t.get_agg_key(struct) == '__foo=bar,region=us-east-1,target_type=rate'
struct = {
'target_type': [''],
'region': ['us-east', 'us-west', '']
}
# one catchall, the other matches
assert t.get_agg_key(struct) == 'region:us-east,target_type:__foo=bar'
示例2: build_graphs_from_targets
# 需要导入模块: from target import Target [as 别名]
# 或者: from target.Target import get_agg_key [as 别名]
def build_graphs_from_targets(targets, query):
graphs = {}
if not targets:
return (graphs, query)
group_by = query['group_by']
sum_by = query['sum_by']
avg_by = query['avg_by']
avg_over = query['avg_over']
# i'm gonna assume you never use second and your datapoints are stored with
# minutely resolution. later on we can use config options for this (or
# better: somehow query graphite about it)
# note, the day/week/month numbers are not technically accurate, but
# since we're doing movingAvg that's ok
averaging = {
'M': 1,
'h': 60,
'd': 60 * 24,
'w': 60 * 24 * 7,
'mo': 60 * 24 * 30
}
if avg_over is not None:
avg_over_amount = avg_over[0]
avg_over_unit = avg_over[1]
if avg_over_unit in averaging.keys():
multiplier = averaging[avg_over_unit]
query['target_modifiers'].append(
Query.graphite_function_applier('movingAverage', avg_over_amount * multiplier))
# for each group_by bucket, make 1 graph.
# so for each graph, we have:
# the "constants": tags in the group_by
# the "variables": tags not in the group_by, which can have arbitrary
# values, or different values from a group_by tag that match the same
# bucket pattern
# go through all targets and group them into graphs:
for _target_id, target_data in sorted(targets.items()):
# FWIW. has an 'id' which timeserieswidget doesn't care about
target = Target(target_data)
target['target'] = target['id']
(graph_key, constants) = target.get_graph_info(group_by)
if graph_key not in graphs:
graph = {'from': query['from'], 'until': query['to']}
graph.update({'constants': constants, 'targets': []})
graphs[graph_key] = graph
graphs[graph_key]['targets'].append(target)
# ok so now we have a graphs dictionary with a graph for every appropriate
# combination of group_by tags, and each graph contains all targets that
# should be shown on it. but the user may have asked to aggregate certain
# targets together, by summing and/or averaging across different values of
# (a) certain tag(s). let's process the aggregations now.
if (sum_by or avg_by):
for (graph_key, graph_config) in graphs.items():
graph_config['targets_sum_candidates'] = {}
graph_config['targets_avg_candidates'] = {}
graph_config['normal_targets'] = []
for target in graph_config['targets']:
sum_id = target.get_agg_key(sum_by)
if sum_id:
if sum_id not in graph_config['targets_sum_candidates']:
graphs[graph_key]['targets_sum_candidates'][sum_id] = []
graph_config['targets_sum_candidates'][sum_id].append(target)
for (sum_id, targets) in graph_config['targets_sum_candidates'].items():
if len(targets) > 1:
for t in targets:
graph_config['targets'].remove(t)
graph_config['targets'].append(
graphite_func_aggregate(targets, sum_by, "sumSeries"))
for target in graph_config['targets']:
# Now that any summing is done, we look at aggregating by
# averaging because avg(foo+bar+baz) is more efficient
# than avg(foo)+avg(bar)+avg(baz)
# aggregate targets (whether those are sums or regular ones)
avg_id = target.get_agg_key(avg_by)
if avg_id:
if avg_id not in graph_config['targets_avg_candidates']:
graph_config['targets_avg_candidates'][avg_id] = []
graph_config['targets_avg_candidates'][avg_id].append(target)
for (avg_id, targets) in graph_config['targets_avg_candidates'].items():
if len(targets) > 1:
for t in targets:
graph_config['targets'].remove(t)
graph_config['targets'].append(
graphite_func_aggregate(targets, avg_by, "averageSeries"))
# remove targets/graphs over the limit
graphs = graphs_limit_targets(graphs, query['limit_targets'])
# Apply target modifiers (like movingAverage, summarize, ...)
for (graph_key, graph_config) in graphs.items():
for target in graph_config['targets']:
for target_modifier in query['target_modifiers']:
target_modifier(target, graph_config)
# if in a graph all targets have a tag with the same value, they are
#.........这里部分代码省略.........