本文档介绍了 Secure Web Proxy 如何记录其运维数据、如何使用 Cloud Monitoring API 指标分析代理性能,以及如何使用分布式跟踪来观察请求生命周期。
日志
Secure Web Proxy 使用 Cloud Logging,让您可以在以下关键领域捕获信息并执行各种任务:
监控和合规性
- 强制遵守法规、提高网络安全性,并提供对发送到允许的外部目的地的出站 Web 流量的可见性。
- 获得对工作负载流量的宝贵控制和可见性。
- 获得重要的数据洞见,以便进行有效的安全运维中心 (SOC) 监控。
- 使用日志检测和跟踪安全性事件,以主动应对威胁。
部署和配置
- 跟踪初始基础设施设置、用户账号创建和配置更改。
- 监控潜在错误,帮助确保部署顺利、安全。
- 了解政策调整的影响并优化保护措施。
日志类型
Secure Web Proxy 使用 Logging 来捕获和存储以下类型的日志:
Cloud Audit Logs:捕获对 Secure Web Proxy 资源的管理更改和数据访问。这些日志包括:
代理事务日志:捕获有关 Secure Web Proxy 处理的特定 Web 请求的详细信息。这些日志可让您深入了解 Secure Web Proxy 实例的流量、政策强制执行情况和性能。当您将 Secure Web Proxy 实例部署为 Agent Gateway 时,事务日志会继续记录在标准
networkservices.googleapis.com/Gateway受监控的资源下,并自动显示 AI 智能体执行元数据 (agentGatewayInfo)。
配置日志提醒
您可以针对 Secure Web Proxy 写入 Logging 的事件(例如流量拒绝或特定规则匹配)配置提醒。如需了解如何设置这些提醒的一般说明,请参阅配置基于日志的提醒。
以下是一些可用于为 Secure Web Proxy 配置基于日志的提醒的查询示例:
针对被 Secure Web Proxy 政策拒绝的流量发出提醒
当 Secure Web Proxy 政策拒绝请求时,使用以下查询触发提醒:
logName="projects/PROJECT_ID/logs/networkservices.googleapis.com%2Fgateway_requests" resource.type="networkservices.googleapis.com/Gateway" jsonPayload.enforcedGatewaySecurityPolicy.matchedRules.action="DENIED"
将 PROJECT_ID 替换为目标Google Cloud 项目的 ID。
针对被 Secure Web Proxy 规则拒绝的流量的提醒
当特定 Secure Web Proxy 规则(例如 my-specific-deny-rule)拒绝请求时,使用以下查询触发提醒:
logName="projects/PROJECT_ID/logs/networkservices.googleapis.com%2Fgateway_requests" resource.type="networkservices.googleapis.com/Gateway" jsonPayload.enforcedGatewaySecurityPolicy.matchedRules.action="DENIED" AND jsonPayload.enforcedGatewaySecurityPolicy.matchedRules.name=~"projects/PROJECT_ID/locations/REGION/gatewaySecurityPolicies/POLICY_NAME/rules/my-specific-deny-rule$"
替换以下内容:
PROJECT_ID:目标 Google Cloud 项目的 IDREGION:Secure Web Proxy 实例的区域POLICY_NAME:Secure Web Proxy 政策的名称
针对 Agent Gateway 授权政策拒绝的流量发出提醒
将 Secure Web Proxy 实例部署为 Agent Gateway时,请使用以下查询在授权政策拒绝 AI 智能体的请求时触发提醒:
logName="projects/PROJECT_ID/logs/networkservices.googleapis.com%2Fgateway_requests" resource.type="networkservices.googleapis.com/Gateway" jsonPayload.authzPolicyInfo.result="DENIED"
将 PROJECT_ID 替换为目标Google Cloud 项目的 ID。
针对服务速率限制政策限制的流量发出提醒
使用以下查询可在服务速率限制政策限制请求时触发提醒:
logName="projects/PROJECT_ID/logs/networkservices.googleapis.com%2Fgateway_requests" resource.type="networkservices.googleapis.com/Gateway" jsonPayload.rateLimitPolicyInfo.overallResult="THROTTLED"
将 PROJECT_ID 替换为目标Google Cloud 项目的 ID。
针对高延迟请求发出提醒
使用以下查询可在请求超过特定延迟时间(例如 5 秒)时收到通知:
logName="projects/'PROJECT_ID'/logs/networkservices.googleapis.com%2Fgateway_requests" resource.type="networkservices.googleapis.com/Gateway" latency >= "5s"
将 PROJECT_ID 替换为目标Google Cloud 项目的 ID。
在 Cloud Logging 中查看日志
在 Google Cloud 控制台中,前往 Logs Explorer 页面。
选择您的 Google Cloud 项目。
使用下拉菜单选择
networkservices.googleapis.com/Gateway资源或 Secure Web Proxy 实例。
如需了解详情,请参阅使用 Logs Explorer。
日志条目示例
Secure Web Proxy 每次处理请求时都会生成详细的日志条目,以跟踪其操作和适用政策。以下示例展示了 Secure Web Proxy 日志的工作原理。
允许日志条目示例
以下日志条目显示 Secure Web Proxy 实例拦截并检查了 www.example.com 的 HTTPS 流量,然后允许其继续访问目标网站。政策和规则名称分别为 swp-policy 和 allow-port-443。
| 字段 | 值 |
|---|---|
enforcedGatewaySecurityPolicy |
{
"requestWasTlsIntercepted": true,
"hostname": "www.example.com",
"matchedRules": [
{
"action": "ALLOWED",
"name": "projects/76537/locations/us-central1/gatewaySecurityPolicies/swp-policy/rules/allow-port-443"
}
]
} |
httpRequest |
{
"requestMethod": "GET",
"requestUrl": "https://www.example.com/",
"requestSize": "41",
"status": 200,
"responseSize": "1446",
"userAgent": "curl/7.74.0",
"remoteIp": "10.128.0.12:35418",
"serverIp": "93.184.216.34:443",
"latency": "0.051800s",
"protocol": "HTTP/2"
} |
resource |
{
"type": "networkservices.googleapis.com/Gateway",
"labels": {
"gateway_name": "multi-level-tlds",
"network_name": "projects/76537/global/networks/default",
"location": "us-central1",
"resource_container": "",
"gateway_type": "SECURE_WEB_GATEWAY"
}
} |
timestamp |
"2024-02-15T16:56:19.570534Z" |
severity |
"INFO" |
logName |
"projects/76537/logs/networkservices.googleapis.com%2Fgateway_requests" |
receiveTimestamp |
"2024-02-15T16:56:20.714988329Z" |
拒绝日志条目示例
此日志条目显示,Secure Web Proxy 实例检查了 www.example.com:443 的流量,并因 Secure Web Proxy 政策中的 default_denied 规则而拒绝了 HTTPS 请求。
| 字段 | 值 |
|---|---|
enforcedGatewaySecurityPolicy |
{
"hostname": "www.example.com:443",
"matchedRules": [
{
"name": "default_denied",
"action": "DENIED"
}
]
} |
httpRequest |
{
"requestMethod": "CONNECT",
"requestSize": "122",
"status": 403,
"responseSize": "141",
"userAgent": "curl/7.74.0",
"remoteIp": "10.128.0.12:36338",
"latency": "0.000133s",
"protocol": "HTTP/1.1"
} |
resource |
{
"type": "networkservices.googleapis.com/Gateway",
"labels": {
"gateway_type": "SECURE_WEB_GATEWAY",
"resource_container": "",
"location": "us-central1",
"network_name": "projects/gcp-1768/global/networks/default",
"gateway_name": "high-latency-repro"
}
} |
timestamp |
"2024-02-15T16:55:00.089727Z" |
severity |
“WARNING” |
logName |
"projects/gcp-1768/logs/networkservices.googleapis.com%2Fgateway_requests" |
receiveTimestamp |
"2024-02-15T16:55:04.456901833Z" |
服务速率限制政策日志条目示例
以下日志条目显示,Secure Web Proxy 实例限制了请求,因为客户端超出了 rl_default_rpm_limit RateLimitBucket 下的 RateLimitPolicy(名为 rl-egress-policy)。
| 字段 | 值 |
|---|---|
rateLimitPolicyInfo |
{
"policies": [
{
"name": "projects/76537/locations/us-central1/rateLimitPolicies/rl-egress-policy",
"buckets": [
{
"bucket": "rl_default_rpm_limit",
"key": "spiffe://projects-123.global.workload.id.goog/ns/ns1/sa/hellomcp",
"result": "THROTTLED"
}
],
"result": "THROTTLED",
"details": "Default user rate limit rate exceeded client-side."
}
],
"overallResult": "THROTTLED"
} |
httpRequest |
{
"requestMethod": "POST",
"requestUrl": "https://example.com/v1/chat/completions",
"requestSize": "144",
"status": 429,
"responseSize": "85",
"userAgent": "curl/7.74.0",
"remoteIp": "10.128.0.12:35418",
"serverIp": "93.184.216.34:443",
"latency": "0.001200s",
"protocol": "HTTP/2"
} |
resource |
{
"type": "networkservices.googleapis.com/Gateway",
"labels": {
"gateway_type": "SECURE_WEB_GATEWAY",
"resource_container": "",
"location": "us-central1",
"network_name": "projects/76537/global/networks/default",
"gateway_name": "egress-swp-gateway"
}
} |
timestamp |
"2026-02-15T16:56:19.570534Z" |
severity |
“WARNING” |
logName |
"projects/76537/logs/networkservices.googleapis.com%2Fgateway_requests" |
receiveTimestamp |
"2026-02-15T16:56:20.714988329Z" |
使用 Cloud Trace 执行分布式跟踪
Secure Web Proxy 支持与 Trace 集成的内置分布式请求跟踪。
日志-跟踪记录关联
写入 Logging 的每个代理事务日志条目都包含一个 trace 字段,其中包含 Google Cloud 跟踪记录资源字符串:
<pre class="devsite-click-to-copy">
"trace": "projects/PROJECT_ID/traces/TRACE_ID"
</pre>
替换以下内容:
PROJECT_ID:您的 Google Cloud 项目的 IDTRACE_ID:来自客户端或跟踪记录 span 的 128 位(32 个字符的十六进制)跟踪记录 ID。例如4bf92f3577b34da6a3ce929d0e0e4736。
您可以使用此跟踪记录 ID 将日志条目与其对应的跟踪记录 span 相关联:
- 从日志到跟踪记录:在 Logs Explorer 中,点击任意日志条目的
trace字段,然后选择查看跟踪记录详细信息,以在 Trace 中打开完整的请求瀑布图。 - 从跟踪记录到日志:在 Trace 中,点击跟踪记录详细信息窗格中的显示日志,以查看与跟踪记录关联的所有代理事务日志。
如需了解详情,请参阅使用 Trace 进行分布式跟踪。
指标
Cloud Monitoring API 指标可帮助您观察 Secure Web Proxy 实例的性能、运行状况和使用情况。
受监控的资源
Secure Web Proxy 的指标会在以下受监控资源下导出:
networkservices.googleapis.com/Gateway:表示 Secure Web Proxy 网关实例。
下表介绍了 networkservices.googleapis.com/Gateway 的可用资源。您可以使用这些资源来过滤和汇总监控数据。
| 标签 | 说明 |
|---|---|
resource_container |
与 Secure Web Proxy 网关实例关联的项目的 ID。 |
location |
Google Cloud 网关部署到的区域。 |
gateway_id |
Secure Web Proxy 网关实例的唯一名称。 |
gateway_type |
网关类型,设置为 SECURE_WEB_GATEWAY。 |
network_name |
与网关关联的虚拟私有云 (VPC) 网络的名称。 |
可用指标
Gateway 资源可使用以下指标。所有指标都以 networkservices.googleapis.com/https/ 为前缀。
| 指标类型 | 显示名称 | 种类、类型、单元 | 说明 |
|---|---|---|---|
networkservices.googleapis.com/https/request_count |
请求数 | DELTA、INT64、1 |
代理处理的请求总数。 |
networkservices.googleapis.com/https/request_bytes_count |
请求字节数 | DELTA、INT64、By |
请求中收到的字节总数。 |
networkservices.googleapis.com/https/response_bytes_count |
响应字节数 | DELTA、INT64、By |
响应中发送的总字节数。 |
networkservices.googleapis.com/https/total_latencies |
总延迟时间 | DELTA、DIST、ms |
从收到请求的第一个字节到发送响应的最后一个字节所用的时间。 |
networkservices.googleapis.com/https/backend_latencies |
后端延迟时间 | DELTA、DIST、ms |
从请求发送到后端到收到响应的第一个字节所用的时间。 |
创建自定义信息中心
如需构建自定义信息中心以直观呈现 Secure Web Proxy 实例的性能和流量趋势,请执行以下操作:
在 Google Cloud 控制台中,前往信息中心页面。
点击 创建自定义信息中心。
点击 添加 widget,然后选择折线图选项。
在指标字段中,搜索
networkservices.googleapis.com/https/request_count。如果您配置了多个 Secure Web Proxy 实例,则可以在过滤条件字段中按
gateway_id进行过滤。在聚合部分中,将对齐周期设置为
1 minute,并为对齐器选择rate。这会将原始请求数据转换为每秒请求数,从而更轻松地查看和分析一段时间内的一致流量趋势。
如需保存该微件,请点击应用。