简体   繁体   English

aws-cdk 使用现有的负载均衡器和 ECS 服务创建 cloudwatch 仪表板

[英]aws-cdk to create cloudwatch dashboard using existing Load balancer & ECS service

I am using aws-cdk to create Cloudwatch metric, widget ,dashboard but not sure how to refer existing resources like Load balancer, ECS Service to create these cloudwatch resources.我正在使用 aws-cdk 创建 Cloudwatch 指标、小部件、仪表板,但不确定如何引用现有资源(如负载均衡器、ECS 服务)来创建这些 cloudwatch 资源。 Here is a POC:这是一个 POC:

from aws_cdk import (
    Stack,
    aws_elasticloadbalancingv2 as elbv2,
    aws_cloudwatch as cw
)
from constructs import Construct

class CwDashboardStack(Stack):

    def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
        super().__init__(scope, construct_id, **kwargs)

        cpu_utilization_metric = cw.Metric(namespace="AWS/ECS",metric_name="CPUUtilization")
        cpu_widget = cw.GraphWidget(
            title="CPU Utilization",
            height=8,
            width=12,
            left=[cpu_utilization_metric]
        )            

        cw.Dashboard(
            self,
            "Dashboard",
            dashboard_name="Service-Status",
            widgets=[
                [cpu_widget]
            ]
        )

But it results in an empty Cloudwatch dashboard:-但它会导致一个空的 Cloudwatch 仪表板:- 在此处输入图像描述 This is expected as there is no ECS service name, Cluster etc specified.But I can't find corresponding attribute in Metric class where I can put these values.Anyone has any suggestions?这是预期的,因为没有指定 ECS 服务名称、集群等。但是我在 Metric 类中找不到可以放置这些值的相应属性。有人有什么建议吗?

The ServiceName and ClusterName can be passed along as part of the dimenion_maps parameter of the cw.Metric() call. ServiceName 和 ClusterName 可以作为cw.Metric()调用的dimenion_maps参数的一部分传递。

Doing a bit of experimenting locally with CDK, I didn't have an ECS cluster handy to work with, but here's an example of providing a dimension_maps parameter to the cw.Metric() call:在本地使用 CDK 进行了一些试验,我没有方便使用的 ECS 集群,但这里有一个为cw.Metric()调用提供 dimension_maps 参数的示例:

        r53_utilization_metric = cw.Metric(
            namespace="AWS/Route53",
            metric_name="DNSQueries",
            dimensions_map = {
                "HostedZoneId": "<...>"
            }
        )
        r53_widget = cw.GraphWidget(
            title="Route53 Utilization",
            height=8,
            width=12,
            left=[r53_utilization_metric]
        )
        cw.Dashboard(
            self,
            "Dashboard",
            dashboard_name="Service-Status",
            widgets=[
                [r53_widget]
            ]
        )

Hopefully that gives you an idea on how to proceed.希望这能让您了解如何进行。

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

相关问题 如何使用 Python AWS-CDK 将现有资源添加到堆栈? - How to add an existing resource to stack using Python AWS-CDK? 在创建粘合表时使用 aws-cdk 中的现有数据库 - Using existing database in aws-cdk while creating a glue table 如何使用 aws-cdk for python 在一个 cloudwatch 图中获取多个 lambda - How to get multiple lambdas in one cloudwatch graph using aws-cdk for python 具有异常检测功能的 CloudWatch 警报的 AWS-CDK 示例 - AWS-CDK Example of CloudWatch Alarm with Anomaly detection 有没有办法使用 AWS-CDK 将新的 lambda function 连接到现有的 AWS ApiGateway? (Python) - Is there a way to connect a new lambda function an existing AWS ApiGateway using AWS-CDK? (Python) AWS CDK Python 使用默认操作创建 App Load Balancer Listner - AWS CDK Python Create App Load Balancer Listner with default action AWS CDK 并在现有 ALB 上创建 ECS/Fargate 服务。 使用现有的监听器? - AWS CDK and creating ECS/Fargate Service on existing ALB. Use existing listener? 如何在 python 中为 aws-cdk 创建自定义构造库 - How to create custom construct library for aws-cdk in python 使用 aws-cdk(python) 更新 redis 集群的问题 - issue with updating redis cluster using aws-cdk(python) 使用 AWS CDK for python 创建 AWS 网络负载均衡器时无法传递 ec2-instance 详细信息 - Unable to pass the ec2-instance details while creating AWS network load balancer using AWS CDK for python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM