Azure 应用程序网关 - 故障排除?

Azure Application gateway - trouble shooting?

我已经在 Azure kubernetes 上部署了我的应用程序,我正在使用 Azure 应用程序网关来公开服务。

我想跟踪传入的请求以了解完整的执行过程。 eg:应用网关处理请求需要多长时间。

有什么方法可以在 Azure 应用程序网关中跟踪单个请求吗?

首先你必须启用日志,参见the docs

You can use different types of logs in Azure to manage and troubleshoot application gateways. You can access some of these logs through the portal. All logs can be extracted from Azure Blob storage and viewed in different tools, such as Azure Monitor logs, Excel, and Power BI. You can learn more about the different types of logs from the following list:

  • Performance log: You can use this log to view how Application Gateway instances are performing. This log captures performance information for each instance, including total requests served, throughput in bytes, total requests served, failed request count, and healthy and unhealthy back-end instance count. A performance log is collected every 60 seconds. The Performance log is available only for the v1 SKU. For the v2 SKU, use Metrics for performance data.
  • Access log: You can use this log to view Application Gateway access patterns and analyze important information. This includes the caller's IP, requested URL, response latency, return code, and bytes in and out. An access log is collected every 60 seconds. This log contains one record per instance of Application Gateway. The Application Gateway instance is identified by the instanceId property.

如果允许将日志写入 Azure Log Analytics 工作区,则可以执行如下查询:

AzureDiagnostics
| where Category == "ApplicationGatewayAccessLog"  
| project timeStamp_t, requestUri_s, httpMethod_s, httpStatus_d, receivedBytes_d, sentBytes_d, timeTaken_d

它会向您显示如下内容: