你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

Query - Get

执行 Analytics 查询
对数据执行 Analytics 查询

GET https://api.loganalytics.io/v1/workspaces/{workspaceId}/query?query={query}
GET https://api.loganalytics.io/v1/workspaces/{workspaceId}/query?query={query}&timespan={timespan}

URI 参数

名称 必需 类型 说明
workspaceId
path True

string

工作区的 ID。 这是Azure 门户的“属性”边栏选项卡中的工作区 ID。

query
query True

string

分析查询。 详细了解 Analytics 查询语法

timespan
query

string

duration

可选。 查询数据的时间跨度。 这是一个ISO8601时间段值。 除了查询表达式中指定的任何时间跨度外,还会应用此时间跨度。

响应

名称 类型 说明
200 OK

queryResults

没问题。 API 调用成功,分析查询结果位于响应有效负载中

Other Status Codes

errorResponse

错误响应对象。

安全性

oauth2

Azure Active Directory OAuth2 流

Type: oauth2
Flow: implicit
Authorization URL: https://login.microsoftonline.com/common/oauth2/authorize

Scopes

名称 说明
user_impersonation 模拟用户帐户

示例

cross-workspace
simple-query

cross-workspace

Sample Request

GET https://api.loganalytics.io/v1/workspaces/63613592-b6f7-4c3d-a390-22ba13102111/query?query=union * | where TimeGenerated > ago(1h) | summarize count() by Type, TenantId

Sample Response

{
  "tables": [
    {
      "name": "PrimaryResult",
      "columns": [
        {
          "name": "Type",
          "type": "string"
        },
        {
          "name": "TenantId",
          "type": "string"
        },
        {
          "name": "count_",
          "type": "long"
        }
      ],
      "rows": [
        [
          "Usage",
          "63613592-b6f7-4c3d-a390-22ba13102111",
          "1"
        ],
        [
          "Usage",
          "d436f322-a9f4-4aad-9a7d-271fbf66001c",
          "1"
        ],
        [
          "BillingFact",
          "63613592-b6f7-4c3d-a390-22ba13102111",
          "1"
        ],
        [
          "BillingFact",
          "d436f322-a9f4-4aad-9a7d-271fbf66001c",
          "1"
        ],
        [
          "Operation",
          "63613592-b6f7-4c3d-a390-22ba13102111",
          "7"
        ],
        [
          "Operation",
          "d436f322-a9f4-4aad-9a7d-271fbf66001c",
          "5"
        ]
      ]
    }
  ]
}

simple-query

Sample Request

GET https://api.loganalytics.io/v1/workspaces/63613592-b6f7-4c3d-a390-22ba13102111/query?query=Usage | take 10&timespan=PT12H

Sample Response

