Azure Log Analytics 在计数时聚合相似数据

Azure Log Analytics aggregate similar data when counting

我正在尝试获取有关我们客户使用的浏览器类型的数据。我想要一个饼图,显示 Chrome 用户的百分比,Firefox/Mozilla 用户的百分比,百分比Safari 用户,以及 Edge/IE 用户的百分比。

使用以下查询,我可以列出所有独特的浏览器类型:Chrome57、Chrome59 等...

customEvents
| where timestamp >= ago(7d)
| summarize Count=count(customDimensions.Type) by Browser=tostring(customDimensions.Type)
| project Browser,Count

How can I aggregate the browsers that have the same name but different version? For instance, add all the Chrome browsers into one giant total.

最简单的方法是在数据收集步骤不使用浏览器版本的情况下记录 customDimension.Type。如果这不是一个选项,第二个最简单的方法是使用 reduce 运算符来避免正则表达式字符串操作以仅提取浏览器名称。

如果在投影 customDimensions.Type 之后使用,那么它将自动对匹配的字符串(浏览器名称)进行分组,并提供它们的计数以及与通配符匹配的示例浏览器字符串。

语法

T | reduce [kind = ReduceKind] by Expr [with [threshold = Threshold] [, characters = Characters] ]

参数

Expr: An expression that evaluates to a string value.
Threshold: A real literal in the range (0..1). Default is 0.1. For large inputs, threshold should be small.
Characters: A string literal containing a list of characters to add to the list of characters that don't break a term. (For example, if you want aaa=bbbb and aaa:bbb to each be a whole term, rather than break on = and :, use ":=" as the string literal.)
ReduceKind: Specifies the reduce flavor. The only valid value for the time being is source.

Returns

此运算符 returns 具有三列(模式、计数和代表)的 table,行数与组数一样多。 Pattern 是组的模式值,*用作通配符(表示任意插入字符串),Count 计算运算符的输入中有多少行由该模式表示,Representative 是输入中落下的一个值加入这个小组。

P.S

或者,您可以尝试 regex extraction 名称(例如,提取任何数字之前的所有内容并将其用作浏览器名称)。