如何使用 Application Insights 查询查询多个 Azure API 管理 API 名称

发布时间:2021-03-02 10:41

您好,我正在努力通过 Azure API 管理获取请求,但是我正在获取所有现有的 api。我只想过滤我需要的 api

这是我所做的:

requests
|summarize totalCount=sum(itemCount) by bin(timestamp,15m),toString(customDimensions.["API Name"])
where (toString(customDimensions.["API Name"]) == "api1" && "api2"
|render timechart

当我测试它时,它告诉我状态:有些东西坏了,我怎样才能从所有人中过滤出我需要的 api

回答1

将查询更改为

requests
| extend apiName = tostring(customDimensions.["API Name"])
| summarize totalCount=sum(itemCount) by bin(timestamp,15m),apiName
| where apiName in ("api1", "api2")
| render timechart
回答2

要深入了解请求,您需要了解应用程序。您可以将 ApplicationInsights 链接到 APIM 实例以进行监控。

在 Azure 中创建 Application Insights 并复制生成的 Instrumentation key

浏览到 APIM 资源,滚动到 Monitoring 部分以选择 Application Insights。使用上面复制的 Instrumentation key

默认情况下,所有传入和传出的监控未开启。要启用它,请在 APIM 中滚动到 API 部分以选择 APIs。在顶部选择设置并启用 Application Insights。 enter image description here

现在一切准备就绪,可以监控您的 API。

回答3

在 azure 文档中找到了解决方案。 该语言称为kusto 这是文档的链接:Azure Kusto Query language

requests
| extend apiName = tostring(customDimensions.["API Name"])
| summarize totalCount=sum(itemCount) by bin(timestamp,15m),apiName
| where apiName in ("api1", "api2")
| render timechart
回答4

在配置 Application Insights 诊断日志时,不要忘记将有效负载字节数设置为足够的值。这将为您提供来自您正在监控的请求和响应的更多信息。

enter image description here

appinsights 相关推荐