如果您需要在同一个指标中使用“OR”和“Exclude”,则需要拆分该指标并将其分解为多个指标,以单独地应用“OR”和“Exclude”过滤器。以下是一个代码示例,演示如何将一个指标拆分成多个指标,并对每个指标应用不同的过滤器:
{
"Namespace": "AWS/Logs",
"MetricName": "ErrorCount",
"Dimensions": [
{
"Name": "LogGroupName",
"Value": "/aws/lambda/my-lambda-function"
},
{
"Name": "FilterPattern",
"Value": "{ ($.level = \"ERROR\") || ($.message = \"Connection timed out\") }"
}
]
},
{
"Namespace": "AWS/Logs",
"MetricName": "ErrorCount (Excluding Timeout Errors)",
"Dimensions": [
{
"Name": "LogGroupName",
"Value": "/aws/lambda/my-lambda-function"
},
{
"Name": "FilterPattern",
"Value": "{ ($.level = \"ERROR\") && ($.message != \"Connection timed out\") }"
}
]
}
在这个示例中,通过创建两个不同的指标来解决“OR”和“Exclude”不兼容的问题。第一个指标使用“OR”过滤器,选择错误级别为“ERROR”或错误信息包含“Connection timed out”的日志事件。第二个指标使用“Exclude”过滤器,选择错误级别为“ERROR”,但排除了错误信息包含“Connection timed out”的日志事件。