Query - Execute
执行分析查询
对数据执行 Analytics 查询。
此处 是将 POST 与 Analytics 查询配合使用的示例。
POST https://api.applicationinsights.io/v1/apps/{appId}/query
URI 参数
| 名称 | 在 | 必需 | 类型 | 说明 |
|---|---|---|---|---|
|
app
|
path | True |
string |
应用程序的 ID。 这是 Azure 门户中“API 访问设置”边栏选项卡中的应用程序 ID。 |
请求正文
| 名称 | 必需 | 类型 | 说明 |
|---|---|---|---|
| query | True |
string |
要执行的查询。 |
| applications |
string[] |
跨应用程序查询的应用程序 ID 列表。 |
|
| timespan |
string |
可选。 要查询数据的时间跨度。 这是ISO8601时间段值。 除了在查询表达式中指定的任何时间跨度外,还会应用此时间跨度。 |
响应
| 名称 | 类型 | 说明 |
|---|---|---|
| 200 OK |
成功的响应 |
|
| Other Status Codes |
错误响应对象。 |
安全性
oauth2
连接到 Azure Application Insights API
类型:
oauth2
流向:
implicit
授权 URL:
https://login.microsoftonline.com/common/oauth2/authorize?resource=https%3A%2F%2Fapi.applicationinsights.io
作用域
| 名称 | 说明 |
|---|---|
| user_impersonation | 模拟用户帐户 |
示例
queryPost
示例请求
POST https://api.applicationinsights.io/v1/apps/34adfa4f-cedf-4dc0-ba29-b6d1a69ab345/query
{
"timespan": "PT12H",
"query": "requests | summarize count() by bin(timestamp, 1h)"
}
示例响应
x-ms-request-id: 58a37988-2c05-427a-891f-5e0e1266fcc5
x-ms-correlation-request-id: 58a37988-2c05-427a-891f-5e0e1266fcc5
{
"tables": [
{
"name": "PrimaryResult",
"columns": [
{
"name": "timestamp",
"type": "datetime"
},
{
"name": "count_",
"type": "long"
}
],
"rows": [
[
"2018-02-02T05:00:00Z",
"255"
],
[
"2018-02-01T17:00:00Z",
"148"
],
[
"2018-02-01T18:00:00Z",
"453"
],
[
"2018-02-01T19:00:00Z",
"404"
],
[
"2018-02-01T20:00:00Z",
"403"
],
[
"2018-02-01T21:00:00Z",
"405"
],
[
"2018-02-01T22:00:00Z",
"438"
],
[
"2018-02-01T23:00:00Z",
"403"
],
[
"2018-02-02T00:00:00Z",
"423"
],
[
"2018-02-02T01:00:00Z",
"403"
],
[
"2018-02-02T02:00:00Z",
"425"
],
[
"2018-02-02T03:00:00Z",
"437"
],
[
"2018-02-02T04:00:00Z",
"420"
]
]
}
]
}
定义
| 名称 | 说明 |
|---|---|
| column |
表列。 |
|
error |
错误详细信息。 |
|
error |
错误的代码和消息。 |
|
error |
错误详细信息。 |
|
query |
Analytics 查询。 详细了解 Analytics 查询语法 |
|
query |
查询响应。 |
| table |
查询响应表。 |
column
表列。
| 名称 | 类型 | 说明 |
|---|---|---|
| name |
string |
此列的名称。 |
| type |
string |
此列的数据类型。 |
errorDetail
错误详细信息。
| 名称 | 类型 | 说明 |
|---|---|---|
| additionalProperties |
object |
|
| code |
string |
错误的代码。 |
| message |
string |
人工可读错误消息。 |
| resources |
string[] |
指示对错误负责的资源。 |
| target |
string |
指示请求中的哪个属性负责错误。 |
| value |
string |
指示“target”中的哪个值负责错误。 |
errorInfo
错误的代码和消息。
| 名称 | 类型 | 说明 |
|---|---|---|
| additionalProperties |
object |
|
| code |
string |
计算机可读错误代码。 |
| details |
错误详细信息。 |
|
| innererror |
错误的代码和消息。 |
|
| message |
string |
人工可读错误消息。 |
errorResponse
错误详细信息。
| 名称 | 类型 | 说明 |
|---|---|---|
| error |
错误的代码和消息。 |
queryBody
Analytics 查询。 详细了解 Analytics 查询语法
| 名称 | 类型 | 说明 |
|---|---|---|
| applications |
string[] |
跨应用程序查询的应用程序 ID 列表。 |
| query |
string |
要执行的查询。 |
| timespan |
string |
可选。 要查询数据的时间跨度。 这是ISO8601时间段值。 除了在查询表达式中指定的任何时间跨度外,还会应用此时间跨度。 |
queryResults
查询响应。
| 名称 | 类型 | 说明 |
|---|---|---|
| tables |
table[] |
表、列和行的列表。 |
table
查询响应表。
| 名称 | 类型 | 说明 |
|---|---|---|
| columns |
column[] |
此表中的列列表。 |
| name |
string |
表的名称。 |
| rows |
string[] |
此查询生成的行。 |