> For the complete documentation index, see [llms.txt](https://docs.onelens.cloud/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.onelens.cloud/integrations/vpc-flow-logs/google-cloud.md). Agents can also search and read this documentation through its [MCP server](https://docs.onelens.cloud/~gitbook/mcp).

# Google Cloud

OneLens analyses your Google Cloud VPC flow logs to show which VMs, GKE nodes and workloads send traffic where, and what it costs: Cloud NAT, internet egress, cross-zone and cross-region transfer. You choose the date range (up to 30 days) and OneLens analyses it once, from flow-log files you export to a Cloud Storage bucket you own.

Setup takes about 15 minutes, plus a few hours for the first files to arrive.

### How it works

{% stepper %}
{% step %}

### VPC Flow Logs record traffic

VPC Flow Logs record the traffic of the subnets or VPC networks you choose.
{% endstep %}

{% step %}

### Route logs to Cloud Storage

A Cloud Logging sink writes the logs to a Cloud Storage bucket in your project, as hourly files.
{% endstep %}

{% step %}

### Grant OneLens access

You grant the OneLens Reader service account read access to that bucket. This is the service account created when you onboarded OneLens.
{% endstep %}

{% step %}

### Request an analysis

You request an analysis in OneLens for a date range. OneLens checks it can read the bucket, then analyses the files in its nightly processing window.
{% endstep %}

{% step %}

### View results

Results appear under **Optimize → Deep Insights → VPC Flow Analysis**.
{% endstep %}
{% endstepper %}

{% hint style="info" %}
OneLens can only analyse days for which flow logs were enabled and their files are still in the bucket. Turn on flow logs before the period you want to analyse.
{% endhint %}

### Before you start

* **Google Cloud is connected to OneLens.** Follow [Connecting to GCP](https://docs.onelens.cloud/integrations/cloud-and-cost-sources/connecting-to-gcp) first. That setup creates the **OneLens Reader** service account and the roles OneLens needs to identify VMs, GKE nodes and Cloud NAT.
* **Estimate the cost first.** Google charges for flow-log generation per GiB (see [Costs](#costs)). Google's [Network Telemetry pricing](https://cloud.google.com/vpc/pricing#network-telemetry) page links a VPC Flow Logs cost estimator that gives a monthly estimate per project or subnet before you enable anything.

#### Required roles

| Role                                                       | Where                                              | Used for                                         |
| ---------------------------------------------------------- | -------------------------------------------------- | ------------------------------------------------ |
| Network Management Admin (`roles/networkmanagement.admin`) | Projects with the subnets or networks to log       | Step 3, turning on flow logs                     |
| Logs Configuration Writer (`roles/logging.configWriter`)   | The project (or organisation) that routes the logs | Step 2, the log sink and exclusion               |
| Storage Admin (`roles/storage.admin`)                      | The bucket's project                               | Steps 1, 2 and 4: the bucket and its permissions |
| Role Administrator (`roles/iam.roleAdmin`)                 | The bucket's project                               | Step 4, the custom role for OneLens              |

### Set it up

{% stepper %}
{% step %}

### Create a bucket for the flow logs

Use a bucket that holds only flow logs. Granting OneLens read access to it then gives access to the flow logs and nothing else.

```bash
gcloud storage buckets create gs://BUCKET_NAME \
  --project=PROJECT_ID \
  --location=asia-south1 \
  --uniform-bucket-level-access
```

{% hint style="info" %}
**Create the bucket in `asia-south1` (Mumbai)**, the region OneLens reads your files from. Reads within the same region are free. A bucket in another region, or in a multi-region location, costs your project Google's [data-transfer rate](https://cloud.google.com/storage/pricing#network-buckets) for the files OneLens reads: about the size of the flow logs for the dates you analyse.
{% endhint %}

Optional: to keep storage costs down, add a [lifecycle rule](https://docs.cloud.google.com/storage/docs/lifecycle) that deletes files after a set number of days. Keep files at least as long as the longest period you want to analyse.
{% endstep %}

{% step %}

### Route the flow logs to the bucket

Create a log sink that sends VPC flow logs to the bucket, and let the sink write to it:

```bash
gcloud logging sinks create onelens-vpc-flow-logs storage.googleapis.com/BUCKET_NAME \
  --project=PROJECT_ID \
  --log-filter='resource.type="vpc_flow_logs_config" AND logName:"networkmanagement.googleapis.com%2Fvpc_flows"'

gcloud storage buckets add-iam-policy-binding gs://BUCKET_NAME \
  --member="$(gcloud logging sinks describe onelens-vpc-flow-logs --project=PROJECT_ID --format='value(writerIdentity)')" \
  --role=roles/storage.objectCreator
```

Optional: keep the logs out of your `_Default` Cloud Logging bucket so they are stored only in your bucket:

```bash
gcloud logging sinks update _Default --project=PROJECT_ID \
  --add-exclusion='name=exclude-vpc-flow-logs,filter=resource.type="vpc_flow_logs_config" AND logName:"networkmanagement.googleapis.com%2Fvpc_flows"'
```

{% hint style="info" %}
Google charges for flow-log generation whether or not the logs are kept in Cloud Logging. The exclusion only stops a second copy being stored there.
{% endhint %}

Logging several projects? Create the sink once at organisation level instead, with `--organization=ORGANIZATION_ID --include-children` in place of `--project`, and add the exclusion in each project.
{% endstep %}

{% step %}

### Turn on VPC flow logs

Create a flow-log configuration for each subnet you want to analyse:

```bash
gcloud network-management vpc-flow-logs-configs create onelens-SUBNET_NAME \
  --project=PROJECT_ID \
  --location=global \
  --subnet=projects/PROJECT_ID/regions/REGION/subnetworks/SUBNET_NAME \
  --aggregation-interval=interval-15-min \
  --flow-sampling=1.0 \
  --metadata=include-all-metadata
```

To cover a whole VPC network instead, replace `--subnet=…` with `--network=projects/PROJECT_ID/global/networks/NETWORK_NAME`.

| Setting                  | Use                    | Why                                                                                                                                                |
| ------------------------ | ---------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- |
| `--aggregation-interval` | `interval-15-min`      | OneLens analyses traffic per day. A longer interval writes fewer log records, which lowers the log-generation cost. Google's default is 5 seconds. |
| `--flow-sampling`        | `1.0`                  | OneLens uses the volumes as logged and does not scale them up, so a lower rate under-reports traffic and cost.                                     |
| `--metadata`             | `include-all-metadata` | Adds the GKE pod, workload, Google service and location details that OneLens uses to name traffic.                                                 |

You don't need to turn on GKE intranode visibility.
{% endstep %}

{% step %}

### Give OneLens read access to the bucket

Give the **OneLens Reader** service account read access to the bucket's files, and nothing more: create a role with only the two permissions OneLens uses (listing and reading files), then grant it on the bucket. The Reader service account is the one you created when you connected Google Cloud to OneLens; you'll find it in IAM in your billing-export project.

```bash
gcloud iam roles create onelensFlowLogReader \
  --project=PROJECT_ID \
  --title="OneLens Flow Log Reader" \
  --description="Lists and reads VPC flow-log files for OneLens" \
  --permissions=storage.objects.list,storage.objects.get \
  --stage=GA

gcloud storage buckets add-iam-policy-binding gs://BUCKET_NAME \
  --member=serviceAccount:READER_SERVICE_ACCOUNT_EMAIL \
  --role=projects/PROJECT_ID/roles/onelensFlowLogReader
```

Grant it on the bucket, not the project, so OneLens can read this bucket only.

{% hint style="info" %}
To tell Cloud NAT traffic from direct internet traffic, OneLens also uses the Compute Viewer, Kubernetes Engine Viewer and Monitoring Viewer roles that standard onboarding grants the Reader service account. If your onboarding left them out, the analysis still completes, but Cloud NAT cost may be understated and the request shows a note saying so.
{% endhint %}
{% endstep %}

{% step %}

### Check that files arrive

The first files appear one to three hours after you turn on flow logs. Each hour is written as one or more files under `networkmanagement.googleapis.com/vpc_flows/YYYY/MM/DD/`.

```bash
gcloud storage ls -r gs://BUCKET_NAME/networkmanagement.googleapis.com/vpc_flows/ | tail -3
```

{% endstep %}

{% step %}

### Request an analysis in OneLens

In **Optimize → Deep Insights → VPC Flow Analysis → Flow logs**, select **Add Flow Log**, choose **Google Cloud**, and enter:

| Field         | Value                                                                                  |
| ------------- | -------------------------------------------------------------------------------------- |
| Project       | The project whose flow logs you exported                                               |
| Bucket        | `BUCKET_NAME`, the name only, without `gs://`                                          |
| Folder prefix | Leave empty for a log sink. Only set it if the files sit under a folder in the bucket. |
| Log type      | VPC Flow Logs (`networkmanagement.googleapis.com/vpc_flows`)                           |
| Dates         | Up to 15 days, ending yesterday or earlier                                             |

OneLens checks that it can read the bucket when you submit. If it can't, it tells you what to fix and saves nothing. Accepted requests are analysed in OneLens's nightly processing window, so results are usually ready within a day.
{% endstep %}
{% endstepper %}

### How OneLens reads your logs

* **Who reads:** your **OneLens Reader** service account. OneLens acts as it through the service-account impersonation you allowed when connecting Google Cloud. No keys are created.
* **What it reads:** only the files for the dates you request, under the flow-log folder of the bucket you name. Nothing is written to your bucket.
* **How:** each file is read through a signed URL that the Reader service account creates and that expires after 35 minutes. If you turn on Cloud Storage Data Access audit logs, these reads appear there under the Reader service account.
* **What OneLens keeps:** traffic and cost totals per day by resource, route and destination. It doesn't keep a copy of your log files or GKE pod IP addresses.

### Costs

| Charge                    | Billed to                                | Rate                                                                                                                                                                                                                                                            |
| ------------------------- | ---------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Flow-log generation       | The project that owns the logged subnets | $0.25 per GiB for the first 10 TiB a month per billing account, then $0.15, $0.075 and $0.05 per GiB at higher volumes ([Google pricing](https://cloud.google.com/vpc/pricing#network-telemetry)). It applies even if the logs are excluded from Cloud Logging. |
| Cloud Storage             | The bucket's project                     | Your bucket's storage class and region ([pricing](https://cloud.google.com/storage/pricing))                                                                                                                                                                    |
| OneLens reading the files | The bucket's project                     | Read operations cost fractions of a cent per analysis. Data transfer is added if the bucket isn't in `asia-south1` (see step 1).                                                                                                                                |

{% hint style="info" %}
For scale: a production GKE cluster in OneLens's own environment produced about 240 GiB of flow logs a day at 15-minute aggregation, about $60 a day in log generation.
{% endhint %}

### Turn it off

Stopping the flow logs stops the generation charge. Keep the bucket for as long as you want to analyse past dates.

```bash
gcloud network-management vpc-flow-logs-configs delete onelens-SUBNET_NAME \
  --project=PROJECT_ID --location=global
gcloud logging sinks delete onelens-vpc-flow-logs --project=PROJECT_ID
gcloud logging sinks update _Default --project=PROJECT_ID \
  --remove-exclusions=exclude-vpc-flow-logs
gcloud storage buckets remove-iam-policy-binding gs://BUCKET_NAME \
  --member=serviceAccount:READER_SERVICE_ACCOUNT_EMAIL \
  --role=projects/PROJECT_ID/roles/onelensFlowLogReader
gcloud iam roles delete onelensFlowLogReader --project=PROJECT_ID
```

### Troubleshooting

| Message                                                                                         | What to do                                                                                                                                                                         |
| ----------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `OneLens can't read gs://…`                                                                     | Check the bucket name, then complete step 4: grant the OneLens Reader service account the **OneLens Flow Log Reader** role on the bucket                                           |
| `No flow-log files under gs://…`                                                                | Check the folder prefix and log type. Files appear one to three hours after flow logs are turned on.                                                                               |
| `No active GCP billing account is onboarded for this tenant`                                    | Connect Google Cloud to OneLens first.                                                                                                                                             |
| `No flow-log files for <start>..<end> in the export bucket.`                                    | Flow logs weren't on for those dates, or the files were deleted. Choose dates that have files.                                                                                     |
| `… GiB of flow logs is above the 3,072 GiB limit for one request; choose a shorter date range.` | Request a shorter period.                                                                                                                                                          |
| `No OneLens Reader service account found for GCP project …`                                     | The project isn't under a billing account connected to OneLens. Check the project ID, or connect its billing account.                                                              |
| `Completed, but some route checks were refused, so Cloud NAT cost may be understated …`         | Grant the Reader service account Compute Viewer, Kubernetes Engine Viewer and Monitoring Viewer on the projects with the logged VMs and clusters, then request the analysis again. |
| `Unexpected error while analysing the flow logs …`                                              | Submit the request again. Contact OneLens support if it fails again.                                                                                                               |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.onelens.cloud/integrations/vpc-flow-logs/google-cloud.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
