[英]AWS Cloudwatch PHP SDK returning unsorted metrics statistics
I am currently extracting CloudWatch metrics statistics with the aws php sdk. 我目前正在使用aws php sdk提取CloudWatch指标统计信息。
Unfortunately the getMetricStatistics method is returning unsorted results. 不幸的是,getMetricStatistics方法返回未排序的结果。 I wonder why it is not sorted by Timestamp ASC.
我想知道为什么它不是按时间戳ASC排序的。 Does anyone know how to get sorted results from Cloudwatch?
有谁知道如何从Cloudwatch获得排序结果?
my code 我的代码
$result = $this->client->getMetricStatistics(array(
'Namespace' => 'My.Namespace',
'MetricName' => 'my-metric',
'StartTime' => strtotime('-1 days'),
'EndTime' => strtotime('now'),
'Period' => 300,
'Statistics' => array('Average'),
));
and the result 和结果
array (size=7)
0 =>
array (size=3)
'Timestamp' => string '2014-04-16T10:53:00Z' (length=20)
'Unit' => string 'Count' (length=5)
'Average' => string '9.998594711316002' (length=17)
1 =>
array (size=3)
'Timestamp' => string '2014-04-16T11:43:00Z' (length=20)
'Unit' => string 'Count' (length=5)
'Average' => string '0.7908148450858722' (length=18)
2 =>
array (size=3)
'Timestamp' => string '2014-04-16T11:08:00Z' (length=20)
'Unit' => string 'Count' (length=5)
'Average' => string '5.402251656252796' (length=17)
3 =>
array (size=3)
'Timestamp' => string '2014-04-16T11:03:00Z' (length=20)
'Unit' => string 'Count' (length=5)
'Average' => string '8.958888493053081' (length=17)
Thanks for your help! 谢谢你的帮助!
J. J.
I still did not manage to get sorted results directly from the method call. 我仍然没有设法直接从方法调用中获得排序结果。 So I used usort as suggested by @Svenskunganka
所以我按照@Svenskunganka的建议使用了usort
usort($result['Datapoints'], function($a, $b) {
if($a['Timestamp'] == $b['Timestamp']) {
return 0;
}
return ($a['Timestamp'] < $b['Timestamp']) ? -1 : 1;
});
I am still looking for the perfect way to get sorted results. 我仍在寻找获得排序结果的完美方法。 If anyone has a clue, I would be really thankful.
如果有人有线索,我将非常感激。
There is no way to get sorted results from GetMetricStatistics, you have to sort the datapoints yourself. 无法从GetMetricStatistics获取排序结果,您必须自己对数据点进行排序。
"GetMetricStatistics does not return the data in chronological order."
“ GetMetricStatistics不会按时间顺序返回数据。”
Source: http://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_GetMetricStatistics.html
资料来源: http : //docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_GetMetricStatistics.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.