在 Log Analytics Kusto 查询中添加包含总计的行

Bra*_*out 7 azure-log-analytics kql azure-log-analytics-workspace

我查询请求日志以获取状态代码的摘要。不过,我想在结果末尾添加一行,显示请求总数。如何添加这样的行?

当前查询(简化)

MyLog
| summarize count() by responseCode
Run Code Online (Sandbox Code Playgroud)

目前的结果看起来像

响应码 数数
200 1000
404 20
500 100

我想要这样的总数

响应码 数数
200 1000
404 20
500 100
全部的 1120

Yon*_*i L 6

你可以试试这个:

MyLog
| summarize c = count() by responseCode
| as hint.materialized=true T
| union (T | summarize c = sum(c) by responseCode = "total")
Run Code Online (Sandbox Code Playgroud)

或这个:

MyLog
| summarize c = count() by responseCode
| union (print responseCode = "total", c = toscalar(MyLog | count))
Run Code Online (Sandbox Code Playgroud)

如果您想将“总计”行保留在最后,您可以对联合数据集进行排序。例如:

MyLog
| summarize c = count() by responseCode
| extend _o = 0
| union (
    print responseCode = "total",
          c = toscalar(MyLog | count),
          _o = 1
)
| order by _o asc, c desc
| project-away _o
Run Code Online (Sandbox Code Playgroud)