日志和指标

本页介绍了安全 Web 代理如何记录有关其运行的各种类型的信息,以及如何使用 Cloud Monitoring API 指标分析代理的性能。

日志

安全 Web 代理使用 Cloud Logging,让您能够捕获信息并执行以下关键领域的各种任务:

  • 监控和合规性

    • 强制执行法规遵从性,提高网络安全性,并提供对发送到允许的外部出站网络流量的可见性。
    • 获得对工作负载流量的宝贵控制权和可见性。
    • 获得关键洞见,以便有效监控安全运维中心 (SOC)。
    • 使用日志检测和跟踪安全事件,以便主动应对威胁。
  • 部署和配置

    • 跟踪初始基础设施设置、用户账号创建和配置更改。
    • 监控潜在错误,以确保部署顺利安全。
    • 了解政策调整的影响,并优化保护措施。

日志类型

安全 Web 代理使用 Logging 来捕获和存储以下类型的日志:

  • Cloud Audit Logs:捕获对安全 Web 代理资源的管理变更和数据访问。这些日志包括:

  • 代理事务日志:捕获有关安全 Web 代理处理的特定 Web 请求的详细信息。这些日志可提供有关安全 Web 代理实例的流量流、政策执行情况和性能的分析洞见。

配置日志提醒

您可以为安全 Web 代理写入日志记录的事件(例如流量拒绝或特定规则匹配)配置提醒。如需有关如何设置这些提醒的一般说明,请参阅配置基于日志的提醒

以下是一些可用于为安全 Web 代理配置基于日志的提醒的查询示例:

安全 Web 代理政策拒绝流量的提醒

使用以下查询可在安全 Web 代理政策拒绝请求时触发提醒:

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。

安全 Web 代理规则拒绝流量时的提醒

使用以下查询可在特定安全 Web 代理规则(例如 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 项目的 ID
  • REGION:Secure Web Proxy 实例的区域
  • POLICY_NAME:安全 Web 代理政策的名称

针对高延迟时间请求的提醒

使用以下查询可在请求延迟时间超过某个值(例如 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 中查看日志

  1. 在 Google Cloud 控制台中,前往 Logs Explorer 页面。

    转到 Logs Explorer

  2. 选择您的 Google Cloud 项目。

  3. 使用下拉菜单选择 networkservices.googleapis.com/Gateway 资源或您的安全 Web 代理实例。

如需了解详情,请参阅使用日志浏览器

日志条目示例

安全 Web 代理每次处理请求时都会生成详细的日志条目,记录其操作和应用的政策。以下示例展示了安全 Web 代理日志的工作原理。

允许日志条目示例

以下日志条目显示,Secure Web Proxy 实例拦截并检查了 www.example.com 的 HTTPS 流量,然后允许该流量继续流向目标网站。政策名称和规则名称分别为 swp-policyallow-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"

拒绝日志条目示例

此日志条目显示,安全 Web 代理实例检查了 www.example.com:443 的流量,并因安全 Web 代理政策中的 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"

指标

Cloud Monitoring API 指标可帮助您观察安全 Web 代理实例的性能、运行状况和使用情况。

受监控的资源

安全 Web 代理的指标会导出到以下受监控的资源:

  • networkservices.googleapis.com/Gateway:表示安全 Web 代理网关实例。

下表介绍了 networkservices.googleapis.com/Gateway 的可用资源。您可以使用这些资源来过滤和汇总监控数据。

标签 说明
resource_container 与安全 Web 代理网关实例关联的项目的 ID。
location Google Cloud 部署网关的区域。
gateway_id Secure Web Proxy 网关实例的唯一名称。
gateway_type 网关类型,设置为 SECURE_WEB_GATEWAY
network_name 与网关关联的 Virtual Private Cloud (VPC) 网络的名称。

可用指标

以下指标适用于 Gateway 资源。所有指标都以 networkservices.googleapis.com/https/ 为前缀。

指标类型 显示名 种类、类型、单元 说明
networkservices.googleapis.com/https/request_count 请求数 DELTAINT641 代理处理的请求总数。
networkservices.googleapis.com/https/request_bytes_count 请求字节数 DELTAINT64By 请求中收到的总字节数。
networkservices.googleapis.com/https/response_bytes_count 响应字节数 DELTAINT64By 响应中发送的字节总数。
networkservices.googleapis.com/https/total_latencies 总延迟时间 DELTADISTms 从收到请求的第一个字节开始,直到发送响应的最后一个字节为止的时间。
networkservices.googleapis.com/https/backend_latencies 后端延迟时间 DELTADISTms 从向后端发送请求开始,直到收到响应的第一个字节为止的时间。

创建自定义信息中心

如需构建自定义信息中心来直观呈现安全 Web 代理实例的性能和流量趋势,请执行以下操作:

  1. 在 Google Cloud 控制台中,前往信息中心页面。

    转到“信息中心”

  2. 点击 创建自定义信息中心

  3. 点击 添加 widget,然后选择折线图选项。

  4. 指标字段中,搜索 networkservices.googleapis.com/https/request_count

  5. 过滤条件字段中,如果您配置了多个安全 Web 代理实例,则可以按 gateway_id 进行过滤。

  6. 聚合部分中,将校准时间段设置为 1 minute,并为校准器选择 rate

    这会将原始请求数据转换为每秒请求数,从而更轻松地查看和分析随时间变化的一致流量趋势。

  7. 如需保存该 widget,请点击应用

后续步骤