[英]CDK v2 - access metric from CloudFormation Queue (CfnQueue)
I am using the cdk v2.33.0 for Typescript and I am trying to get the NumberOfMessageSent metric from a Cloud Formation Queue I created using the CfnQueue class.我正在为 Typescript 使用 cdk v2.33.0,我正在尝试从使用 CfnQueue 类创建的 Cloud Formation 队列中获取 NumberOfMessageSent 指标。 The end goal being to use this metric for an alarm I want to create.
最终目标是将此指标用于我要创建的警报。
While I am able to do myStandardQueue.metricNumberOfMessagesSent()
with a Queue
object, it seems CfnQueue
doesn't have this method.虽然我可以使用
Queue
对象执行myStandardQueue.metricNumberOfMessagesSent()
,但CfnQueue
似乎没有这种方法。
So my question is, is there another way to do this with CfnQueue objects?所以我的问题是,还有另一种方法可以用 CfnQueue 对象做到这一点吗?
To illustrate:为了显示:
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',
})
});
Thanks :)谢谢 :)
You can construct it manually.您可以手动构建它。 For
metricNumberOfMessagesSent
, the equivalent Metric would be:对于
metricNumberOfMessagesSent
,等效的 Metric 将是:
const myMetric = new Metric({
dimensions: { QueueName: myCfnQueue.attrQueueName },
namespace: 'AWS/SQS',
metricName: 'NumberOfMessagesSent',
period: Duration.minutes(5),
statistic: 'Sum',
});
You can do this for any metrics exposed by SQS.您可以对 SQS 公开的任何指标执行此操作。
The metric methods available in L2 are generated from spec files - here's the one for SQS: https://github.com/aws/aws-cdk/blob/main/packages/%40aws-cdk/cfnspec/lib/augmentations/AWS_SQS_Queue.json 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.