【问题标题】:How to reference a CloudWatch metric created by container insights for ECS/Fargate如何引用由 ECS/Fargate 的容器洞察创建的 CloudWatch 指标
【发布时间】:2021-10-23 06:15:57
【问题描述】:

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

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

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

    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 创建的指标相匹配,但似乎无法以这种方式引用它。

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

【问题讨论】:

    标签: javascript typescript amazon-ecs aws-cdk aws-fargate


    【解决方案1】:

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

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

    这里重要的是命名空间、dimensionMap 和 metricName。

    您可以从指标控制台和最后一个选项卡“源”中获取有关命名空间和维度的信息。

    【讨论】:

      猜你喜欢
      • 2021-10-26
      • 2019-12-19
      • 2020-11-09
      • 1970-01-01
      • 2021-12-27
      • 1970-01-01
      • 2020-02-16
      • 1970-01-01
      • 2022-12-15
      相关资源
      最近更新 更多