2017-10-06 103 views
0

我们将通过应用程序洞察从我们的应用程序收集使用度量(通过customEvents定义customMeasurements)。如果我们的(Windows)服务启动,然后每天通过计时器收集数据,则会收集数据。如何总结应用程序洞察分析中的最大值

我知道,应用程序的见解并不意味着使用“处所”的软件,但我们做吧;-)

所以我们得到的是安装在我们的客户的所有服务中的数据。每个客户都有一个唯一的ID(GUID),它允许我们按客户分组。 (FYI我们不知道哪些客户是这样的GUID的背后,它只是为“分组”的客户值)

事件看起来是这样的:

enter image description here

  1. 我现在想group by customerId,
  2. 获取特定度量值的最大值值
  3. 并为所有客户创建总和。

我得到了1和2,但已经不知道如何总结的最高值......

enter image description here

证明什么,我试图做我在SQL添加了一个例子:

CREATE TABLE [dbo].[metricData] 
(
    [RecId] [int] IDENTITY(1,1) NOT NULL, 
    [customerId] [int], 
    [metricValue1] [int], 
    [metricValue2] [int] 
) 


INSERT INTO [dbo].[metricData]  VALUES (1234, 1,1) 
INSERT INTO [dbo].[metricData]  VALUES (1234, 1,2) 
INSERT INTO [dbo].[metricData]  VALUES (1234, 1,1) 
INSERT INTO [dbo].[metricData]  VALUES (2345, 6,4) 
INSERT INTO [dbo].[metricData]  VALUES (2345, 8,7) 
INSERT INTO [dbo].[metricData]  VALUES (3456, 1,1) 
INSERT INTO [dbo].[metricData]  VALUES (3456, 1,2) 
INSERT INTO [dbo].[metricData]  VALUES (3456, 1,1) 
INSERT INTO [dbo].[metricData]  VALUES (4576, 20,30) 


select sum(maxVal1),sum(maxVal2) from 
(
    select max(metricValue1) as maxVal1, max(metricValue2) as maxVal2 from metricData 
    group by customerId 
) t 

基本上相同,这里也问过,但对于应用程序的见解:-) SQL: SUM the MAX values of results returned

感谢任何提示

+0

也*,我知道,应用程序的见解并不意味着用于“本地”软件,但我们无论如何做“*不真实:)。应用程序见解适用于任何可以将数据发送到应用程序见解的遥测。唯一不起作用的地方是遥测无法离开的封闭网络。对于内部部署应用程序,Web测试等一些应用程序见解功能将无法正常工作,因为webtest无法在您的网络中看到*。 –

回答

1

我得到了一个解决方案:

customEvents 
|where name == "usageMetrics" 
|extend cn = tostring(customDimensions.["CustomerId"]) 
|summarize maxValTotal= max(toint(customMeasurements.['metric_Total'])), maxValFree= max(toint(customMeasurements.['metric_Free'])) by cn 
|summarize dcount(cn),sum(maxValTotal), sum(maxValFree) 
|render barchart kind=unstacked  

希望这可以帮助其他人,因为这样的查询语言不是那么直观...

反正让我知道如果你有任何更好的解决方案,以解决这个问题...

+1

另外,如果您的自定义维度或指标不包含特殊字符,则可以简化其他的东西,比如'extend CustomerId = tostring(customDimensions.CustomerId)' –