This document is intended for application owners that run Google Distributed Cloud.
This document shows you how to view console logs for virtual machines (VMs) that
use VM Runtime on GDC. You can use the VM console logs to
troubleshoot and diagnose problems in your cluster.

## Before you begin

To complete this document, you need access to the following resources:

- A VM that runs in one of your clusters. If needed, [create a VM in Google Distributed Cloud](https://docs.cloud.google.com/kubernetes-engine/distributed-cloud/bare-metal/docs/vm-runtime/quickstart.md.txt).
- The `virtctl` client tool installed as a plugin for `kubectl`. If needed, [install the virtctl client tool](https://docs.cloud.google.com/kubernetes-engine/distributed-cloud/bare-metal/docs/vm-runtime/quickstart.md.txt#install_the_virtctl_client_tool).

## Connect to VM

To make sure there are logs to review, connect to your VM and generate some log
activity.

1. To access a VM from the console, use `kubectl`:

   ```bash
   kubectl virt console VM_NAME
   ```

   Replace `VM_NAME` with the name of the VM that you want to
   connect to.
2. When prompted, enter the user credentials you specified when you created the
   VM.

3. Run a command to check for updates, such as `apt-get` for Debian-based VMs
   or `yum check-update` for Red Hat-based VMs.

   ### Debian-based

   ```bash
   apt-get update
   ```

   ### Red Hat-based

   ```bash
   yum check-update
   ```
4. After you have successfully generated some console log activity, exit the VM
   session and console:

   ```bash
   Ctrl + ]
   ```

## View VM console logs

You view VM console logs in the Google Cloud console. VM serial console logs
are streamed to Cloud Logging and can be viewed in Logs Explorer. VMs
that run using VM Runtime on GDC are classed as containers in the
console logs.

1. In the Google Cloud console, go to the **Logs Explorer** page in the
   **Logging** menu.

   [Go to Logs Explorer](https://console.cloud.google.com/logs/query)
2. In the **Query** field, enter the following basic query:

   ```sql
   resource.type="k8s_container"
   resource.labels.container_name="log"
   ```
3. The **Query results** window shows the output of the console logs from
   your VMs, as shown in the following example screenshot:

   ![The output of the query displays the console logs](https://docs.cloud.google.com/static/distributed-cloud/images/vm-runtime-view-console-logs.png)
4. You can further filter the results of your query to a particular VM by adding
   the cluster name and the name of the VM to your query:

   ```sql
   resource.type="k8s_container"
   resource.labels.container_name="log"
   resource.labels.cluster_name="CLUSTER_NAME"
   labels.k8s-pod/kubevirt/vm="VM_NAME"
   ```

   Replace the following:
   - `CLUSTER_NAME`: the name of the cluster that contains your VM.
   - `VM_NAME`: the name of your VM.

## What's next

- To learn more about how to filter your console logs, see [Build queries in Logs Explorer](https://docs.cloud.google.com/logging/docs/view/building-queries.md.txt).