使用 PowerShell 在 Application Insights 上运行查询包项目

问题描述 投票:0回答:1

使用以下步骤,可以从 Default Query Pack

 上的 PowerShell 运行存储在 
Log Analytics Workspace
 中的 Kusto 查询。

$baseUrl  = "https://management.azure.com"
$RId      = (Get-AzResource -ResourceGroupName LogAnalyticsDefaultResources -Name DefaultQueryPack).ResourceId
$token    = (Get-AzAccessToken -ResourceUrl $baseUrl).Token
$response = Invoke-RestMethod -Uri "$baseUrl$RId/queries?api-version=2019-09-01" -Method Get -Headers @{Authorization = "Bearer $token"}

$response.value.properties.displayname  # Display names
#Runs the first query in the pack
Invoke-AzOperationalInsightsQuery -Query ($response.value)[0].properties.body -WorkspaceId <>

如何使用

Invoke-AzOperationalInsightsQuery
从连接到 Application Insights
Log Analytics Workspace 上的默认包运行查询?运行 AppInsights 查询时,我得到
Operation returned an invalid status code 'BadRequest'

azure-application-insights azure-powershell kql azure-log-analytics azure-monitoring
1个回答
0
投票

如何使用 Invoke-AzOperationalInsightsQuery 从连接到

Application Insights
Log Analytics Workspace
上的默认包运行查询?

您可以使用

Invoke-AzOperationalInsightsQuery
在 Log Analytics 工作区上运行查询,如下所示:

Connect-AzAccount -SubscriptionId 'b83c1ed3'
$rith_workspaceId = "3c62e221"
$rith_query = @"
AzureMetrics
"@

Invoke-AzOperationalInsightsQuery -WorkspaceId $rith_workspaceId  -Query $rith_query

enter image description here

以上

Invoke-AzOperationalInsightsQuery
仅适用于 Log Analytics 工作区及其表,不适用于 Application Insights 及其表。

在上面的 Azure Metrics 中,您可以使用从

($response.value)[-1].properties.body

的输出中获得的查询

enter image description here

如果您想对应用程序见解运行查询,您可以遵循此SO-Thread

$query
的值可以赋值给(
$response.value)[0].properties.body
。也可以使用cli命令.

© www.soinside.com 2019 - 2024. All rights reserved.