如何将DIAGSESSION/ETW/ETL文件从Azure拉入管道

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

对于上下文,我有在 Azure 上托管/监控的 API,并启用了探查器。

我想知道是否可以从应用程序洞察分析器获取 DIAGSESSION/ETW/ETL 文件,并在通过管道执行测试并收集例如具有最高错误、响应时间等的分析数据后将其自动化?我该怎么做呢?

我希望它能够访问并下载代理/虚拟机上的文件,因此我不确定是否可以在无需访问浏览器并登录和下载的情况下提取信息。

我计划制作一个 powershell 脚本来获取此文件并在 perfview/WPA 上为我生成特定的图表

azure powershell azure-pipelines performance-testing etw
1个回答
0
投票

不幸的是,您要查找的文件保留在计算机本地。

如果应用程序配置为 App Insights,则遥测数据会实时传输。

进入 App Insights 后,必须使用 Kusto 查询语言 (KQL) 进行查询。

因此,可以使用令牌从 Application Insights API 以编程方式检索数据,但您必须确定正确的查询来检索所需的数据。

要以编程方式或脚本访问 API,您需要创建或使用现有服务主体进行身份验证。有很多关于如何执行此操作的文章。

以下是您可以使用 PowerShell 进行调用以执行简单查询的简单示例:

# Install Az module if not installed
if (-not (Get-Module -ListAvailable -Name Az)) {
    Install-Module -Name Az -Scope CurrentUser -Force -SkipPublisherCheck
}

# Login to Azure using service principal credentials
$tenantId = "yourAzureTenantId"
$clientId = "yourServicePrincipalClientId"
$clientSecret = "yourServicePrincipalClientSecret"

$secureClientSecret = ConvertTo-SecureString -String $clientSecret -AsPlainText -Force
$credential = New-Object -TypeName PSCredential -ArgumentList $clientId, $secureClientSecret

Connect-AzAccount -ServicePrincipal -Credential $credential -Tenant $tenantId

# Variables
$appInsightsAppId = "yourApplicationInsightsAppId"
$resourceGroupName = "yourResourceGroupName"
$appName = "yourAppName"

# Acquire Azure AD token
$token = (Get-AzAccessToken -ResourceUrl "https://api.applicationinsights.io/").Token
$headers = @{
    "Authorization" = "Bearer $token"
}
# Example query
$kustoQuery = "requests | where timestamp > ago(24h) | project session_Id, operation_Id | top 1"

$queryUrl = "https://api.applicationinsights.io/v1/apps/$appInsightsAppId/query?query=$kustoQuery"

$response = Invoke-RestMethod -Uri $queryUrl -Headers $headers -Method Get

# Get data in API response body (json)
$sessionId = $response.value[0].session_Id
$operationId = $response.value[0].operation_Id
© www.soinside.com 2019 - 2024. All rights reserved.