繁体   English   中英

CDK v2 - 来自 CloudFormation 队列 (CfnQueue) 的访问指标

[英]CDK v2 - access metric from CloudFormation Queue (CfnQueue)

我正在为 Typescript 使用 cdk v2.33.0,我正在尝试从使用 CfnQueue 类创建的 Cloud Formation 队列中获取 NumberOfMessageSent 指标。 最终目标是将此指标用于我要创建的警报。

虽然我可以使用Queue对象执行myStandardQueue.metricNumberOfMessagesSent() ,但CfnQueue似乎没有这种方法。

所以我的问题是,还有另一种方法可以用 CfnQueue 对象做到这一点吗?

为了显示:

import { CfnQueue, Queue } from 'aws-cdk-lib/aws-sqs'


// THIS PART IS OK
const myStandardQueue = new Queue(..some parameters...);

const myStandardQueueAlarm = new Alarm(myScope, 'someIdForMyAlarm', {
      alarmName: `myStandardQueueAlarm`,
      comparisonOperator: ComparisonOperator.GREATER_THAN_OR_EQUAL_TO_THRESHOLD,
      evaluationPeriods: 1,
      threshold: 1,
      // this works because Queue has the metricNumberOfMessagesSent method -->
      metric: myStandardQueue.metricNumberOfMessagesSent({
        period: Duration.seconds(60),
        statistic: 'Sum',
      })
    });


// THIS PART IS NOT OK
const myCfnQueue = new CfnQueue(...some parameters...);

const myCfnQueueAlarm = new Alarm(myScope, 'someOtherIdForMyOtherAlarm', {
      alarmName: `myCfnQueueAlarm`,
      comparisonOperator: ComparisonOperator.GREATER_THAN_OR_EQUAL_TO_THRESHOLD,
      evaluationPeriods: 1,
      threshold: 1,
      // this does not works because CfnQueue does not have 
      // a metricNumberOfMessagesSent method -->
      metric: myStandardQueue.metricNumberOfMessagesSent({
        period: Duration.seconds(60),
        statistic: 'Sum',
      })
    });

谢谢 :)

您可以手动构建它。 对于metricNumberOfMessagesSent ,等效的 Metric 将是:

const myMetric = new Metric({
    dimensions: { QueueName: myCfnQueue.attrQueueName },
    namespace: 'AWS/SQS',
    metricName: 'NumberOfMessagesSent',
    period: Duration.minutes(5),
    statistic: 'Sum',
  });

您可以对 SQS 公开的任何指标执行此操作。

L2 中可用的度量方法是从规范文件生成的 - 这是 SQS 的方法: https ://github.com/aws/aws-cdk/blob/main/packages/%40aws-cdk/cfnspec/lib/augmentations/AWS_SQS_Queue .json

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM