通过CloudWatch监控SQS消息

问题描述 投票:0回答:1

我收到了 SNS 通知,并且我已订阅了 SQS。我可以轮询我的消息并查看其内容。消息的内容包括自动化的通过/失败状态。是否可以根据指标内容创建cloudwatch指标?

amazon-cloudwatch amazon-sqs amazon-sns
1个回答
0
投票

这里有一些 pyhton 中的伪代码可以给你一个想法:

import json
import boto3

# Initialize CloudWatch client
cloudwatch = boto3.client('cloudwatch')

def lambda_handler(event, context):
    # Your code to parse the incoming SQS message
    # Assume that the status is stored in a variable called 'status'
    # ...

    # Put custom metric data into CloudWatch
    cloudwatch.put_metric_data(
        Namespace='MyCustomNamespace',
        MetricName='MyCustomMetricName',
        Dimensions=[
            {
                'Name': 'STATUS',
                'Value': status  # Use the parsed status here
            },
        ],
        Value=1  # Increment the metric by 1
    )
  1. 将 AWS Lambda 订阅到 SQS 队列

  2. 在 Lambda 中解析消息

  3. 将指标发送到 CloudWatch

  4. 创建 CloudWatch 警报和仪表板

© www.soinside.com 2019 - 2024. All rights reserved.