對於使用 Network Management API 建立的設定,預設會保留 100% 的記錄項目。您可以將這個參數從 1.0 設為大於 0.0。
中繼資料註解:根據預設,流程記錄項目會以中繼資料資訊加註,例如來源與目的地 VM 的名稱,或外部來源與目的地的地理地區。 Google Cloud 您可以關閉中繼資料註解,或只指定特定註解,以節省儲存空間。
篩選:根據預設,系統會為每個取樣的流程產生記錄。您可以設定篩選器,只產生符合特定條件的記錄。
規格
啟用虛擬私有雲流量記錄檔後,不會造成延遲或效能損失。
虛擬私有雲流程記錄可與虛擬私有雲網路搭配使用,但無法搭配舊版網路使用。
虛擬私有雲流量記錄會取樣 TCP、UDP、ICMP、ESP 和 GRE 流量。系統會對傳入和傳出流量進行取樣。這些流量可以是 Google Cloud 內部或 Google Cloud 與其他網路之間的流量。如果流程是由取樣作業擷取,虛擬私有雲流量記錄會為該流程產生記錄。每項流程記錄都會包含記錄格式一節說明的資料。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-08-19 (世界標準時間)。"],[],[],null,["# VPC Flow Logs\n=============\n\nVPC Flow Logs samples packets in your Virtual Private Cloud (VPC)\nnetwork to generate flow logs. Flow logs are aggregated by IP connection\n(5-tuple). VPC Flow Logs samples the following packets:\n\n- Packets sent from and received by [virtual machine (VM) instances](/compute/docs/instances), including instances used as [Google Kubernetes Engine nodes](/kubernetes-engine/docs)\n- Packets sent through VLAN attachments for [Cloud Interconnect](/network-connectivity/docs/interconnect/concepts/overview) and [Cloud VPN](/network-connectivity/docs/vpn/concepts/overview) tunnels\n\nYou can view flow logs in [Cloud Logging](/logging), and you\ncan export logs to any destination that Cloud Logging export supports.\nThese logs can be used for network monitoring, forensics, security analysis,\nand expense optimization.\n\nFor more information, see [Supported configurations](#configurations).\n\nUse cases\n---------\n\nThe following are use cases for VPC Flow Logs.\n\n### Network monitoring\n\nVPC Flow Logs provides you with visibility into network\nthroughput and performance. You can:\n\n- Monitor the VPC network\n- Perform network diagnosis\n- Filter the flow logs by VMs, VLAN attachments, and Cloud VPN tunnels to understand traffic changes\n- Understand traffic growth for capacity forecasting\n\n### Understanding network usage and optimizing network traffic expenses\n\nYou can analyze network usage with VPC Flow Logs to\noptimize network traffic expenses. For example, you can\nanalyze the network flows for the following:\n\n- Traffic between regions and zones\n- Traffic to specific countries on the internet\n- Traffic to on-premises and other cloud networks\n- Top talkers in the network, including VMs, VLAN attachments, and Cloud VPN tunnels\n\n### Network forensics\n\nYou can use VPC Flow Logs for network forensics. For example,\nif an incident occurs, you can examine the following:\n\n- Which IPs talked with whom and when\n- Any compromised IPs by analyzing all the incoming and outgoing network flows\n\nSupported configurations\n------------------------\n\nYou can enable VPC Flow Logs at the organization and project\nlevels. An organization-level VPC Flow Logs configuration enables\nflow logs for all subnets, VLAN attachments, and Cloud VPN tunnels in\nall VPC networks in the organization.\n\nAt the project level, you can enable VPC Flow Logs for specific\nVPC networks, subnets, VLAN attachments, and Cloud VPN\ntunnels.\n\nYou can use filtering to customize these configuration scopes. For more\ninformation, see [Log sampling and processing](#log-sampling).\n\nLogs collection\n---------------\n\nPackets are sampled within an aggregation interval. All packets collected for\na given IP connection within the aggregation interval are aggregated into a\nsingle flow log entry. This data is then sent to\n[Logging](/logging/docs) in the Google Cloud project of the\nVPC network that reported the flow.\n\nLogs are stored in Logging for 30 days by default. If\nyou want to keep logs longer than that, you can either [set a custom\nretention period](/logging/docs/storage#logs-retention) or\n[export them](/logging/docs/export/configure_export_v2) to a supported\ndestination.\n\n### Log sampling and processing\n\nTo generate flow logs, VPC Flow Logs samples packets that\nleave and enter a VM or pass through a gateway such as a VLAN attachment\nor Cloud VPN tunnel. After the flow logs are generated,\nVPC Flow Logs processes them by following the procedure described\nin this section.\n\nVPC Flow Logs samples packets using a *primary sampling rate*.\nThe primary sampling rate is dynamic and varies\ndepending on the load of the physical host running the VM or gateway at the\ntime of sampling. The probability of sampling any single IP connection increases\nwith the volume of packets. You can't control the primary flow log sampling\nprocess or adjust the primary sampling rate.\n\nAfter the flow logs are generated, VPC Flow Logs processes them\naccording to the following procedure:\n\n1. **Filtering** . You can specify that only logs that match specified criteria are generated. For example, you can filter so that only logs for a particular VM or only logs with a particular metadata value are generated and the rest are discarded. For more information, see [Log filtering](/vpc/docs/about-flow-logs-records#filtering).\n2. **Aggregation** . Information for sampled packets is aggregated over a configurable *aggregation interval* to produce a *flow log entry*.\n3. **Secondary flow log sampling** . This is a second sampling process. Flow log entries are further sampled according to a configurable *secondary sampling rate* parameter. The secondary sampling is performed on the flow logs generated by the primary flow log sampling process. For example, if the secondary sampling rate is set to 1.0, or 100%, VPC Flow Logs samples 100% of the flow logs generated by the primary flow log sampling.\n4. **Metadata** . If disabled, all metadata annotations are discarded. If you want to keep metadata, you can specify that all fields or a specified set of fields are retained. For more information, see [Metadata\n annotations](/vpc/docs/about-flow-logs-records#metadata).\n5. **Write to Logging**. The final log entries are written to Cloud Logging.\n\n| **Note:** You can't change how VPC Flow Logs collects samples. However, you can control the secondary flow log sampling with the **Secondary sampling rate** parameter, as described in [Enable VPC Flow Logs](/vpc/docs/using-flow-logs#enabling-vpc-flow-logs). If you need to analyze all packets, you can use [Packet Mirroring](/vpc/docs/packet-mirroring) and collector instances running third-party software.\n\nBecause VPC Flow Logs doesn't capture every packet, it compensates\nfor missed packets by interpolating from the captured packets. This happens for\npackets missed because of initial and user-configurable sampling settings.\n\nEven though Google Cloud doesn't capture every packet, log record captures\ncan be quite large. You can balance your traffic visibility and storage cost\nneeds by adjusting the following aspects of logs collection:\n\n- **Aggregation interval**. Sampled packets for a time interval are aggregated into a single log entry. This time interval can be 5 seconds (default), 30 seconds, 1 minute, 5 minutes, 10 minutes, or 15 minutes.\n- **Secondary sampling rate** .\n - For configurations created with the Compute Engine API, 50% of log entries are kept by default. You can set this parameter from `1.0` (100%, all log entries are kept) to `0.0` (0%, no logs are kept).\n - For configurations created with the Network Management API, 100% of log entries are kept by default. You can set this parameter from `1.0` to greater than `0.0`.\n- **Metadata annotations**. By default, flow log entries are annotated with metadata information, such as the names of the source and destination within Google Cloud or the geographic region of external sources and destinations. Metadata annotations can be turned off, or you can specify only certain annotations, to save storage space.\n- **Filtering**. By default, logs are generated for every sampled flow. You can set filters so that only logs that match certain criteria are generated.\n\nSpecifications\n--------------\n\n- VPC Flow Logs introduces no delay or performance penalty when enabled.\n- VPC Flow Logs works with VPC networks, not legacy networks.\n- VPC Flow Logs [samples](#log-sampling) TCP, UDP, ICMP, ESP, GRE, and RDMA flows:\n - Both inbound and outbound flows are sampled. For RDMA over Converged Ethernet (RoCE), only outbound flows are sampled.\n - Flows can be within Google Cloud or between Google Cloud and other networks.\n - If a flow is captured by sampling, VPC Flow Logs generates a log for the flow. Each flow record includes the information described in the [Record format](/vpc/docs/about-flow-logs-records#record_format) section.\n- VPC Flow Logs interacts with firewall rules in the following ways:\n - Egress packets are sampled *before* *egress* firewall rules. Even if an egress firewall rule denies outbound packets, those packets can be sampled by VPC Flow Logs.\n - Ingress packets are sampled *after* *ingress* firewall rules. If an ingress firewall rule denies inbound packets, those packets aren't sampled by VPC Flow Logs.\n- You can use [filters](/vpc/docs/about-flow-logs-records#filtering) in VPC Flow Logs to generate only certain logs.\n- VPC Flow Logs supports VMs that have multiple network interfaces. You need to enable VPC Flow Logs for each subnet, in each VPC, that contains a network interface.\n- To log flows between Pods on the same Google Kubernetes Engine (GKE) node, you must enable [intranode visibility](/kubernetes-engine/docs/how-to/intranode-visibility) for the cluster.\n- VPC Flow Logs isn't supported for Cloud Run resources.\n- VPC Flow Logs isn't supported for subnets with purpose `INTERNAL_HTTPS_LOAD_BALANCER` because these subnets are used as proxy-only subnets and have no VM instances.\n- VPC Flow Logs writes logs to the project of the reporting VPC network. For resources in Shared VPC networks, logs are reported in the host project.\n\nPricing and billing\n-------------------\n\nStandard pricing for Logging,\nBigQuery, or Pub/Sub apply.\nVPC Flow Logs pricing is described in\n[Network Telemetry pricing](/vpc/pricing#network-telemetry).\n\nVPC Flow Logs charges are billed to the Google Cloud project of the\nresource that reports flow logs. If VPC Flow Logs is enabled for an\norganization, each project is billed separately.\n\nWhat's next\n-----------\n\n- To learn more about the VPC Flow Logs record format and which metadata annotations are available, see [About VPC Flow Logs records](/vpc/docs/about-flow-logs-records).\n- To see examples of VPC Flow Logs that are collected for various use cases, see [About traffic flows](/vpc/docs/about-traffic-flows).\n- To start reporting flows for a subnet, see [Configure VPC Flow Logs](/vpc/docs/using-flow-logs)."]]