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
Before you start
Google Cloud is connected to OneLens. Follow 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). Google's Network Telemetry pricing page links a VPC Flow Logs cost estimator that gives a monthly estimate per project or subnet before you enable anything.
Required roles
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
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.
gcloud storage buckets create gs://BUCKET_NAME \
--project=PROJECT_ID \
--location=asia-south1 \
--uniform-bucket-level-accessOptional: to keep storage costs down, add a lifecycle rule that deletes files after a set number of days. Keep files at least as long as the longest period you want to analyse.
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:
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.objectCreatorOptional: keep the logs out of your _Default Cloud Logging bucket so they are stored only in your bucket:
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"'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.
Turn on VPC flow logs
Create a flow-log configuration for each subnet you want to analyse:
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-metadataTo cover a whole VPC network instead, replace --subnet=… with --network=projects/PROJECT_ID/global/networks/NETWORK_NAME.
--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.
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.
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/onelensFlowLogReaderGrant it on the bucket, not the project, so OneLens can read this bucket only.
Request an analysis in OneLens
In Optimize → Deep Insights → VPC Flow Analysis → Flow logs, select Add Flow Log, choose Google Cloud, and enter:
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.
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
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). It applies even if the logs are excluded from Cloud Logging.
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).
Turn it off
Stopping the flow logs stops the generation charge. Keep the bucket for as long as you want to analyse past dates.
Troubleshooting
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.
Last updated

