> [!WARNING]
>
> **Preview**
>
>
> This feature is
>
> subject to the "Pre-GA Offerings Terms" in the General Service Terms section of the
> [Service Specific
> Terms](https://docs.cloud.google.com/terms/service-terms#1).
>
> Pre-GA features are available "as is" and might have limited support.
>
> For more information, see the
> [launch stage descriptions](https://cloud.google.com/products/#product-launch-stages).

You can use Cloud Monitoring to monitor your external key manager (EKM)
connection. The following metrics can help you understand your EKM usage:

- `cloudkms.googleapis.com/ekm/external/request_latencies`
- `cloudkms.googleapis.com/ekm/external/request_count`

This page shows you how to create a dashboard to track metrics related to your
Cloud EKM keys and external key manager connection, such as request
counts and latencies. For more information about these metrics, see
[cloudkms metrics](https://docs.cloud.google.com/monitoring/api/metrics_gcp_c.md.txt#gcp-cloudkms). For more
information about the dashboard creation process described in the following
sections, see
[Managing dashboards by API](https://docs.cloud.google.com/monitoring/dashboards/api-dashboard.md.txt).

## Before you begin

The steps on this page assume the following:

- You already have Cloud EKM set up in a project, including an [EKM connection](https://docs.cloud.google.com/kms/docs/create-ekm-connection.md.txt) and one or more [external keys](https://docs.cloud.google.com/kms/docs/create-external-key.md.txt).

### Required roles


To get the permissions that
you need to create dashboards using the gcloud CLI,

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

- [Monitoring Dashboard Configuration Editor](https://docs.cloud.google.com/iam/docs/roles-permissions/monitoring.md.txt#monitoring.dashboardEditor) (`roles/monitoring.dashboardEditor`)
- [Service Usage Consumer](https://docs.cloud.google.com/iam/docs/roles-permissions/serviceusage.md.txt#serviceusage.serviceUsageConsumer) (`roles/serviceusage.serviceUsageConsumer`)


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.md.txt).


These predefined roles contain

the permissions required to create dashboards using the gcloud CLI. To see the exact permissions that are
required, expand the **Required permissions** section:


#### Required permissions

The following permissions are required to create dashboards using the gcloud CLI:

- `monitoring.dashboards.create`
- `monitoring.dashboards.delete`
- `monitoring.dashboards.update`
- `serviceusage.services.use`


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

## Create a dashboard to monitor your EKM

To monitor the status of your EKM, create a dashboard that monitors your
request count and latencies:

1. Download the dashboard configuration:
   [`ekm-dashboard.json`](https://docs.cloud.google.com/static/kms/static/ekm-dashboard.json).

2. Create a custom dashboard with the configuration file by running the
   following command:

   ```
   gcloud monitoring dashboards create \
   --config-from-file=ekm-dashboard.json
   ```

## View your EKM dashboard

1.

   In the Google Cloud console, go to the
   **Monitoring** page.

   [Go to Monitoring](https://console.cloud.google.com/monitoring)

   <br />

2. Select **Resources \> Dashboards** and view the dashboard
   named **Cloud KMS EKM**.

## Create an alert policy for EKM metrics

Complete the following steps using the gcloud CLI:

1. Select a notification channel to receive EKM metrics alerts.

   - To use an existing notification channel, first view your channels:

     ```
     gcloud beta monitoring channels list
     ```

     Choose a channel from the list. Make note of the notification channel
     ID; you need it later.
   - To use a new notification channel, create the channel using an email
     address:

     ```
     gcloud beta monitoring channels create \
     --display-name="Notification channel for EKM latency alert" \
     --description="This notification channel receives EKM latency metric alerts" \
     --type=email \
     --channel-labels=email_address=NOTIFICATION_EMAIL
     ```

     If successful, this command returns the name of the new channel. Make
     note of the notification channel ID; you need it later. The output is
     similar to the following:

     ```
     Created notification channel [projects/PROJECT_ID/notificationChannels/NOTIFICATION_CHANNEL_ID]
     ```
2. Create an alerting policy using the [`monitoring policies
   create`](https://docs.cloud.google.com/sdk/gcloud/reference/alpha/monitoring/policies/create) command:

   ```bash
       gcloud monitoring policies create \
           --notification-channels=NOTIFICATION_CHANNEL_ID \
           --aggregation=' {"alignmentPeriod": "60s","perSeriesAligner": "ALIGN_PERCENTILE_99"}' \
           --condition-display-name="EKM Request Latency > 150ms" \
           --condition-filter='resource.type="cloudkms.googleapis.com/Project"
                               metric.type="cloudkms.googleapis.com/ekm/external/request_latencies"
                               metric.labels.ekm_service_region="LOCATION"
                               metric.labels.method="LABEL_METHOD"' \
           --duration="0s" \
           --if="> 150" \
           --display-name="EKM metric latency alert" \
           --trigger-count=1 \
           --combiner='AND'
   ```

   Replace the following:
   - <var translate="no">NOTIFICATION_CHANNEL_ID</var>: the ID of the notification channel.
   - <var translate="no">LOCATION</var>: the region for which you want to alert on this metric. If you want to alert regardless of region, omit `metric.labels.ekm_service_region`.
   - <var translate="no">LABEL_METHOD</var>: the `method` label that you want to alert on---for example, `wrap`, `unwrap`, `asymmetricSign`, `checkCryptoSpacePermissions`, `createKey`, `getInfo`, or `getPublicKey`. You can use **Metrics Explorer** to explore metric labels.

## What's next

- [Explore your data across various metric dimensions using
  Metrics Explorer](https://docs.cloud.google.com/monitoring/charts/metrics-explorer).
- Optional: Create [alerting policies](https://docs.cloud.google.com/monitoring/alerts.md.txt).