AWS CloudWatch日志过滤的参数可在警报通知中提供



我正在使用CloudWatch和Lambda监视日志。我设置了一些特定类型的错误在日志中出现时触发的一些过滤器。是否可以在CloudWatch Alarm sns上发送已过滤在日志上的参数?

例如:

接收错误:

[2017-06-29 17:58:52] prod.error:errorexception:未定义变量: 消息x

公制过滤器:

[date,info ="*。错误:",错误]

警报:

当< = 0

时还可以

已发送到SNS和Lambda的通知触发不同的通知代理。

SNS事件给了我此消息,但是我想访问已过滤的vars:

{
    "AlarmName": "PHP_ERROR",
    "AlarmDescription": null,
    "AWSAccountId": "xxxxxxxxx",
    "NewStateValue": "OK",
    "NewStateReason": "Threshold Crossed: no datapoints were received for 1 period and 1 missing datapoint was treated as [NonBreaching]",
    "StateChangeTime": "2017-06-29T17:09:12.336+0000",
    "Region": "EU - Ireland",
    "OldStateValue": "ALARM",
    "Trigger": {
        "MetricName": "PHP_ERROR",
        "Namespace": "Logs",
        "StatisticType": "Statistic",
        "Statistic": "SUM",
        "Unit": null,
        "Dimensions": [],
        "Period": 60,
        "EvaluationPeriods": 1,
        "ComparisonOperator": "GreaterThanOrEqualToThreshold",
        "Threshold": 0,
        "TreatMissingData": "- TreatMissingData:                    NonBreaching",
        "EvaluateLowSampleCountPercentile": ""
    }
}

谢谢,

不幸的是,alarm仅查看metric来评估阈值。因此,简短的答案是 no :(

然后,您还有另一个抽象级别,因为metric已经从filter的特定值设置了。

filter是唯一可以找到提取值的地方,但它只会将匹配转换为公制的值或增量(即:数字(,它不会用作解析的日志存储。p> AWS最近发布 CloudWatch日志见解,可以帮助您找到错误消息。

否则,您可以尝试使用logs命令的AWS CLI过滤器,该命令允许您浏览日志。

ubuntu中的示例

export YOUR_LOG_GROUP_NAME=SomeLogGroup
# The 1000 multiplication is to convert from seconds to milliseconds
# If you already have a specific timestamp, just replace it on the start-time argument
aws logs filter-log-events --log-group-name $YOUR_LOG_GROUP_NAME 
--start-time $(($(date +%s --date="1 minute ago") * 1000)) 
--interleaved --filter-pattern ".ERROR" 
--output=text --query events[*].[message]

OSX中的示例

export YOUR_LOG_GROUP_NAME=SomeLogGroup
# The 1000 multiplication is to convert from seconds to milliseconds
# If you already have a specific timestamp, just replace it on the start-time argument
aws logs filter-log-events --log-group-name $YOUR_LOG_GROUP_NAME 
--start-time $(($(date -v-1M +%s) * 1000)) 
--interleaved --filter-pattern ".ERROR" 
--output=text --query events[*].[message]

如果要自动化它,则可以替换触发操作,调用lambda(使用一些AWS SDK而不是CLI(,可以使用此信息为SNS生成所需的消息。

IE:

  • 来自:Metric -> Alarm -> SNS
  • to: Metric -> Alarm -> Lambda -> SNS

最新更新