# Set up managed data collection with Managed Service for Prometheus

This page explains how you can set up managed data collection with
[Google Cloud Managed Service for Prometheus](https://docs.cloud.google.com/stackdriver/docs/managed-prometheus.md.txt) for
GKE on Azure. This feature is available on Azure clusters
running Kubernetes version 1.25 or later. It is also supported on Kubernetes
clusters at version 1.24 for customers who had earlier signed up for a
preview of this feature on that version.

With this feature, you can use a PodMonitoring resource to choose the metrics
that you want to ingest into Cloud Monitoring. You can then view these
metrics in the Google Cloud console.

## Limitations

- This feature is not available on Kubernetes clusters earlier than version 1.24.

<!-- -->

- This feature requires a Linux workload.

## Set up managed data collection

To set up managed data collection with Managed Service for Prometheus, complete the following steps:

> [!NOTE]
> **Note:** Starting with Kubernetes version 1.28, manual policy binding to authorize service accounts for data collection is no longer necessary. The required permissions are now automatically granted to this service account. You can therefore disregard step 1 in this section.

1. Authorize the `gmp-system/collector` and `gmp-system/rule-evaluator` service
   accounts to write your metrics:

   ```bash
     gcloud projects add-iam-policy-binding GOOGLE_PROJECT_ID \
         --member="serviceAccount:GOOGLE_PROJECT_ID.svc.id.goog[gmp-system/collector]" \
         --role=roles/monitoring.metricWriter
     gcloud projects add-iam-policy-binding GOOGLE_PROJECT_ID \
         --member="serviceAccount:GOOGLE_PROJECT_ID.svc.id.goog[gmp-system/rule-evaluator]" \
         --role=roles/monitoring.viewer
     gcloud projects add-iam-policy-binding GOOGLE_PROJECT_ID \
         --member="serviceAccount:GOOGLE_PROJECT_ID.svc.id.goog[gmp-system/rule-evaluator]" \
         --role=roles/monitoring.metricWriter
   ```

   Replace `GOOGLE_PROJECT_ID` with your Google Cloud
   project ID.

   Adding this IAM binding fails unless at least one
   cluster has been created in your Google Cloud project. This is because the
   workload identity pool it refers to
   (`GOOGLE_PROJECT_ID.svc.id.goog`) isn't provisioned until
   cluster creation.
2. Create a cluster with the standard `gcloud`
   [Create your cluster](https://docs.cloud.google.com/kubernetes-engine/multi-cloud/docs/azure/how-to/create-cluster.md.txt#create_your_cluster)
   command, but include the optional `--enable-managed-prometheus` flag. For
   example:

   ```bash
    gcloud container azure clusters create \
        ...
        --enable-managed-prometheus
   ```
3. To configure which workload metrics you want to ingest, set up a
   [PodMonitoring](https://github.com/GoogleCloudPlatform/prometheus-engine/blob/v0.4.3-gke.0/doc/api.md#podmonitoring)
   resource. For an example, see
   [Configure a PodMonitoring resource](https://docs.cloud.google.com/stackdriver/docs/managed-prometheus/setup-managed.md.txt#gmp-pod-monitoring)
   in the managed data collection with Managed Service for Prometheus documentation.

After you enable managed data collection with Managed Service for Prometheus, GKE on Azure creates the
`gmp-system` namespace. Don't modify or deploy anything in this namespace.
GKE on Azure also creates the `gmp-public` namespace. Managed Service
for Prometheus uses the `gmp-public` namespace to deploy the
[OperatorConfig](https://github.com/GoogleCloudPlatform/prometheus-engine/blob/v0.4.3-gke.0/doc/api.md#operatorconfig)
resource.

## Update your Prometheus configuration

To disable or re-enable Prometheus data collection, use the standard `gcloud` [Update your cluster](https://docs.cloud.google.com/kubernetes-engine/multi-cloud/docs/azure/how-to/update-cluster.md.txt#update_your_cluster) command, but add a --disable-managed-prometheus or --enable-managed-prometheus optional parameter. For example:

<br />

```bash
  gcloud container azure clusters update \
    ...
    --disable-managed-prometheus
       OR
    --enable-managed-prometheus
```

## What's next

- Discover how to [Configure a query user interface](https://docs.cloud.google.com/stackdriver/docs/managed-prometheus/query.md.txt) in the managed data collection with Managed Service for Prometheus documentation.
- Learn about [Managed rule evaluation and alerting](https://docs.cloud.google.com/stackdriver/docs/managed-prometheus/rules-managed.md.txt) in the Google Cloud Managed Service for Prometheus documentation.