我有一个查询,它总结了一些以毫秒为单位的数据:
requests
| summarize avg(duration) by name
当我显示此数据时,我想对其进行格式化,以便它以智能方式显示时间量:
示例:
- 1500 将显示 1.5 秒
- 300 将显示 300 毫秒
- 120000 将显示 2 分钟
我知道 Application Insights 的内置图表在“性能”选项卡中执行此操作,但我找不到执行此操作的内置函数。有谁知道是否有一个函数可以做到这一点?
最佳答案
下面是一个选项,使用 timespan
算术和一些字符串操作
或者 - 如果它适合您的要求 - 您可以使用 format_timespan()
: https://learn.microsoft.com/en-us/azure/data-explorer/kusto/query/format-timespanfunction
let format_ms_as_pretty_string = (t:long)
{
case(t < 1s / 1ms, strcat(t, " ms"),
t < 1m / 1ms, strcat(round(1.0 * t * 1ms / 1s, 3), " secs"),
t < 1h / 1ms, strcat(round(1.0 * t * 1ms / 1m, 3), " mins"),
strcat(round(1.0 * t * 1ms / 1h, 3), " hours"))
}
;
let input = datatable(t:long) [1500,300,120000,8481600,360100] // replace this with your input
;
input
| extend output = format_ms_as_pretty_string(t)
关于azure-log-analytics - 巧妙地设置毫秒格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67643315/