为 Azure API 管理自承载网关配置云指标和日志Configure cloud metrics and logs for Azure API Management self-hosted gateway
本文详细介绍了如何为自承载网关配置云指标和日志。This article provides details for configuring cloud metrics and logs for the self-hosted gateway.
自承载网关必须与 API 管理服务关联,并要求在端口 443 上与 Azure 建立出站 TCP/IP 连接。The self-hosted gateway has to be associated with an API management service and requires outbound TCP/IP connectivity to Azure on port 443. 该网关利用出站连接将遥测发送到 Azure(如果配置为这样做)。The gateway leverages the outbound connection to send telemetry to Azure, if configured to do so.
指标Metrics
默认情况下,自承载网关通过 Azure Monitor 发出大量指标,与云中的托管网关相同。By default, the self-hosted gateway emits a number of metrics through Azure Monitor, same as the managed gateway in the cloud.
可使用网关部署的 ConfigMap 中的 telemetry.metrics.cloud
键启用或禁用该功能。The feature can be enabled or disabled using the telemetry.metrics.cloud
key in the ConfigMap of the gateway Deployment. 以下是可用配置的详细信息:Below is a breakdown of the available configurations:
字段Field | 默认Default | 说明Description |
---|---|---|
telemetry.metrics.cloudtelemetry.metrics.cloud | true |
通过 Azure Monitor 启用日志记录。Enables logging through Azure Monitor. 值可以是 true 、false 。Value can be true , false . |
下面是示例配置:Here is a sample configuration:
apiVersion: v1
kind: ConfigMap
metadata:
name: contoso-gateway-environment
data:
config.service.endpoint: "<contoso-gateway-management-endpoint>"
telemetry.metrics.cloud: "true"
自承载网关当前通过 Azure Monitor 发出以下指标:The self-hosted gateway currently emits the following metrics through Azure Monitor:
指标Metric | 说明Description |
---|---|
请求Requests | 期间内的 API 请求数Number of API requests in the period |
网关请求的持续时间Duration of gateway requests | 从网关收到请求到响应全部发送出去经过的时间(毫秒)Number of milliseconds from the moment gateway received request until the moment response sent in full |
后端请求持续时间Duration of backend requests | 花在整个后端 IO(连接、发送和接收字节)上的时间(毫秒)Number of milliseconds spent on overall backend IO (connecting, sending and receiving bytes) |
日志Logs
自承载网关当前不向云发送诊断日志。The self-hosted gateway currently does not send diagnostic logs to the cloud. 但是,可以在部署自承载网关本地配置和保存日志。However, it is possible to configure and persist logs locally where the self-hosted gateway is deployed.
如果网关部署在 Azure Kubernetes 服务中,则可以启用适用于容器的 Azure Monitor,从容器收集日志并查看 Log Analytics 中的日志。If a gateway is deployed in Azure Kubernetes Service, you can enable Azure Monitor for containers to collect logs from your containers and view them in Log Analytics.
后续步骤Next steps
- 若要详细了解自承载网关,请参阅 Azure API 管理自承载网关概述To learn more about the self-hosted gateway, see Azure API Management self-hosted gateway overview
- 了解在本地配置和保存日志Learn about configuring and persisting logs locally