获取 AWS 实例的运行时间 [英] Getting running time for an AWS instance

查看:24
本文介绍了获取 AWS 实例的运行时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 PHP AWS 开发工具包来获取我账户中所有正在运行的实例.我使用了以下 API:

I am using the PHP AWS SDK for getting all the running instances in my account. I used the following API:

$this->ec2Client = Ec2Client::factory(array(
            'profile' => AWS_PROFILE, //contains my credentials
            'region' => 'ap-northeast-1',
            'version' => 'latest',
        ));

$result = $this->ec2Client->DescribeInstances(array(
            'Filters' => array(
                array('Name' => 'instance-state-name', 'Values' => array('running')),
            )
        ));

我可以通过 LaunchTimeAvailabilityZone 信息获取所有正在运行的实例.

I can get all the running instances with the LaunchTimeand the AvailabilityZone information.

它们的值分别是 2014-10-31T10:58:35+00:00ap-northeast-1a.

The values for them are 2014-10-31T10:58:35+00:00 and ap-northeast-1a respectively.

根据这些信息,我想以分钟为单位计算运行时间.这样做的正确方法是什么?

Based on this information, I want to calculate the running time in minutes. What is the correct way to do this?

推荐答案

我在 v3 中使用以下解决方案:

I solved it using the following in v3:

function interval_in_minutes($start_time){
        return round(abs($start_time->getTimestamp() -
            (new \DateTime)->getTimestamp()) / 60);
    }

$running_time = interval_in_minutes($instance["LaunchTime"]);

这篇关于获取 AWS 实例的运行时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