如何让 Application Insights Rest Api return 所有数据,即使它不存在?
How do i make Application Insights Rest Api return all data even if it doesn't exist?
所以我尝试使用演示凭据使用 GET 请求获取最后一天每小时的浏览器异常数量:
https://api.applicationinsights.io/beta/apps/DEMO_APP/metrics/exceptions/browser?timespan=P1D&interval=PT1H
但它不是 return 所有数据,它只是 return 已设置的数据,如图所示:
{
start: '2017-08-22T13:00:00.000Z',
end: '2017-08-22T14:00:00.000Z',
'exceptions/browser': { sum: 1 }
}
{
start: '2017-08-23T04:00:00.000Z',
end: '2017-08-23T05:00:00.000Z',
'exceptions/browser': { sum: 1 }
}
我如何做到 return即使总和为 0 也能处理每一位数据?例如:
{
start: '2017-08-22T13:00:00.000Z',
end: '2017-08-22T14:00:00.000Z',
'exceptions/browser': { sum: 1 }
}
{
start: '2017-08-23T14:00:00.000Z',
end: '2017-08-23T15:00:00.000Z',
'exceptions/browser': { sum: 0 }
}
{
start: '2017-08-23T15:00:00.000Z',
end: '2017-08-23T16:00:00.000Z',
'exceptions/browser': { sum: 0 }
}
{
start: '2017-08-23T16:00:00.000Z',
end: '2017-08-23T17:00:00.000Z',
'exceptions/browser': { sum: 1 }
}
您正在使用 API 的度量部分,请使用查询部分。
查询仍将 return Json 但在 odata 标准中。这意味着需要涉及分页。
查询调用将允许您return所有列和所有行。
这将需要使用查询 API,并使用 Analytics Query Language.
形式化您的查询
我的查询 运行 得到与你想要的相同的数据是:
exceptions
| where timestamp >= ago(24h)
| where client_Type=="Browser"
| make-series count() default=0 on timestamp in range(ago(24h), now(), 1h)
| mvexpand count_ to typeof(long), timestamp to typeof(datetime)
注意事项:
- 我用
client_Type=="Browser"
过滤以匹配 exceptions/browser
查询
- 为了 "fill in the blanks" 你必须使用
make-series
而不是 summarize
- 查询的最终 URL 是:
https://api.applicationinsights.io/beta/apps/DEMO_APP/query?query=exceptions%7C%20where%20timestamp%20%3E%3D%20ago(24h)%7C%20where%20client_Type%3D%3D%22Browser%22%7C%20make-series%20count()%20default%3D0%20on%20timestamp%20in%20range(ago(24h)%2C%20now()%2C%201h)%7C%20mvexpand%20count_%20to%20typeof(long)%2C%20timestamp%20to%20typeof(datetime)
所以我尝试使用演示凭据使用 GET 请求获取最后一天每小时的浏览器异常数量:
https://api.applicationinsights.io/beta/apps/DEMO_APP/metrics/exceptions/browser?timespan=P1D&interval=PT1H
但它不是 return 所有数据,它只是 return 已设置的数据,如图所示:
{
start: '2017-08-22T13:00:00.000Z',
end: '2017-08-22T14:00:00.000Z',
'exceptions/browser': { sum: 1 }
}
{
start: '2017-08-23T04:00:00.000Z',
end: '2017-08-23T05:00:00.000Z',
'exceptions/browser': { sum: 1 }
}
我如何做到 return即使总和为 0 也能处理每一位数据?例如:
{
start: '2017-08-22T13:00:00.000Z',
end: '2017-08-22T14:00:00.000Z',
'exceptions/browser': { sum: 1 }
}
{
start: '2017-08-23T14:00:00.000Z',
end: '2017-08-23T15:00:00.000Z',
'exceptions/browser': { sum: 0 }
}
{
start: '2017-08-23T15:00:00.000Z',
end: '2017-08-23T16:00:00.000Z',
'exceptions/browser': { sum: 0 }
}
{
start: '2017-08-23T16:00:00.000Z',
end: '2017-08-23T17:00:00.000Z',
'exceptions/browser': { sum: 1 }
}
您正在使用 API 的度量部分,请使用查询部分。
查询仍将 return Json 但在 odata 标准中。这意味着需要涉及分页。
查询调用将允许您return所有列和所有行。
这将需要使用查询 API,并使用 Analytics Query Language.
形式化您的查询
我的查询 运行 得到与你想要的相同的数据是:
exceptions
| where timestamp >= ago(24h)
| where client_Type=="Browser"
| make-series count() default=0 on timestamp in range(ago(24h), now(), 1h)
| mvexpand count_ to typeof(long), timestamp to typeof(datetime)
注意事项:
- 我用
client_Type=="Browser"
过滤以匹配exceptions/browser
查询 - 为了 "fill in the blanks" 你必须使用
make-series
而不是summarize
- 查询的最终 URL 是:
https://api.applicationinsights.io/beta/apps/DEMO_APP/query?query=exceptions%7C%20where%20timestamp%20%3E%3D%20ago(24h)%7C%20where%20client_Type%3D%3D%22Browser%22%7C%20make-series%20count()%20default%3D0%20on%20timestamp%20in%20range(ago(24h)%2C%20now()%2C%201h)%7C%20mvexpand%20count_%20to%20typeof(long)%2C%20timestamp%20to%20typeof(datetime)