为什么 az monitor app-insights 尝试使用 cp1252 进行编码?

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

我正在尝试检索一些应用程序见解,因此我发出一个基本查询

$QUERY = @"
traces
| where timestamp >= ago(1h)
| order by timestamp desc, itemId asc
| limit 2
"@
$resultJson = az monitor app-insights query --app $APP_ID --analytics-query $QUERY

我收到此警告

WARNING: Unable to encode the output with cp1252 encoding. Unsupported characters are discarded.

我看到这只是一个警告,但我正在尝试解决为什么我收到数百个日志条目,即使我只要求两个。

我也尝试过设置编码:

$env:AZURE_CLI_ENCODING = "UTF-8"

关于我可以尝试什么的任何指示?;)

azure azure-application-insights
1个回答
0
投票

首先,您正在执行的 CLI 脚本方法没有问题。并且将编码格式设置为

$env:AZURE_CLI_ENCODING = "UTF-8"
也是一个正确的做法。

警告:无法使用 cp1252 编码对输出进行编码:

由于您仍然面临这里的冲突,您可以尝试将编码设置为

[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
详细信息请参阅这篇 SO 帖子。

为什么我收到数百个日志条目,即使我只要求两个:

不要使用

limit
运算符,而是尝试使用
take
运算符
,它相当于 kql 中的限制运算符。

它还将返回如上所述的指定行数。

take
limit
运算符是等效的。

我尝试了以下方法来满足要求,并且能够成功实现。

traces
| where timestamp >= ago(1h)
| order by timestamp desc, itemId asc
| take 2

--output Json
添加到 CLI 命令的末尾,如下所示。

$APP_ID="xxxxx"
$resultJson = az monitor app-insights query --app $APP_ID --analytics-query $QUERY --output Json

enter image description here

如果问题仍然存在,请尝试将查询与

--analytics-query
直接参数,而不是将其存储在变量中。

az monitor app-insights query --app "b7xxxae67b" --analytics-query 'traces | where timestamp >= ago(1h) | order by timestamp desc, itemId asc | limit 2'

enter image description here

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