为 aws cloudwatch 日志创建警报

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

我有一个 AWS cloudwatch 日志,其中包含包含类似日志的日志流

{"levelname": "INFO", "asctime": "2024-01-27T05:09:56Z+0000", "name": "root", "processName": "MainProcess", "filename": "app.py", "funcName": "lambda_handler", "lineno": 85, "module": "app", "threadName": "MainThread", "message": "reset successful", "aws_request_id": null, "export_rs": true, "user_id": "abcd3928784798ahHBS", "type_of_event": "RESET_SUCCESSFUL", "event_ts": "2024-01-27 05:09:56", "timestamp": "2024-01-27T05:09:56Z+0000"}

这里我需要在提到的 logroup 内 6 小时内出现超过 x 次

user_id
RESET_SUCCESSFUL 的
type_of_event
时创建警报,并且警报消息应该 包含
user_id
以及
type_of_event
出现的次数 ..

我尝试对cloudwatch日志组使用指标过滤器,但它同时过滤了user_id和type_of_event,并且我无法计算出现更多type_of_event的user_id。

有没有办法实现这一点,有人可以帮助我吗?

amazon-web-services devops monitoring amazon-cloudwatchlogs
1个回答
0
投票

据我所知,日志中的指标过滤器将给出“平坦”的数字结果,没有可用的分组。 根据您的需求,自定义指标是最合适的! 以下是它的实施方式:

  1. 更改您的应用程序顶部发布具有标准分辨率的自定义指标。
  2. 自定义指标将发送值 1,因为我们将对事件进行计数。
  3. 向自定义指标添加维度:UserId 和 TypeOfEvent。
  4. 转到 CloudWatch Alarms 并单击“创建警报”。
  5. 选择您的自定义指标并使用“查询”选择指标,您可以在其中使用维度过滤组时间序列。 有关指标查询语言的更多信息

这是如何通过 cli 发布自定义指标的示例:https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/publishingMetrics.html,以此类推,找出如何操作应该没有问题通过 SDK。

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