Compute Engine VM log troubleshooting and observability
This skill diagnoses and resolves in-guest Google Compute Engine virtual machine
(VM) issues across Out-of-Memory (OOM) exhaustion, authorization and OAuth
access scope failures, full disks (ENOSPC) and filesystem expansion, and
boot, startup script, Ops Agent, and SSH connectivity errors. It encodes the
exact Cloud Logging schemas, serial console fallbacks, and hardware and OS
nuances where default troubleshooting queries silently return empty results or
fail.
MCP Tools:
get_instance_basic_info,list_instances,list_instance_attached_disks,get_disk_basic_info,stop_instance,set_instance_machine_type,start_instance,get_zone_operation
Usage Attribution
MUST READ: Before executing any gcloud, REST API, or Model Context
Protocol (MCP) command, you MUST read and follow the instructions in
Usage Attribution [blocked].
Prerequisites and environment setup
Any command that mutates state requires explicit user approval before execution.
For example, get approval before running commands that install gcloud,
configure MCP servers, enable APIs, stop or resize VMs, create snapshots, resize
disks, update metadata or access scopes, or change Identity and Access
Management (IAM) bindings.
- Google Cloud CLI (
gcloud): Before runninggcloudcommands in a terminal, rungcloud versionto verify the command-line interface (CLI) is installed (skip this when answering conceptual questions or providing copy-pasteable commands only). Ifgcloudis missing, notify the user thatgcloudis required for CLI execution, provide copy-pasteable commands, and ask before installing via Install the gcloud CLI. - Remote MCP servers and capability boundaries: Check whether these MCP
tools are already available in your active session before suggesting setup,
and ask for user approval before modifying MCP client configuration:
- Compute Engine (MCP server endpoint:
https://compute.googleapis.com/mcp): Configure per Use the Compute Engine MCP server; see Compute Engine MCP reference. For VM troubleshooting, the MCP server exposes tools such asget_instance_basic_info(resolves VMnameto numericid,status,machineType),list_instances,list_instance_attached_disks,get_disk_basic_info,stop_instance,set_instance_machine_type,start_instance, andget_zone_operation(noget_instanceorlist_zone_operationstools exist).get_instance_basic_infoomitsserviceAccounts(and OAuthscopes),metadata,networkInterfaces, andscheduling, and Compute Engine has no MCP tools forget-serial-port-output,disks resize, orsnapshots create—route those togcloudor REST. - Cloud Logging (MCP server endpoint:
https://logging.googleapis.com/mcp): Configure per Use the Cloud Logging remote MCP server; see Cloud Logging MCP reference. The server exposes tools such aslist_log_entriesandlist_log_names(nolist_monitored_resource_descriptorstool exists).list_log_entriesrequires"resourceNames": ["projects/{project_id}"](never"projects") and supports only one project per call. - Cloud Monitoring (MCP server endpoint:
https://monitoring.googleapis.com/mcp): Configure per Use the Cloud Monitoring remote MCP server; see Cloud Monitoring MCP reference. The server exposes tools such aslist_timeseries,query_range, andlist_metric_descriptors(plural—no singularget_metric_descriptortool).
- Compute Engine (MCP server endpoint:
- Authentication: Authenticate via
gcloud auth login(CLI),gcloud auth application-default login(Application Default Credentials for SDKs and MCP), orGOOGLE_APPLICATION_CREDENTIALS(service account key or Workload Identity). - Project, region, billing, and API enablement: Ask the user for
{project_id},{region}, and{zone}if not provided. Pass--projectand--zoneper command for read-only diagnostics, and request user approval before modifyinggcloudconfig defaults or enabling APIs:
Note: Target projects require an active billing account (even when using Google Cloud Free Tier resources).gcloud config set project {project_id} gcloud config set compute/region {region} gcloud config set compute/zone {zone} gcloud services enable compute.googleapis.com logging.googleapis.com monitoring.googleapis.com telemetry.googleapis.comlogging.googleapis.com,monitoring.googleapis.com, andtelemetry.googleapis.comare typically enabled on new projects (verifytelemetry.googleapis.comon existing projects when ingesting OpenTelemetry Protocol (OTLP) telemetry). Always use the existing VM's region and zone; for new test or rescue resources with no location specified, ask for the user's location and select a nearby region from Google Cloud locations (using a broadly supported region such asus-central1only as an example fallback, noting preview features are often restricted toglobalorus-central1). - Required IAM roles:
- Read-only diagnostics:
roles/compute.viewer(VM config andget-serial-port-output),roles/logging.viewer(orroles/logging.privateLogViewerfor Data Access audit logs), androles/monitoring.viewer. - Remote MCP access:
roles/mcp.toolUser(plusroles/logging.adminandroles/monitoring.adminwhere required by remote Logging and Monitoring OAuth scopes; see the MCP setup guides above). - Remediation (after user confirmation):
roles/compute.instanceAdmin.v1(plusroles/iam.serviceAccountUserwhen updating access scopes or service accounts), resource-scoped IAM admin roles (roles/secretmanager.adminorroles/storage.adminbound on the specific secret or bucket), and project-levelroles/resourcemanager.projectIamAdminonly when modifying project-level IAM bindings (such as grantingroles/logging.logWriter).
- Read-only diagnostics:
Core diagnostic workflow and empty-logs decision tree
1. Mode-aware intake and constraint handling
- Conceptual or query-syntax questions: Answer immediately from the rules below without running shell or MCP commands, or blocking on intake prompts.
- Read-only or
"Do not execute"requests: Never invoke terminal or mutating MCP commands when the user asks not to execute commands, declines approval, or works in a read-only environment. Provide copy-pasteablegcloudcommands (without--quiet) and valid MCP JSON arguments, and end with an explicit confirmation prompt before the user applies mutating steps. - Live troubleshooting missing inputs: If
{project_id},{vm_name}(or numeric{instance_id}),{zone}, or the time window of the issue is missing (see Prerequisite #4), ask the user for the missing details in a single concise turn without probinggcloud config listfirst: briefly note the main candidate causes for the symptom (such as OOM kills, full boot disk, startup or service crashes, or firewall or SSH blocks), clarify whether to run diagnostics via connected MCP orgcloudtools or provide copy-pasteablegcloudcommands, and offer to list VMs vialist_instancesonce{project_id}and{zone}are confirmed.
2. Resolve {vm_name} to numeric {instance_id} and check telemetry state
In Cloud Logging, resource.labels.instance_id on gce_instance stores the
numeric VM ID (64-bit integer), not {vm_name}. Filtering
resource.labels.instance_id="{vm_name}" silently returns zero entries.
Always resolve {instance_id} and inspect disk interfaces (NVME vs. SCSI),
serviceAccounts[].scopes, and serial-port-logging-enable metadata first:
gcloud compute instances describe {vm_name} --project={project_id} --zone={zone} \
--format="yaml(id, status, machineType.basename(), disks, serviceAccounts, metadata.items, networkInterfaces)"
For lightweight MCP discovery when only id, status, and machineType are
needed, call get_instance_basic_info with {"project": "{project_id}", "zone": "{zone}", "name": "{vm_name}"} and list_instance_attached_disks.
3. Compute Engine log stream reference (why queries return 0 rows)
By default, Compute Engine VMs send neither guest OS logs (syslog) nor
serial console logs to Cloud Logging. Use this matrix to identify which log
streams are enabled by default, how to filter each stream, and when to fall back
to the live hypervisor serial buffer:
| Log Stream | Enabled by Default? | Exact resource.type & log_id or Command | VM Identifier Filter | Default Severity & Filtering Notes |
|---|---|---|---|---|
| Control-Plane & Host Audit Logs | Yes | resource.type="gce_instance" + log_id("cloudaudit.googleapis.com/activity") or log_id("cloudaudit.googleapis.com/system_event") | resource.labels.instance_id="{instance_id}" or protoPayload.resourceName:"{vm_name}" | system_event entries (hostError, migrateOnHostMaintenance, guestTerminate, preempted) log at INFO and route to _Required (not _Default). Delegate deep host-event recovery to compute-host-events-troubleshooting. |
| Guest OS & App Logs (Ops Agent) | No (Requires Ops Agent + roles/logging.logWriter) | resource.type="gce_instance" + log_id("syslog") (Linux) or log_id("windows_event_log") (Windows) | resource.labels.instance_id="{instance_id}" or labels."compute.googleapis.com/resource_name"="{vm_name}" | Default Linux pipeline writes to syslog (not journald). If the disk hits 100% full, OOM kills the agent, or IAM logWriter is missing, final crash logs never reach Cloud Logging. |
| Serial Console in Cloud Logging | No (Requires serial-port-logging-enable=true metadata) | resource.type="gce_instance" + log_id("serialconsole.googleapis.com/serial_port_1_output") | resource.labels.instance_id="{instance_id}" | Ingested at INFO or DEFAULT even for kernel panics and OOM kills—never add severity>=ERROR or severity>=ALERT, which filters out every serial log line. |
| Live Hypervisor Serial Ring Buffer | Yes (Last 1 MB on running VMs; no metadata needed) | gcloud compute instances get-serial-port-output {vm_name} --project={project_id} --zone={zone} --port=1 | {vm_name} + --zone={zone} | Primary fallback when Cloud Logging is empty or SSH is unreachable. Captures kernel panics, OOM kills, google_metadata_script_runner, and full-disk boot errors directly from the hypervisor. |
| VPC Firewall Rules Logging | No (Opt-in per firewall rule via --enable-logging) | resource.type="gce_subnetwork" + log_id("compute.googleapis.com/firewall") | jsonPayload.instance.vm_name="{vm_name}" | Uses gce_subnetwork (never gce_instance), severity=DEFAULT, and jsonPayload.disposition="DENIED" (never "DROPPED"). VPC Flow Logs (vpc_flows) do not capture ingress packets denied by firewall rules. |
4. Apply explicit time bounds (--freshness vs. timestamp>=)
Consult Logging query language for filter syntax details and apply explicit time bounds on every query:
gcloud logging readdefault 24-hour window:gcloud logging readdefaults to--freshness=1dand silently excludes log entries older than 24 hours. Always pass--freshness=7d(or explicit RFC 3339 boundstimestamp>="{start_time}" AND timestamp<="{end_time}"computed from the target time window—never hardcode static example dates).- Cloud Logging
list_log_entries: Has no default 24-hour bound. Always includetimestamp>="{start_time}","orderBy": "timestamp desc", and a bounded"pageSize"(for example,20) to prevent slow multi-day scans and timeouts. Standardentries.listqueries do not charge per byte scanned; scan charges apply only to BigQuery queries on linked datasets.
5. Correlate hypervisor vs. Ops Agent metrics
- Built-in hypervisor metrics (
compute.googleapis.com/instance/*): Always available without an agent—checkcompute.googleapis.com/instance/cpu/utilization,disk/read_bytes_count,disk/write_bytes_count, andnetwork/received_bytes_countvia Cloud Monitoring'slist_timeseriesorquery_rangetools. ForE2VMs only, built-in GA hypervisor balloon metrics also expose RAM and swap without Ops Agent (compute.googleapis.com/instance/memory/balloon/ram_size,ram_used,swap_in_bytes_count, andswap_out_bytes_count). - Guest RAM, swap, and filesystem metrics (
agent.googleapis.com/*): Required on non-E2VMs for guest RAM and swap—and on all VMs for filesystem utilization—via the Ops Agent (see Install the Ops Agent).agent.googleapis.com/memory/percent_usedemits five separatestateseries (buffered,cached,free,slab,used): filter withmetric.labels.state = "used"to isolate active non-cache process memory during Linux OOM diagnosis (state != "free"includes reclaimable Linux page cache, which is routinely 90–99% on healthy VMs, and returns multiple unaggregated series unless reduced). Also checkagent.googleapis.com/swap/percent_usedfor swap pressure.agent.googleapis.com/disk/percent_usedemits threestateseries (free,used,reserved): inspectstate = "free"(or aggregateusedplusreserved) to measure available filesystem headroom.
Diagnostic and remediation playbooks
MUST READ: Before diagnosing or remediating a specific symptom, read the
matching playbook in references/:
| Symptom | Playbook reference |
|---|---|
| Memory exhaustion, Linux OOM killer, process crashes, or VM memory right-sizing | OOM and memory exhaustion [blocked] |
| Missing IAM permissions, legacy OAuth scopes, Secret Manager or Cloud Storage 403s, or Ops Agent ingestion failures | IAM, OAuth scopes, and Ops Agent 403s [blocked] |
Full boot or data disk (No space left on device, ENOSPC), snapshot backups, Hyperdisk or Persistent Disk resize, or partition expansion | Disk space exhaustion and resizing [blocked] |
| Boot errors, startup script failures, unreachable SSH, serial console modes, or VPC Firewall Rules Logging blocks | Boot, startup scripts, SSH, and firewall triage [blocked] |
Verification, rollback, cleanup, and cost governance
- Verify recovery: Confirm instance state (
RUNNING), clean serial console tail (get-serial-port-output), restored disk headroom (df -Thanddf -i), and fresh telemetry in Cloud Logging and Cloud Monitoring. - Rollback temporary interactive serial access: If
serial-port-enable=TRUEwas temporarily enabled for emergency login, disable it immediately:gcloud compute instances add-metadata {vm_name} --project={project_id} \ --zone={zone} --metadata=serial-port-enable=FALSE - Clean up temporary snapshots and rescue resources: Once disk and OS
stability are verified, delete temporary pre-resize snapshots or rescue VMs
so storage charges do not accumulate (omit
--quieton manualdeletecommands so interactive confirmation prevents accidental data loss):gcloud compute snapshots delete {snapshot_name} --project={project_id} gcloud compute instances delete {rescue_vm_name} --project={project_id} --zone={zone} --delete-disks=all - Pricing reference: Point users to Google Cloud Observability pricing, Compute Engine pricing, and Google Cloud pricing rather than quoting hardcoded dollar rates (Cloud Logging charges depend on log storage volume and retention settings, while resized disks and retained snapshots incur ongoing storage charges until deleted).


