記錄、指標和追蹤記錄

本文說明 Secure Web 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 執行個體的流量、政策執行情形和效能。

設定記錄檔快訊

您可以針對安全網頁 Proxy 寫入記錄檔的事件設定快訊,例如流量遭拒或符合特定規則。如需設定這些警告的一般操作說明,請參閱「設定記錄檔警告」。

以下列舉幾個查詢範例,可用於設定 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 政策名稱

服務頻率限制政策限制流量的警示

當服務頻率限制政策節流要求時,請使用下列查詢觸發快訊:

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 查看記錄

  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 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. 如要儲存小工具,請按一下「套用」。

後續步驟