[英]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.