共用方式為


Query - Execute

執行分析查詢
執行數據的分析查詢。 以下是 搭配分析查詢使用POST的範例。

POST https://api.loganalytics.io/v1/workspaces/{workspaceId}/query

URI 參數

名稱 位於 必要 類型 Description
workspaceId
path True

string

工作區的標識碼。 這是 Azure 入口網站 中 [屬性] 刀鋒視窗中的 [工作區標識符]。

要求標頭

名稱 必要 類型 Description
Prefer

string

選擇性。 偏好的標頭是設定伺服器逾時、查詢統計數據和視覺效果資訊。

要求本文

名稱 必要 類型 Description
query True

string

要執行的查詢。

timespan

string

選擇性。 要查詢數據的時間範圍。 這是ISO8601時間週期值。 除了查詢表達式中指定的任何時間範圍之外,還會套用這個時間範圍。

workspaces

string[]

查詢中包含的工作區清單。

回應

名稱 類型 Description
200 OK

queryResults

正常。 API 呼叫成功,且 Analytics 查詢結果位於響應承載中

Other Status Codes

errorResponse

錯誤回應物件。

安全性

oauth2

Azure Active Directory OAuth2 Flow

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

Scopes

名稱 Description
user_impersonation 模擬您的用戶帳戶

範例

cross-workspace
simple-query

cross-workspace

Sample Request

POST https://api.loganalytics.io/v1/workspaces/63613592-b6f7-4c3d-a390-22ba13102111/query

{
  "query": "union * | where TimeGenerated > ago(1h) | summarize count() by Type, TenantId",
  "workspaces": [
    "draft-test",
    "draft-test-2"
  ]
}

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

POST https://api.loganalytics.io/v1/workspaces/63613592-b6f7-4c3d-a390-22ba13102111/query

{
  "query": "Usage | take 10",
  "timespan": "PT12H"
}

Sample Response

{
  "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"
        ]
      ]
    }
  ]
}

定義

名稱 Description
column

數據表數據行。

errorDetail

錯誤詳細數據。

errorInfo

錯誤的程式代碼和訊息。

errorResponse

錯誤詳細數據。

logsColumnType

此數據行的數據類型。

queryBody

分析查詢。 深入瞭解 Analytics 查詢語法

queryResults

查詢回應。

Render

JSON 格式的視覺效果數據。

Statistics

以 JSON 格式表示的統計數據。

table

查詢回應表。

column

數據表數據行。

名稱 類型 Description
name

string

此資料行的名稱。

type

logsColumnType

此數據行的數據類型。

errorDetail

錯誤詳細數據。

名稱 類型 Description
additionalProperties

object

可在錯誤詳細數據物件上提供的其他屬性

code

string

錯誤的程序代碼。

message

string

人類可讀取的錯誤訊息。

resources

string[]

指出負責錯誤的資源。

target

string

指出要求中的哪個屬性負責錯誤。

value

string

指出 『target』 中的哪個值負責錯誤。

errorInfo

錯誤的程式代碼和訊息。

名稱 類型 Description
additionalProperties

object

可在錯誤信息物件上提供的其他屬性

code

string

計算機可讀取的錯誤碼。

details

errorDetail[]

錯誤詳細數據。

innererror

errorInfo

錯誤的程式代碼和訊息。
如果內部錯誤詳細資料存在,則為 。

message

string

人類可讀取的錯誤訊息。

errorResponse

錯誤詳細數據。

名稱 類型 Description
error

errorInfo

錯誤的程式代碼和訊息。
錯誤詳細資料。

logsColumnType

此數據行的數據類型。

名稱 類型 Description
bool

string

datetime

string

decimal

string

dynamic

string

guid

string

int

string

long

string

real

string

string

string

timespan

string

queryBody

分析查詢。 深入瞭解 Analytics 查詢語法

名稱 類型 Description
query

string

要執行的查詢。

timespan

string

選擇性。 要查詢數據的時間範圍。 這是ISO8601時間週期值。 除了查詢表達式中指定的任何時間範圍之外,還會套用這個時間範圍。

workspaces

string[]

查詢中包含的工作區清單。

queryResults

查詢回應。

名稱 類型 Description
error

errorInfo

錯誤的程式代碼和訊息。

render

Render

JSON 格式的視覺效果數據。

statistics

Statistics

以 JSON 格式表示的統計數據。

tables

table[]

數據表、資料列和數據列的清單。

Render

JSON 格式的視覺效果數據。

Statistics

以 JSON 格式表示的統計數據。

table

查詢回應表。

名稱 類型 Description
columns

column[]

此資料表中的數據列清單。

name

string

資料表的名稱。

rows

object[]

此查詢所產生的數據列。