问题描述
我在Azure AppInsights中有一个日志序列,该日志序列保留计划作业每次运行的日志记录。
为了知道作业的最后一次运行时间,我按以下方式使用请求
customEvents
| where name == "Scheduled job started"
| project source=strcat(tostring(customDimensions.prefix),"-",tostring(customDimensions.postfix)),timestamp
| summarize last_started=max(format_datetime(todatetime(timestamp),'yy-MM-dd HH:mm:ss')) by source
| order by last_started desc
所以它给了我一张像这样的桌子
job0 20-08-11 13:40:06
job1 20-08-11 13:35:06
job2 20-08-11 13:15:06
...
现在,我需要为过去超过24小时的时间戳创建一个警报,这意味着我想修改查询,使其仅包含时间戳超过24小时的行。以后,如果有这样的时间戳,我将制定警报规则。
我该如何实现?
解决方法
尝试使用ago
运算符:
customEvents
| where name == "Scheduled job started"
| extend source=strcat(tostring(customDimensions.prefix),"-",tostring(customDimensions.postfix)),timestamp
| summarize last_started=max(format_datetime(todatetime(timestamp),'yy-MM-dd HH:mm:ss')),lastTimestamp = max(timestamp) by source
| where lastTimestamp < ago(1d)
| order by lastTimestamp desc
| project source,last_started
您会看到ago
运算符可以在这里为您提供帮助。由于该运算符只能与日期时间字段一起使用,因此我也必须选择lastTimestamp,但是它会在投影中被过滤掉。