x-ms-request-id: 58a37988-2c05-427a-891f-5e0e1266fcc5
x-ms-correlation-request-id: 58a37988-2c05-427a-891f-5e0e1266fcc5
{
  "tables": [
    {
      "name": "PrimaryResult",
      "columns": [
        {
          "name": "TenantId",
          "type": "string"
        },
        {
          "name": "Computer",
          "type": "string"
        },
        {
          "name": "TimeGenerated",
          "type": "datetime"
        },
        {
          "name": "SourceSystem",
          "type": "string"
        },
        {
          "name": "StartTime",
          "type": "datetime"
        },
        {
          "name": "EndTime",
          "type": "datetime"
        },
        {
          "name": "ResourceUri",
          "type": "string"
        },
        {
          "name": "LinkedResourceUri",
          "type": "string"
        },
        {
          "name": "DataType",
          "type": "string"
        },
        {
          "name": "Solution",
          "type": "string"
        },
        {
          "name": "BatchesWithinSla",
          "type": "long"
        },
        {
          "name": "BatchesOutsideSla",
          "type": "long"
        },
        {
          "name": "BatchesCapped",
          "type": "long"
        },
        {
          "name": "TotalBatches",
          "type": "long"
        },
        {
          "name": "AvgLatencyInSeconds",
          "type": "real"
        },
        {
          "name": "Quantity",
          "type": "real"
        },
        {
          "name": "QuantityUnit",
          "type": "string"
        },
        {
          "name": "IsBillable",
          "type": "bool"
        },
        {
          "name": "MeterId",
          "type": "string"
        },
        {
          "name": "LinkedMeterId",
          "type": "string"
        },
        {
          "name": "Type",
          "type": "string"
        }
      ],
      "rows": [
        [
          "b438b4f6-912a-46d5-9cb1-b44069212abc",
          "ContosoSQLSrv1",
          "2017-08-24T06:59:59Z",
          "OMS",
          "2017-08-24T06:00:00Z",
          "2017-08-24T06:59:59Z",
          "/subscriptions/e4272367-5645-4c4e-9c67-3b74b59a6982/resourcegroups/contosoazurehq/providers/microsoft.operationalinsights/workspaces/contosoretail-it",
          null,
          "Perf",
          "LogManagement",
          "1",
          "0",
          "0",
          "1",
          "1.286",
          "0.076408",
          "MBytes",
          "true",
          "a4e29a95-5b4c-408b-80e3-113f9410566e",
          "00000000-0000-0000-0000-000000000000",
          "Usage"
        ],
        [
          "b438b4f6-912a-46d5-9cb1-b44069212abc",
          "Store010Web3",
          "2017-08-24T06:59:59Z",
          "OMS",
          "2017-08-24T06:00:00Z",
          "2017-08-24T06:59:59Z",
          "/subscriptions/e4272367-5645-4c4e-9c67-3b74b59a6982/resourcegroups/contosoazurehq/providers/microsoft.operationalinsights/workspaces/contosoretail-it",
          null,
          "Perf",
          "LogManagement",
          "1",
          "0",
          "0",
          "1",
          "1.7",
          "0.106767",
          "MBytes",
          "true",
          "a4e29a95-5b4c-408b-80e3-113f9410566e",
          "00000000-0000-0000-0000-000000000000",
          "Usage"
        ]
      ]
    }
  ]
}

定义

名称 说明
column

表列。

errorDetail

错误详细信息。

errorInfo

错误的代码和消息。

errorResponse

错误详细信息。

logsColumnType

此列的数据类型。

queryResults

查询响应。

Render

JSON 格式的可视化数据。

Statistics

以 JSON 格式表示的统计信息。

table

查询响应表。

column

表列。

名称 类型 说明
name

string

此列的名称。

type

logsColumnType

此列的数据类型。

errorDetail

错误详细信息。

名称 类型 说明
additionalProperties

object

可在错误详细信息对象上提供的其他属性

code

string

错误的代码。

message

string

人工可读错误消息。

resources

string[]

指示对错误负责的资源。

target

string

指示请求中的哪个属性对错误负责。

value

string

指示“target”中的哪个值是导致此错误的。

errorInfo

错误的代码和消息。

名称 类型 说明
additionalProperties

object

可在错误信息对象上提供的其他属性

code

string

计算机可读错误代码。

details

errorDetail[]

错误详细信息。

innererror

errorInfo

错误的代码和消息。
内部错误详细信息(如果存在)。

message

string

人工可读错误消息。

errorResponse

错误详细信息。

名称 类型 说明
error

errorInfo

错误的代码和消息。
错误详细信息。

logsColumnType

此列的数据类型。

名称 类型 说明
bool

string

datetime

string

decimal

string

dynamic

string

guid

string

int

string

long

string

real

string

string

string

timespan

string

queryResults

查询响应。

名称 类型 说明
error

errorInfo

错误的代码和消息。

render

Render

JSON 格式的可视化数据。

statistics

Statistics

以 JSON 格式表示的统计信息。

tables

table[]

表、列和行的列表。

Render

JSON 格式的可视化数据。

Statistics

以 JSON 格式表示的统计信息。

table

查询响应表。

名称 类型 说明
columns

column[]

此表中的列列表。

name

string

表的名称。

rows

object[]

此查询的结果行。