如何解决使用SEARCH的MathExpression的CloudWatch警报和图形
我正在尝试使用AWS-CDK为我的Kafka使用者创建图表和相应的滞后警报,但似乎无法获得它来生成有效的配置。
我要报告的指标是Count
,具有两个维度:topic
和partition
。现在,我想创建一个图形,每个分区一行,以及这些值的总和一行。本质上,我正在尝试在CDK中复制此图:
// To create one metric per partition,I'm using a MathExpression with a SEARCH
// since I won't necessarily know how many partitions there are.
const lagPerPartition = new MathExpression({
expression: "SEARCH(' {kafkajs-canary-app/Consumer,topic,partition} MetricName=OffsetLag topic=test-topic','Average',300)",// This feels suspicious to me. `usingMetrics` is required,but I don't have any use
// for a metric in my expression,and adding a metric I don't use doesn't seem to change anything
usingMetrics: {}
});
// Now to sum those values
const totalLag = new MathExpression({
expression: 'SUM(lagPerPartition)',usingMetrics: {
lagPerPartition
},label: "Total lag"
});
// Now to create alarms
const lagPerPartitionAlarm = lagPerPartition.createAlarm(this,'ConsumerOffsetLagPerPartition',{
alarmName: 'Offset Lag per Partition',alarmDescription: 'Consumer has high lag on one or more partitions',threshold: 100,evaluationPeriods: 1,treatMissingData: TreatMissingData.NOT_BREACHING,});
const totalLagAlarm = totalLag.createAlarm(this,'ConsumerOffsetLagTotal',{
alarmName: 'Total Offset Lag',alarmDescription: 'Consumer has high lag across all partitions',threshold: 200,});
// Finally we add it to our dashboard
const dashboard = new Dashboard(this,'Dashboard',{ dashboardName: 'Health' })
dashboard.addWidgets(new GraphWidget({
title:'Consumer lag',left: [lagPerPartition,totalLag],stacked: false,width: 8,leftAnnotations: [
lagPerPartitionAlarm.toAnnotation(),totalLagAlarm.toAnnotation()
]
}));
尝试执行此堆栈只会导致CloudFormation出现错误,该错误指出其中一个表达式存在问题,但不是问题所在,以及为什么我可以通过创建一个我认为会是同一件事的东西用户界面:
警报包含无效的表达式。 (服务:AmazonCloudWatch;状态代码:400;错误代码:ValidationError;请求ID:487e9db7-0035-4fca-90ac-8d0227c589ea;代理服务器:空)
解决方法
您无法使用搜索表达式创建警报。 只是想回答一下以备将来参考。
另请查看:Creating a CloudWatch alarm based on a search expression
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。