简体   繁体   English

未使用的AWS预留实例中的问题

[英]Issue in Unused AWS Reserved Instances

In checking unutilized reserved instances, I retrieve those using python script from Github called ec2-check-reserved-instances . 在检查未使用的预留实例时,我从Github使用python脚本检索了名为ec2-check-reserved-instances的实例 It contains: 它包含:

            running_instances = {}
            for reservation in reservations:
            for instance in reservation.instances:
            if instance.state != "running":
                  sys.stderr.write("Disqualifying instance %s: not running\n" % ( instance.id ) )
            elif instance.spot_instance_request_id:
                sys.stderr.write("Disqualifying instance %s: spot\n" % ( instance.id ) )
            else:
                 **if instance.vpc_id:**
                       print "Does not support vpc yet, please be careful when trusting these results"
                else:
                      az = instance.placement
                      instance_type = instance.instance_type
                      running_instances[ (instance_type, az ) ] = running_instances.get( (instance_type, az ) , 0 ) + 1


   # pprint( running_instances )

It gives me running instances as empty and not reserved instance also empty, but printing unused reserved instances. 它使我正在运行的实例为空,而没有保留的实例也为空,但是输出未使用的保留实例。

When I use the same code without checking if instance.vpc_id , like this: 当我使用相同的代码而不检查if instance.vpc_id ,如下所示:

            running_instances = {}
            for reservation in reservations:
            for instance in reservation.instances:
            if instance.state != "running":
                sys.stderr.write("Disqualifying instance %s: not running\n" % ( instance.id ) )
            elif instance.spot_instance_request_id:
                   sys.stderr.write("Disqualifying instance %s: spot\n" % ( instance.id ) )
            else:
                 az = instance.placement
                 instance_type = instance.instance_type
                 running_instances[ (instance_type, az ) ] = running_instances.get( (instance_type, az ) , 0 ) + 1


           # pprint( running_instances )

It gives me a Running instances list and not created instances. 它给了我一个正在运行的实例列表,而不是创建的实例。 But it does not shows unused reserved instances. 但是它不会显示未使用的保留实例。 Just displays "you have no unused reserved instances". 仅显示“您没有未使用的保留实例”。

Why am I getting a different result when I am checking with and without instance.vpc_id ? 使用和不使用instance.vpc_id检查时,为什么会得到不同的结果? Which one is right? 哪一个是对的?

Actually it is checking out unutilized instances by comparing running and reserved instances part. 实际上,它是通过比较正在运行的实例和保留的实例部分来检查未使用的实例的。

Also what is meant by spot instances, why we have to ignore spot instances too? 竞价型实例又意味着什么,为什么我们也必须忽略竞价型实例?

I'm not going to go through the code (it is your choice to use that code), but I will explain a few concepts that might make things easier to understand. 我不会遍历代码(使用该代码是您的选择),但是我将解释一些概念,这些概念可能会使事情更容易理解。

An Amazon EC2 Reserved Instance is a pre-purchase of certain Amazon EC2 capacity. Amazon EC2预留实例是对某些Amazon EC2容量的预购买。 By purchasing the Reserved Instance, you are entitled to use a matching Amazon EC2 instance at no hourly cost (because the Reserved Instance is charged Annually or Monthly). 通过购买预留实例,您有权免费使用匹配的Amazon EC2实例(因为预留实例是按年或按月收费)。

There is no need to nominate which instance is 'reserved'. 无需指定“保留” 哪个实例。 Rather, the AWS billing system looks at the EC2 instances used every hour and compares it with purchased Reserved Instance capacity. 而是,AWS计费系统查看每小时使用的EC2实例,并将其与购买的预留实例容量进行比较。 If you own a Reserved Instance that matches an instance that was used, then there is no hourly charge for that instance. 如果您拥有与使用的实例匹配的预留实例,则该实例不收取小时费用。 The match is done by Instance Type, Operating System and optionally Availability Zone. 匹配由实例类型,操作系统和可选的可用区完成。

If you own one Reserved Instance but run two matching EC2 instances, only one EC2 instance for that hour is matched with the Reserved Instance. 如果您拥有一个预留实例但运行了两个匹配的EC2实例,则该小时内只有一个 EC2实例与预留实例匹配。 The other EC2 instance is charged at normal On-Demand rates. 另一个EC2实例按正常的按需计费。

Therefore, an unused Reserved Instance simply means that you have purchased Reserved Instance(s) and you are not currently running as many EC2 instances as the number of Reserved Instances. 因此, 未使用的预留实例仅表示您已购买了预留实例,并且当前运行的EC2实例数量不及预留实例的数量。 You could, therefore, run additional EC2 instances at no additional charge (since it has been pre-paid via a Reserved Instance). 因此,您可以免费运行其他EC2实例(因为它已通过预留实例预付费)。

Amazon EC2 instances launched as Spot Instances have their own pricing method, based upon the current Spot Price for the instance based on its Instance Type and Availability Zone. 推出, 现货实例的Amazon EC2实例有自己的定价方法,基于当前现货价格基础上的实例类型和可用区的实例。 Spot Instances will never consume Reserved Instance capacity, so they should be excluded from any calculation of "unused" Reserved Instances. 竞价型实例将永远不会消耗预留实例的容量,因此应将它们从“未使用的”预留实例的任何计算中排除。

Similarly, an EC2 instance that is not running should also be ignored for calculating unused Reserved Instances. 同样,在计算未使用的预留实例时,也应忽略未运行的EC2实例。

As to the instance.vpc_id line in the script, it appears that this script was written in 2012 and does not correctly handle situations where an Amazon EC2 instance is launched into an Amazon VPC. 至于脚本中的instance.vpc_id行,该脚本似乎写于2012年,无法正确处理将Amazon EC2实例启动到Amazon VPC中的情况。 These days, the default is to use an Amazon VPC so I would not recommend using this script since it is out-of-date and does not handle this use-case. 这些天,默认设置是使用Amazon VPC,所以我不建议您使用此脚本,因为它已过期并且无法处理此用例。

Instead, I would recommend using Reserved Instance Utilization Reports provided within the AWS Management Console, which can provide the information you seek: 相反,我建议使用AWS管理控制台中提供的预留实例利用率报告 ,该报告可以提供您要查找的信息:

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM