The [Ops Agent](https://docs.cloud.google.com/stackdriver/docs/solutions/agents/ops-agent) collects telemetry data for instances that you can then use for troubleshooting and performance tuning.

## Before you begin

- If you haven't already, set up [authentication](https://docs.cloud.google.com/compute/docs/authentication). Authentication verifies your identity for access to Google Cloud services and APIs. To run code or samples from a local development environment, you can authenticate to Compute Engine by selecting one of the following options:

  Select the tab for how you plan to use the samples on this page:

  ### Console


  When you use the Google Cloud console to access Google Cloud services and
  APIs, you don't need to set up authentication.

  ### gcloud

  1.
     [Install](https://docs.cloud.google.com/sdk/docs/install) the Google Cloud CLI.

     After installation,
     [initialize](https://docs.cloud.google.com/sdk/docs/initializing) the Google Cloud CLI by running the following command:

     ```bash
     gcloud init
     ```


     If you're using an external identity provider (IdP), you must first
     [sign in to the gcloud CLI with your federated identity](https://docs.cloud.google.com/iam/docs/workforce-log-in-gcloud).

     > [!NOTE]
     > **Note:** If you installed the gcloud CLI previously, make sure you have the latest version by running `gcloud components update`.

  2. [Set a default region and zone](https://docs.cloud.google.com/compute/docs/gcloud-compute#set_default_zone_and_region_in_your_local_client).

  ### REST


  To use the REST API samples on this page in a local development environment, you use the
  credentials you provide to the gcloud CLI.
  1. [Install](https://docs.cloud.google.com/sdk/docs/install) the Google Cloud CLI.
  2. If you're using an external identity provider (IdP), you must first [sign in to the gcloud CLI with your federated identity](https://docs.cloud.google.com/iam/docs/workforce-log-in-gcloud).


  For more information, see
  [Authenticate for using REST](https://docs.cloud.google.com/docs/authentication/rest)
  in the Google Cloud authentication documentation.

### Required roles


To get the permissions that
you need to create an instance for Ops Agent monitoring and logging,

ask your administrator to grant you the
following IAM roles on the project:

- [Compute Instance Admin (v1)](https://docs.cloud.google.com/iam/docs/roles-permissions/compute#compute.instanceAdmin.v1) (`roles/compute.instanceAdmin.v1`)
- To install the Ops Agent on the instance: [OSPolicyAssignment Editor](https://docs.cloud.google.com/iam/docs/roles-permissions/osconfig#osconfig.osPolicyAssignmentEditor) (`roles/osconfig.osPolicyAssignmentEditor`)


For more information about granting roles, see [Manage access to projects, folders, and organizations](https://docs.cloud.google.com/iam/docs/granting-changing-revoking-access).


You might also be able to get
the required permissions through [custom
roles](https://docs.cloud.google.com/iam/docs/creating-custom-roles) or other [predefined
roles](https://docs.cloud.google.com/iam/docs/roles-overview#predefined).

## Create an instance for the Ops Agent monitoring and logging

You can create an instance that's configured for Ops Agent monitoring and
logging only by using the Google Cloud console. This section briefly describes how
to install the Ops Agent while creating an instance. For more information, also
see [Install Ops Agent during instance creation](https://docs.cloud.google.com/stackdriver/docs/solutions/agents/ops-agent/install-agent-vm-creation).

1. In the Google Cloud console, go to the **Create an instance** page.

   [Go to Create an instance](https://console.cloud.google.com/compute/instancesAdd)

   If prompted, select your project and click **Continue**.

   The **Create an instance** page appears and displays the
   **Machine configuration** pane.
2. In the navigation pane, click **Observability** . The **Observability**
   pane appears.

3. In the **Ops Agent** section, select the
   **Install the Ops Agent for Monitoring and Logging** checkbox.

   Selecting this checkbox enables VM Manager in limited
   capability mode and it creates an OS policy assignment for installing
   Ops Agent on the instance.
4. Optional: Specify other configuration options. For more information, see
   [Configuration options during instance creation](https://docs.cloud.google.com/compute/docs/instances/instance-creation-overview#new-instance-configuration-options).

5. To create and start the instance, click **Create**.

## Install the Ops Agent on existing instances

You can use the Google Cloud console, the gcloud CLI, or an automation
tool to install Ops Agent on a fleet of instances or on individual instances.
For detailed instructions, see
[Install the Ops Agent](https://docs.cloud.google.com/stackdriver/docs/solutions/agents/ops-agent/install-index).

> [!NOTE]
> **Note:** If you install the Ops Agent, then you might be charged for the metrics and logs that the agent sends to your Google Cloud project. For more information, see [Google Cloud Observability pricing](https://cloud.google.com/stackdriver/pricing).

## What's next

- Learn how to [check the status of an instance](https://docs.cloud.google.com/compute/docs/instances/instance-life-cycle) to see when it is ready to use.
- Learn how to [connect to your instance0](https://docs.cloud.google.com/compute/docs/instances/connecting-to-instance).