記錄、指標和追蹤記錄

本文說明安全網路 Proxy 如何記錄作業資料、如何使用 Cloud Monitoring API 指標分析 Proxy 效能,以及如何使用分散式追蹤功能觀察要求生命週期。

記錄

Secure Web Proxy 會使用 Cloud Logging,讓您擷取資訊,並在下列重要領域執行各種工作:

  • 監控與法規遵循

    • 強制遵守法規、提升網路安全性,以及掌握傳送至允許外部目的地的傳出網路流量。
    • 取得多層控管機制,並掌握工作負載流量。
    • 取得重要洞察資訊,有效監控資安營運中心 (SOC)。
    • 使用記錄檔偵測及追蹤安全性事件,主動因應威脅。
  • 部署與設定

    • 追蹤初始基礎架構設定、使用者帳戶建立和設定變更。
    • 監控潛在錯誤,確保部署作業順利安全。
    • 瞭解政策調整的影響,並最佳化防護措施。

記錄類型

Secure Web Proxy 會使用 Logging 擷取及儲存下列類型的記錄:

  • Cloud 稽核記錄:擷取 Secure Web Proxy 資源的管理變更和資料存取。這些記錄包括:

  • Proxy 交易記錄:擷取 Secure Web Proxy 處理的特定網頁要求詳細資料。這些記錄可讓您深入瞭解 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 專案的 ID
  • REGION: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。

高延遲要求警示

使用下列查詢,在要求超過特定延遲時間 (例如五秒) 時收到通知:

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 資源或 Secure Web Proxy 執行個體。

詳情請參閱「使用記錄檔探索工具」。

記錄項目範例

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 的每個 Proxy 交易記錄項目都包含 trace 欄位,其中含有 Google Cloud 追蹤記錄資源字串:

<pre class="devsite-click-to-copy">
"trace": "projects/PROJECT_ID/traces/TRACE_ID"
</pre>

更改下列內容:

  • PROJECT_ID: Google Cloud 專案 ID
  • TRACE_ID:用戶端或追蹤記錄範圍的 128 位元 (32 個字元十六進位) 追蹤記錄 ID。例如:4bf92f3577b34da6a3ce929d0e0e4736。

您可以使用這個追蹤記錄 ID,將記錄項目與對應的追蹤記錄 span 建立關聯:

  • 從 Logs 到 Trace:在 Logs Explorer 中,按一下任何記錄項目的 trace 欄位,然後選取「View trace details」(查看追蹤記錄詳細資料),即可在 Trace 中開啟完整的要求瀑布圖。
  • 從追蹤記錄到記錄檔:在 Trace 中,按一下「Trace Details」(追蹤記錄詳細資料) 窗格中的「Show logs」(顯示記錄檔),即可查看與追蹤記錄相關聯的所有 Proxy 交易記錄。

詳情請參閱「使用 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 Proxy 處理的要求總數。
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 執行個體的效能和流量趨勢,請按照下列步驟操作:

  1. 在 Google Cloud 控制台中,前往「Dashboards」(資訊主頁) 頁面。

    前往「Dashboards」(資訊主頁)

  2. 按一下「 建立自訂資訊主頁」。

  3. 按一下「 新增小工具」,然後選取「折線圖」選項。

  4. 在「Metric」(指標) 欄位中,搜尋 networkservices.googleapis.com/https/request_count。

  5. 如果您設定了多個 Secure Web Proxy 執行個體,可以在「Filter」(篩選器) 欄位中依 gateway_id 篩選。

  6. 在「Aggregation」(匯總) 區段中,將「Alignment Period」(校正週期) 設為 1 minute,並為「Aligner」(校正器) 選取 rate。

    這項操作會將原始要求資料轉換為每秒要求率,方便您查看及分析一段時間內的一致流量趨勢。

  7. 如要儲存小工具,請按一下「套用」。

後續步驟