如何通过API获取AWS VCPU的利用率数

发布于 2025-01-17 04:58:43 字数 350 浏览 3 评论 0原文

我想通过 GO API 获取该区域中所有正在运行的实例使用的 AWS VCPU 数量,这样我可以在创建新实例之前运行一些预检检查,以查看是否有足够的 VCPU 可用,而无需增加配额。

换句话说,如果我们查看控制台,我们可以看到运行按需标准(A、C、D、H、I、M、R、T、Z)实例服务配额,显示已应用配额值列,指示当前 VCPU 的限制。如果单击此字段,您可以看到“利用率”字段,其中显示已使用的 VCPU。这就是我所需要的。

AWS 服务配额 - 运行按需标准实例

谢谢!

I would like to get the number of AWS VCPU's used by all running instances in the region via GO API, so I can run some preflight checks before I create new instances, to see if there are enough VCPU's available, without increasing the quota.

In other words, if we look at the console we can see that Running On-Demand Standard (A, C, D, H, I, M, R, T, Z) instances service quota, shows Applied quota value column that indicates the current VCPU's limit. If you click on this field, you can see the 'Utilization' field that shows the used VCPU's. This is what I need.

AWS Service Quotas - Running On-Demand Standard instances

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

深爱成瘾 2025-01-24 04:58:43

为了了解此信息的可用位置,我研究了服务配额 AWS 服务。

aws service-quotas list-service 命令列出服务代码,例如:

{
    "Services": [
        {
            "ServiceCode": "AWSCloudMap",
            "ServiceName": "AWS Cloud Map"
        },
        ...
        {
            "ServiceCode": "ec2",
            "ServiceName": "Amazon Elastic Compute Cloud (Amazon EC2)"
        },
        ...
        {
            "ServiceCode": "xray",
            "ServiceName": "AWS X-Ray"
        }
    ]
}

因此,Amazon EC2 的服务代码是 ec2

接下来,我使用 aws service-quotas list-service-quotas --service-code ec2 列出了该服务的配额。在我发现的输出中:

{
    "Quotas": [
    ...
        {
            "ServiceCode": "ec2",
            "ServiceName": "Amazon Elastic Compute Cloud (Amazon EC2)",
            "QuotaArn": "arn:aws:servicequotas:ap-southeast-2:123456789012:ec2/L-1216C47A",
            "QuotaCode": "L-1216C47A",
            "QuotaName": "Running On-Demand Standard (A, C, D, H, I, M, R, T, Z) instances",
            "Value": 640.0,
            "Unit": "None",
            "Adjustable": true,
            "GlobalQuota": false,
            "UsageMetric": {
                "MetricNamespace": "AWS/Usage",
                "MetricName": "ResourceCount",
                "MetricDimensions": {
                    "Class": "Standard/OnDemand",
                    "Resource": "vCPU",
                    "Service": "EC2",
                    "Type": "Resource"
                },
                "MetricStatisticRecommendation": "Maximum"
            }
        },

    ...
    ]
}

这似乎与管理控制台中显示的配额相匹配。

然后我注意到 UsageMetric 信息看起来像 Amazon CloudWatch 指标:

            "UsageMetric": {
                "MetricNamespace": "AWS/Usage",
                "MetricName": "ResourceCount",
                "MetricDimensions": {
                    "Class": "Standard/OnDemand",
                    "Resource": "vCPU",
                    "Service": "EC2",
                    "Type": "Resource"
                },
                "MetricStatisticRecommendation": "Maximum"
            }

然后我转到 Amazon CloudWatch,单击所有指标并输入搜索词 使用标准< /code>:

Amazon CloudWatch 指标搜索

啊哈! Standard/OnDemand 指标出现了!

选择该复选框后会显示一个图表:

Amazon CloudWatch 指标图表

此指标与显示的利用率数字相匹配在服务配额页面中。

底线

服务配额指标可通过 Amazon CloudWatch 获取。您可以使用标准 API 调用来检索这些指标,或通过 Amazon CloudWatch Metrics 管理控制台访问它们。您还可以针对这些指标创建警报,以便在它们超出所需限制时通知您。

To discover where this information was available, I looked into the Service Quotas AWS service.

The aws service-quotas list-service command lists the service codes, such as:

{
    "Services": [
        {
            "ServiceCode": "AWSCloudMap",
            "ServiceName": "AWS Cloud Map"
        },
        ...
        {
            "ServiceCode": "ec2",
            "ServiceName": "Amazon Elastic Compute Cloud (Amazon EC2)"
        },
        ...
        {
            "ServiceCode": "xray",
            "ServiceName": "AWS X-Ray"
        }
    ]
}

So, the service code for Amazon EC2 is ec2.

Next, I listed the quotas for this service using aws service-quotas list-service-quotas --service-code ec2. Amongst the output I found:

{
    "Quotas": [
    ...
        {
            "ServiceCode": "ec2",
            "ServiceName": "Amazon Elastic Compute Cloud (Amazon EC2)",
            "QuotaArn": "arn:aws:servicequotas:ap-southeast-2:123456789012:ec2/L-1216C47A",
            "QuotaCode": "L-1216C47A",
            "QuotaName": "Running On-Demand Standard (A, C, D, H, I, M, R, T, Z) instances",
            "Value": 640.0,
            "Unit": "None",
            "Adjustable": true,
            "GlobalQuota": false,
            "UsageMetric": {
                "MetricNamespace": "AWS/Usage",
                "MetricName": "ResourceCount",
                "MetricDimensions": {
                    "Class": "Standard/OnDemand",
                    "Resource": "vCPU",
                    "Service": "EC2",
                    "Type": "Resource"
                },
                "MetricStatisticRecommendation": "Maximum"
            }
        },

    ...
    ]
}

This seemed to match the quota displayed in the Management Console.

I then noticed that the UsageMetric information looked like an Amazon CloudWatch metric:

            "UsageMetric": {
                "MetricNamespace": "AWS/Usage",
                "MetricName": "ResourceCount",
                "MetricDimensions": {
                    "Class": "Standard/OnDemand",
                    "Resource": "vCPU",
                    "Service": "EC2",
                    "Type": "Resource"
                },
                "MetricStatisticRecommendation": "Maximum"
            }

I then went to Amazon CloudWatch, clicked All metrics and entered a search term of usage standard:

Amazon CloudWatch metrics search

Aha! The Standard/OnDemand metric appeared!

Selecting the checkbox then showed a chart:

Amazon CloudWatch metrics chart

This metric matches the Utilization figure shown in the Service Quotas page.

Bottom line

Service Quota metrics are available through Amazon CloudWatch. You can use standard API calls to retrieve these metrics, or access them through the Amazon CloudWatch Metrics management console. You can also Create Alarms on these metrics to notify you when they exceed desired limits.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文