def get_history(targets, start='-1h', end='now'):
"""Retrieve the time series data for one or more metrics.
Args:
targets (str|List[str]): Graphite path, or list of paths.
start (Optional[str]): Start of date range. Defaults to one hour ago.
end (Optional[str]): End of date range. Defaults to now.
Returns:
A list of metric values.
"""
metrics = query(targets, start, end)
try:
metrics = json.loads(metrics)[0]['datapoints']
except:
return []
# Convert unix timestamps to plot.ly's required date format
for metric in metrics:
timestamp = datetime.fromtimestamp(metric[1])
metric[1] = timestamp.strftime('%Y-%m-%d %H:%M:%S')
return metrics
评论列表
文章目录