Logs and metrics
Logging
Cloud NAT logging lets you log NAT connections and errors. When Cloud NAT logging is enabled, one log entry can be generated for each of the following scenarios:
- When a network connection using NAT is created.
- When a packet is dropped because no port was available for NAT.
You can choose to log both kinds of events, or only one or the other.
Created logs are sent to Cloud Logging.
Specifications
The following specifications apply to Cloud NAT logging:
Cloud NAT logging handles TCP and UDP traffic only.
Cloud NAT logging only logs dropped packets if they are egress (outbound) TCP and UDP packets. It does not log dropped incoming packets. For example, if an inbound response to an outbound request is dropped for any reason, no error is logged.
Each VM instance can only generate a certain number of log entries per unit time, proportional to its number of vCPUs. The VM can generate 50-100 log entries per second per vCPU.
This rate threshold affects the number of events that can be logged. Even if some events are filtered out, their occurrence counts toward the number of possible log entries. Limiting logs to only errors or only network address translation connections does not necessarily increase the number of viewed log entries. For example, if you choose to log only successful connections, periods of excessive failed connection attempts and NAT errors can still restrict the number of successful connection log entries.
Cloud NAT logging does not log every single packet. Even if the VM's rate threshold has not been reached, some conditions can cause events to be omitted from the log. You should rely on the presence of entries in Cloud NAT logging to make informed decisions, but you must not assume that the absence of entries means that an event didn't happen.
Configure logging
To configure Cloud NAT logging, follow these steps.
Enable logging
If logging is enabled, all collected logs are sent to Cloud Logging by default. You can filter these so that only certain logs are sent.
You can also specify these values when you create or edit a NAT gateway. The following directions show how to enable logging for an existing NAT gateway.
Console
In the Google Cloud console, go to the Cloud NAT page.
Click your NAT gateway.
Click Edit.
Click Advanced configurations.
In the Logging section, select one of the following:
- No logging: disables logging
- Translation and errors: sends all logs to Logging
- Translation only: sends a log only when a connection is created; does not log dropped packets
- Errors only: sends a log when a packet is dropped because no port was available; does not log new connections
Click Save.
gcloud
Use the
gcloud compute routers nats update command.
The following commands enable logging for an existing NAT gateway.
In each command, replace the following:
NAT_GATEWAY: the name of the NAT gatewayROUTER_NAME: the name of the Cloud Router that hosts the NAT gatewayREGION: the region of the Cloud Router
To log network address translation events and errors:
gcloud compute routers nats update NAT_GATEWAY \
--router=ROUTER_NAME \
--region=REGION \
--enable-logging
To log only network address translation events:
gcloud compute routers nats update NAT_GATEWAY \
--router=ROUTER_NAME \
--region=REGION \
--enable-logging \
--log-filter=TRANSLATIONS_ONLY
To log only errors:
gcloud compute routers nats update NAT_GATEWAY \
--router=ROUTER_NAME \
--region=REGION \
--enable-logging \
--log-filter=ERRORS_ONLY
Clear log filters
If you have a filter set, you can clear it. Clearing a log filter means that both network address translation events and errors are logged, provided that logging is enabled.
Console
In the Google Cloud console, go to the Cloud NAT page.
Click your NAT gateway.
Click Edit.
Click Advanced configurations.
In the Logging section, select Translation and errors.
Click Save.
gcloud
Use the
gcloud compute routers nats update command.
The --log-filter=ALL flag in the following command sets the log filter to
accept all logs.
gcloud compute routers nats update NAT_GATEWAY \
--router=ROUTER_NAME \
--region=REGION \
--log-filter=ALL
Replace the following:
NAT_GATEWAY: the name of the NAT gatewayROUTER_NAME: the name of the Cloud Router that hosts the NAT gatewayREGION: the region of the Cloud Router
Disable logging
To disable logging, do the following:
Console
In the Google Cloud console, go to the Cloud NAT page.
Click your NAT gateway.
Click Edit.
Click Advanced configurations.
In the Logging section, select No logging.
Click Save.
gcloud
Use the
gcloud compute routers nats update command.
gcloud compute routers nats update NAT_GATEWAY \
--router=ROUTER_NAME \
--region=REGION \
--no-enable-logging
Replace the following:
NAT_GATEWAY: the name of the NAT gatewayROUTER_NAME: the name of the Cloud Router that hosts the NAT gatewayREGION: the region of the Cloud Router
Determine logging status
To determine the status for logging, do the following:
Console
In the Google Cloud console, go to the Cloud NAT page.
Click your NAT gateway.
Click Edit.
Click Advanced configurations.
Inspect the selections in the Logging section.
gcloud
gcloud compute routers nats describe NAT_GATEWAY \
--router=ROUTER_NAME \
--region=REGION
Replace the following:
NAT_GATEWAY: the name of the NAT gatewayROUTER_NAME: the name of the Cloud Router that hosts the NAT gatewayREGION: the region of the Cloud Router
View logs
To view NAT logs, do the following:
Console
In the Google Cloud console, go to the Logs Explorer page.
- To see all NAT logs, in the Log name menu, select Cloud NAT Gateway.
- To see logs for only one region, in the Log name menu, select Cloud NAT Gateway, and then slide the cursor right to select a region.
- To see logs for only one gateway, in the Log name menu, select Cloud NAT Gateway, and then slide the cursor right to select a region. Slide the cursor right again to select a single gateway.
Alternatively, enter the following expression into the query editor:
resource.type="nat_gateway"
logName="projects/{#project_id}/logs/compute.googleapis.com%2Fnat_flows"
gcloud
gcloud logging read 'resource.type=nat_gateway' \
--limit=10 \
--format=json
Where:
resource.type=nat_gateway: limits the output to your NAT gateways--limit=10: limits the output to 10 entries; you can input a different value to see more or fewer entries, or omit it entirely to see a continuous scroll of logs--format=json: displays the output in JSON format
For more options, see Reading log entries.
You can configure the export of logs-based metrics for resource logs.
What is logged
Cloud NAT log entries contain information useful for monitoring and debugging your NAT traffic. Log entries contain the following types of information:
- General information shown in most Google Cloud logs, such as severity, project ID, project number, and timestamp.
- Specific information related to Cloud NAT. Some log fields contain entries that are themselves multiple fields. These entries and field descriptions are shown in the following tables.
Log fields
| Field | Value | Meaning |
|---|---|---|
connection |
object(NatIpConnection) | 7-tuple describing the source VM IP address and port, NAT source IP address and port, destination IP address and port, and IP address protocol of this connection. |
allocation_status |
enum | Indicates whether this connection was successfully allocated or
dropped. One of OK or DROPPED. |
gateway_identifiers |
object(NatGateway) | The NAT gateway configuration that the connection used. |
endpoint |
object(InstanceDetails) | VM instance details. In a Shared VPC configuration,
project_id corresponds to the service project. |
vpc |
object(VpcDetails) | Virtual Private Cloud (VPC) network details. In a Shared VPC configuration,
project_id corresponds to that of the host project. |
destination |
object(DestinationDetails) | Details of the destination of the connection. |
NatIpConnection field format
| Field | Type | Description |
|---|---|---|
src_ip |
string | Source IP address |
src_port |
int32 | Source port |
nat_ip |
string | NAT IP address |
nat_port |
int32 | NAT assigned port |
dest_ip |
string | Destination IP address1 |
dest_port |
int32 | Destination port |
protocol |
int32 | IANA protocol number |
NatGateway field format
| Field | Type | Description |
|---|---|---|
gateway_name |
string | Name of the NAT gateway |
router_name |
string | Cloud Router associated with the NAT gateway |
region |
string | Region of the Cloud Router |
InstanceDetails field format
| Field | Type | Description |
|---|---|---|
project_id |
string | ID of the project containing the VM |
vm_name |
string | Instance name of the VM |
region |
string | Region of the VM |
zone |
string | Zone of the VM |
VpcDetails field format
| Field | Type | Description |
|---|---|---|
project_id |
string | ID of the project containing the network |
vpc_name |
string | Network on which the VM is operating |
subnetwork_name |
string | Subnet on which the VM is operating |
DestinationDetails field format
| Field | Type | Description |
|---|---|---|
geo_location |
object(GeographicDetails) | If the destination of the connection was external to Google Cloud, this field is populated with available location metadata. |
instance |
object(InstanceDetails) | If the destination of the connection is an instance within the same project as the source, this field is populated with VM instance details. |
vpc |
object(VpcDetails) | If the destination of the connection is within the same project as the source, this field is populated with the destination VPC network details. If the destination is a cross-project VPC network, then this field will display a blank. |
GeographicDetails field format
| Field | Type |
|---|