我是Azure Stream Analytics查询的新手。我的方案是使用Continuous Export将Application Insight遥测编写到Azure Blob存储,并使用Stream Analytics作业将数据从Blob存储推送到Power BI。我的json文件有Array和Request类型,如下所示:
{
"request": [
{
"id": "|HLHUdGy4c3g=.556f8524_",
"name": "HEAD Todos/Index",
"count": 1,
"responseCode": 200,
"success": true,
"url": "http://todoapp20183001.azurewebsites.net/",
"urlData": {
"base": "/",
"host": "todoapp20183001.azurewebsites.net",
"hashTag": "",
"protocol": "http"
},
"durationMetric": {
"value": 973023,
"count": 1,
"min": 973023,
"max": 973023,
"stdDev": 0,
"sampledValue": 973023
}
}
],
"internal": {
"data": {
"id": "124c5c1c-0820-11e8-a590-d95f25fd3f7f",
"documentVersion": "1.61"
}
},
"context": {
"data": {
"eventTime": "2018-02-02T13:50:39.591Z",
"isSynthetic": false,
"samplingRate": 100
},
"cloud": {},
"device": {
"type": "PC",
"roleName": "todoapp20183001",
"roleInstance": "RD0003FF6D001A",
"screenResolution": {}
},
"user": {
"isAuthenticated": false
},
"session": {
"isFirst": false
},
"operation": {
"id": "HLHUdGy4c3g=",
"parentId": "HLHUdGy4c3g=",
"name": "HEAD Todos/Index"
},
"location": {
"clientip": "35.153.211.0",
"continent": "North America",
"country": "United States",
"province": "Virginia",
"city": "Ashburn"
},
"custom": {
"dimensions": [
{
"_MS.ProcessedByMetricExtractors": "(Name:'Requests', Ver:'1.0')"
}
]
}
}
}

使用以下查询,我可以收到预期的输出。
WITH Request AS
(
SELECT
context.location.country as country,
context.location.city as city,
GetArrayElement(request,0) as requests
FROM FromBlob
)
SELECT country, city, requests.name
FROM Request

现在我需要按城市计算所有请求,但我似乎无法用COUNT()和GROUP BY()完成它。在这种情况下是否有提示或参考?
答案 0 :(得分:0)
以下是每5分钟计算一次请求数的示例。 请注意,我必须向GROUB BY添加一个时间组件,因为您的数据是流数据,并且您希望在有限的时间内获得聚合。
WITH Request AS
(
SELECT
context.location.country as country,
context.location.city as city,
GetArrayElement(request,0) as requests
FROM iothub
)
SELECT country, city, count(requests.name)
FROM Request
group by country,city,SlidingWindow(minute,5)
让我知道它是否适合你。