【问题标题】:CloudWatch alarm and graph for MathExpression with SEARCH带有 SEARCH 的 MathExpression 的 CloudWatch 警报和图表
【发布时间】:2020-12-30 02:15:53
【问题描述】:

我正在尝试使用 AWS-CDK 为我的 Kafka 消费者创建一个图表和相应的延迟警报,但我似乎无法让它生成有效的配置。

我报告的指标是Count,具有两个维度:topicpartition。现在我想创建一个图表,每个分区有一条线,这些值的总和有一条线。本质上,我正在尝试在 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,
  evaluationPeriods: 1,
  treatMissingData: TreatMissingData.NOT_BREACHING,
});

// 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;代理:null)

【问题讨论】:

    标签: typescript amazon-web-services amazon-cloudwatch aws-cdk


    【解决方案1】:

    您无法使用搜索表达式创建警报。 只是想回答它以供将来参考。

    也可以看看这个:Creating a CloudWatch alarm based on a search expression

    【讨论】:

    • 加个评论跟Tommy Brunn交流会更好。
    猜你喜欢
    • 2021-01-10
    • 1970-01-01
    • 2020-01-31
    • 2021-04-09
    • 2018-03-23
    • 2021-08-13
    • 2016-03-24
    • 2020-06-18
    • 1970-01-01
    相关资源
    最近更新 更多