如何引用由 ECS/Fargate 容器洞察创建的 CloudWatch 指标 [英] How to reference a CloudWatch metric created by container insights for ECS/Fargate

查看:22
本文介绍了如何引用由 ECS/Fargate 容器洞察创建的 CloudWatch 指标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经像这样创建了一个 ECS 集群:

I've created an ECS cluster like so:

    this.cluster = new ecs.Cluster(this, 'Cluster', {
        containerInsights: true,
        vpc: ec2.Vpc.fromLookup(this, props.stage + 'Vpc', {isDefault: false})
    });

我想根据我的集群创建一个 CW 警报,如下所示:

I want to create a CW alarm based off my cluser like so:

    const CPUHigh = new cw.Alarm(this, "CPUHigh", {
        metric: this.cluster.metric("CPUUtilized"),
        threshold: 50,
        evaluationPeriods: 3,
        period: cdk.Duration.seconds(60),
        comparisonOperator: cw.ComparisonOperator.GREATER_THAN_THRESHOLD
    })

但即使该指标与 Container Insights 创建的指标相匹配,但似乎无法以这种方式引用.

But even though the metric matches the one created by Container Insights, it seems like it can't be referenced this way.

有人知道它应该被引用的方式吗?

Does anyone know the way its supposed to be referenced?

推荐答案

CDK 仅支持某些指标基线,并未涵盖容器洞察力,但这不是问题,您可以非常轻松地创建自己的指标对象.对于容器洞察,它看起来像这样:

CDK only has support for certain metrics baseline and container insight is not covered, but it's not a problem you can create your own metric object pretty easy. For container insights it looks like this:

new cloudwatch.Metric({
  metricName: 'NetworkTxBytes',
  namespace: 'ECS/ContainerInsights',
  dimensionsMap: {
    ServiceName: props.ecsService.serviceName,
    ClusterName: props.ecsCluster.clusterName,
  },
  statistic: 'avg',
  period: cdk.Duration.minutes(5),
}),

这里重要的是命名空间、维度映射和度量名称.

Important here is the namespace, dimensionsMap, and the metricName.

您可以从指标控制台和最后一个标签源"中获取有关命名空间和维度的信息.

You can get the information about the namespace and the dimensions from the metrics console and the last tab "source".

这篇关于如何引用由 ECS/Fargate 容器洞察创建的 CloudWatch 指标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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