简体   繁体   English

AWS Cloudwatch PHP SDK返回未排序的指标统计信息

[英]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.

UPDATE UPDATE

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.

相关问题 如何通过PHP SDK访问AWS CloudWatch自定义指标 - How can I access AWS CloudWatch Custom Metrics via PHP SDK 适用于PHP的AWS开发工具包生成CloudWatch事件(putEvents)的示例 - Example for AWS SDK for PHP to generate CloudWatch event (putEvents) 什么是“私有 Amazon CloudWatch URL”?AWS SDK for PHP 是否需要 OpenSSL? - What are "private Amazon CloudWatch URLs" & do I need OpenSSL for the AWS SDK for PHP? aws php sdk返回内存数据的空数据点,该数据已从mon脚本perl放入cloudwatch - aws php sdk return empty datapoint for MemoryUtilization Metric that put in cloudwatch from mon script perl PHP-AWS CloudWatch Logs返回tooNewLogEventsStartIndex - PHP - AWS CloudWatch Logs return tooNewLogEventsStartIndex 带有CloudWatch的AWS上Symfony应用中的PHP日志目标 - PHP log target in Symfony app on AWS with CloudWatch AWS Elastic Beanstalk PHP 日志不在 CloudWatch 中 - AWS Elastic Beanstalk PHP logs not in CloudWatch 适用于PHP的AWS开发工具包示例吗? - AWS SDK for PHP Example? 如何阻止CognitoIdentityProviderException返回AWS PHP sdk中的500状态代码 - How stop CognitoIdentityProviderException from returning 500 status code in AWS PHP sdk 无法使用 PHP 登录 AWS Cloudwatch? - Can't able to log over AWS Cloudwatch using PHP?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM