【问题标题】:Azure Application Insights - How to display a row with default values if the kusto query returned no results?Azure Application Insights - 如果 kusto 查询未返回任何结果,如何显示具有默认值的行?
【发布时间】:2022-08-05 17:29:28
【问题描述】:

我在 Azure Application Insights 工作簿中使用以下 Kusto 查询来获取满意用户、容忍用户和沮丧用户的数量。

let apdexThreshhold = toint(1000);
let apdexData = pageViews
    | where timestamp > ago(7d)
    | where name in (\'*\') or \'*\' in (\'*\')
    | extend success = columnifexists(\'success\', true)
    | extend Failure = iff(\'ConsiderFailures\' == \'ConsiderFailures\' and success == false, 1, 0)
    | extend InterestingDimension = iff(isempty(name) == true, \'Unknown\', name)
    | where InterestingDimension in (\'*\') or \'*\' in (\'*\')
    | summarize AverageDuration = avg(duration), Failures = sum(Failure) by user_Id, InterestingDimension
    | extend UserExperience = case(AverageDuration <= apdexThreshhold, \'Satisfied\', AverageDuration <= 4 * apdexThreshhold, \'Tolerating\', \'Frustrated\')
    | extend UserExperience = case(Failures > 0, \"Frustrated\", UserExperience)
    | summarize
        Satisfied = countif(UserExperience == \'Satisfied\'),
        Tolerating = countif(UserExperience == \'Tolerating\'),
        Frustrated = countif(UserExperience == \'Frustrated\'),
        Total = count()
        by InterestingDimension
    | project
        InterestingDimension,
        [\"Satisfied Users\"] = Satisfied,
        [\"Tolerating Users\"] = Tolerating,
        [\"Frustrated Users\"] = Frustrated,
        [\"Apdex Score\"] = round((Satisfied + (Tolerating / 2.0)) / Total, 2),
        Total
    | extend Relevance = iff([\"Apdex Score\"] == 0, pow(Total, 1.6), Total / [\"Apdex Score\"])
    | project-rename Users = Total
    | order by Relevance desc
    | project-away Users, Relevance;
apdexData
| extend [\"Apdex Interpretation\"] = case([\"Apdex Score\"] <= 0.5, \'⛔ Unacceptable\', [\"Apdex Score\"] <= 0.7, \'⚠️ Poor\', [\"Apdex Score\"] <= 0.85, \'⚠️ Fair\', [\"Apdex Score\"] <= 0.94, \'✔️ Good\', \'✔️ Excellent\')
| project
    Values = InterestingDimension,
    [\"Apdex Score\"],
    [\"Apdex Interpretation\"],
    [\"Satisfied Users\"],
    [\"Tolerating Users\"],
    [\"Frustrated Users\"]

上面的查询返回结果没有任何问题。但是,只要没有数据,此查询就会返回一条文本消息,上面写着“没有结果”。但我想在每列中显示一行,默认值为“0”。

例子:

更新:

let emptyRow = datatable( Values: string, [\"Apdex Score\"]: double, [\"Apdex Interpretation\"]: string, [\"Satisfied Users\"]:long, [\"Tolerating Users\"]: long, [\"Frustrated Users\"]: long) [ \"0\", 0, \"0\", 0, 0, 0] ;

<Above Query>

// add empty row
| union (emptyRow)
| order by [\"Apdex Interpretation\"] desc

上面的查询添加了空行,即使在结果的情况下也是如此。我尝试使用以下代码行更新上述查询,以仅在没有结果的情况下添加空行。但它仍然没有按预期工作。

let T = apdexData 
| where Values!=null
| project
    Values = InterestingDimension,
    [\"Apdex Score\"],
    [\"Apdex Interpretation\"],
    [\"Satisfied Users\"],
    [\"Tolerating Users\"],
    [\"Frustrated Users\"];
    
let T_has_records = toscalar(T | summarize count() > 0);
union 
(T | where T_has_records == true),
(emptyRow | where T_has_records == false)

标签: azure azure-application-insights kusto-explorer azure-monitor-workbooks


【解决方案1】:

可以以各种方式执行此操作,例如与空行联合:

let emptyRow = datatable( Values: string, ["Apdex Score"]: double, ["Apdex Interpretation"]: string, ["Satisfied Users"]:long, ["Tolerating Users"]: long, ["Frustrated Users"]: long) [ "0", 0, "0", 0, 0, 0] ;
...
your existing query above
...

// add empty row
| union (emptyRow)
| order by ["Apdex Interpretation"] desc

但这总是会添加空行。然后您可以使用scan 运算符(https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/scan-operator)来过滤掉空组?

可能不仅仅是“无结果”消息(您也可以在高级设置选项卡中自定义无结果消息)

【讨论】:

  • 如果可能,请更新上述查询以在没有结果的情况下显示默认值。
  • 我基本上已经做到了,您只需将您的复制并粘贴到我有... your query here... 的地方。正如我所说,它不会是完美的,得到确切地你想要的是留给读者的练习。
猜你喜欢
  • 2021-11-23
  • 1970-01-01
  • 1970-01-01
  • 2019-04-12
  • 1970-01-01
  • 2021-03-20
  • 1970-01-01
  • 2019-11-11
  • 2023-02-17
相关资源
最近更新 更多