在下面的脚本中,我们正在检查所选时间范围内 URL 状态的平均可用性以及最近 3 分钟的最新健康状态,一切正常,但正如您所知,日志分析数据注入缓慢几次,因为在检查最后 3 分钟最新的健康状况我们得到空值,因此它将显示为不健康,但 avg 将显示为健康,因为用户选择了过去 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
我们需要的是,如果由于任何原因 latesthealth 不健康,平均值也需要显示为不健康我附上了工作簿的屏幕截图以供参考