在下面的脚本中,我们正在检查所选时间范围内的URL状态的平均可用性,以及最近3分钟的最新运行状况都正常,但是您知道日志分析数据注入的速度很慢,因为在最后一次检查时最新的健康状态持续3分钟,我们将获得空值,因此它会显示为不健康,但平均会显示为健康,因为用户选择了最近4小时的时间范围,然后会有所有健康状态的记录。
let start = {TimeRange:start};
let grain = {TimeRange:grain};
workspace(name).login_CL
| extend healthy=iff(StatusCode_s == 'OK' , 100 , 0)
| where TimeGenerated>={TimeRange:end}-3m and TimeGenerated<={TimeRange:end}
| summarize Availability=avg(healthy) by EnvName_s, ClientName_s
| extend HealthStatus=0.000
| extend LatestHealthStatus=Availability
| project Client=ClientName_s,Environment=EnvName_s,HealthStatusAverage = HealthStatus,LatestHealthStatus
)
| union
workspace(name).login_CL
| extend healthy=iff(StatusCode_s == 'OK' , 100 , 0)
| where TimeGenerated>={TimeRange:start} and TimeGenerated<={TimeRange:end}
| summarize pageAvailability=avg(healthy) by EnvName_s, ClientName_s
| extend LatestHealthStatus=0.000
| extend HealthStatus=pageAvailability
| join
( workspace(name).login_CL
| extend healthy=iff(StatusCode_s == 'OK' , 100 , 0)
| where TimeGenerated>={TimeRange:start} and TimeGenerated<={TimeRange:end}
| make-series lifeline = avg(healthy) on TimeGenerated from start to now() step grain by EnvName_s, ClientName_s
)
on EnvName_s
| project Environment=EnvName_s,HealthStatusAverage = HealthStatus,LatestHealthStatus,Lifeline=lifeline
| summarize AverageHealth=sum(HealthStatusAverage),
LatestHealth=sum(LatestHealthStatus),HearthbeatAvg=make_list(Lifeline) by
Environment
我们需要的是,如果最新健康状况由于任何原因不健康,平均水平也需要显示为不健康状况,我附上了工作簿的屏幕快照以供参考