|
| 1 | +--- |
| 2 | +title: Storage Management for Google Cloud Storage |
| 3 | +further_reading: |
| 4 | + - link: "https://www.datadoghq.com/blog/datadog-storage-monitoring/" |
| 5 | + tag: "Blog" |
| 6 | + text: "Optimize and troubleshoot cloud storage at scale with Storage Monitoring" |
| 7 | + - link: "https://www.datadoghq.com/blog/storage-monitoring-recommendations/" |
| 8 | + tag: "Blog" |
| 9 | + text: "Reduce cloud storage costs and improve operational efficiency with Datadog Storage Monitoring" |
| 10 | +--- |
| 11 | + |
| 12 | +{{< callout url="https://www.datadoghq.com/product-preview/storage-monitoring/" >}} |
| 13 | + Storage Management is in Preview. Request access to start monitoring your object storage. |
| 14 | +{{< /callout >}} |
| 15 | + |
| 16 | +## Setup |
| 17 | + |
| 18 | +### Step 1: Install the Google Cloud integration and enable resource collection |
| 19 | + |
| 20 | +To collect Google Cloud Storage metrics from your Google Cloud project, install the Google Cloud integration in Datadog. Enable Resource Collection for the project containing the buckets you want to monitor. Resource Collection allows Datadog to associate your buckets' labels with the metrics collected through Storage Management. |
| 21 | + |
| 22 | +**Note**: While you can disable specific metric namespaces, keep the Cloud Storage namespace (gcp.storage) enabled. |
| 23 | + |
| 24 | +### Step 2: Enable the Storage Insights API |
| 25 | + |
| 26 | +Enable the [Storage Insights][2] API in your Google Cloud project. |
| 27 | + |
| 28 | +### Step 3: Grant service agent permissions |
| 29 | + |
| 30 | +After enabling the Storage Insights API, a project-level service agent is created automatically with the following format: `service-PROJECT_NUMBER@gcp-sa-storageinsights.iam.gserviceaccount.com` |
| 31 | + |
| 32 | +The service agent requires these IAM roles: |
| 33 | + |
| 34 | +1. `roles/storage.insightsCollectorService` on the source bucket (includes storage.buckets.getObjectInsights and storage.buckets.get permissions) |
| 35 | +2. `roles/storage.objectCreator` on the destination bucket (includes the storage.objects.create permission) |
| 36 | + |
| 37 | +### Step 4: Create an inventory report configuration |
| 38 | + |
| 39 | +You can create an inventory report configuration in multiple ways. The quickest methods use the Google Cloud CLI or Terraform templates. Regardless of the method, ensure the configuration: |
| 40 | + |
| 41 | +1. Includes these metadata fields: `"bucket", "name", "project", "size", "updated", "storageClass"` |
| 42 | +2. Generates CSV reports with `'\n'` as the delimiter and `','` as the separator |
| 43 | +3. Uses this destination path format: `<BUCKET>/{{date}}`, where `<BUCKET>` is the monitored bucket-name |
| 44 | + |
| 45 | +{{< tabs >}} |
| 46 | +{{% tab "Google Cloud CLI" %}} |
| 47 | + |
| 48 | +Use the [Google Cloud CLI][301] to run the following command: |
| 49 | + |
| 50 | +``` |
| 51 | +gcloud storage insights inventory-reports create <SOURCE_BUCKET_URL> \ |
| 52 | + --no-csv-header \ |
| 53 | + --display-name=datadog-storage-monitoring \ |
| 54 | + --destination=gs://<DESTINATION_BUCKET>/<SOURCE_BUCKET>/{{date}}> \ |
| 55 | + --metadata-fields=project,bucket,name,size,updated,storageClass \ |
| 56 | + --schedule-starts=<YYYY-MM-DD> \ |
| 57 | + --schedule-repeats=<DAILY|WEEKLY> \ |
| 58 | + --schedule-repeats-until=<YYYY-MM-DD> |
| 59 | +``` |
| 60 | + |
| 61 | +[301]: https://cloud.google.com/storage/docs/insights/using-inventory-reports#create-config-cli |
| 62 | + |
| 63 | +{{% /tab %}} |
| 64 | +{{% tab "Terraform" %}} |
| 65 | + |
| 66 | +Copy the following Terraform template, substitute the necessary arguments, and apply it in the Google Cloud project that contains your bucket. |
| 67 | + |
| 68 | +<!-- vale off --> |
| 69 | +{{% collapse-content title="Terraform configuration for inventory reports" level="h4" expanded=true %}} |
| 70 | + |
| 71 | +```hcl |
| 72 | +locals { |
| 73 | + source_bucket = "" # The name of the bucket you want to monitor |
| 74 | + destination_bucket = "" # The bucket where inventory reports are written |
| 75 | + frequency = "" # Possible values: Daily, Weekly (report generation frequency) |
| 76 | + location = "" # The location of your source and destination buckets |
| 77 | +} |
| 78 | +
|
| 79 | +data "google_project" "project" { |
| 80 | +} |
| 81 | +
|
| 82 | +resource "google_storage_insights_report_config" "config" { |
| 83 | + display_name = "datadog-storage-monitoring" |
| 84 | + location = local.location |
| 85 | + frequency_options { |
| 86 | + frequency = local.frequency |
| 87 | + start_date { |
| 88 | + day = "" # Fill in the day |
| 89 | + month = "" # Fill in the month |
| 90 | + year = "" # Fill in the year |
| 91 | + } |
| 92 | + end_date { |
| 93 | + day = "" # Fill in the day |
| 94 | + month = "" # Fill in the month |
| 95 | + year = "" # Fill in the year |
| 96 | + } |
| 97 | + } |
| 98 | + csv_options { |
| 99 | + record_separator = "\n" |
| 100 | + delimiter = "," |
| 101 | + header_required = false |
| 102 | + } |
| 103 | + object_metadata_report_options { |
| 104 | + metadata_fields = ["bucket", "name", "project", "size", "updated", "storageClass"] |
| 105 | + storage_filters { |
| 106 | + bucket = local.source_bucket |
| 107 | + } |
| 108 | + storage_destination_options { |
| 109 | + bucket = google_storage_bucket.report_bucket.name |
| 110 | + destination_path = "${local.source_bucket}/{{date}}" |
| 111 | + } |
| 112 | + } |
| 113 | +
|
| 114 | + depends_on = [ |
| 115 | + google_storage_bucket_iam_member.admin |
| 116 | + ] |
| 117 | +} |
| 118 | +
|
| 119 | +resource "google_storage_bucket" "report_bucket" { |
| 120 | + name = local.destination_bucket |
| 121 | + location = local.location |
| 122 | + force_destroy = true |
| 123 | + uniform_bucket_level_access = true |
| 124 | +} |
| 125 | +
|
| 126 | +resource "google_storage_bucket_iam_member" "admin" { |
| 127 | + bucket = google_storage_bucket.report_bucket.name |
| 128 | + role = "roles/storage.admin" |
| 129 | + member = "serviceAccount:service-${data.google_project.project.number}@gcp-sa-storageinsights.iam.gserviceaccount.com" |
| 130 | +} |
| 131 | +``` |
| 132 | + |
| 133 | +{{% /collapse-content %}} |
| 134 | +<!-- vale on --> |
| 135 | + |
| 136 | +{{% /tab %}} |
| 137 | +{{% tab "Allow Datadog to create the configuration on your behalf" %}} |
| 138 | + |
| 139 | +You can allow Datadog to handle the inventory report configuration by providing the proper permissions to your service account: |
| 140 | + |
| 141 | +1. Navigate to IAM & Admin -> Service accounts |
| 142 | +2. Find your Datadog service account and add the `roles/storageinsights.Admin` role |
| 143 | +3. Navigate to the source bucket you want to monitor and grant these permissions: |
| 144 | + - `roles/storage.insightsCollectorService` |
| 145 | + - `roles/storage.ObjectViewer` |
| 146 | +4. Navigate to the destination bucket and grant these permissions: |
| 147 | + - `roles/storage.objectCreator` |
| 148 | + - `roles/storage.insightsCollectorService` |
| 149 | + |
| 150 | +Alternatively, you can create a custom role specifically for Datadog with these required permissions: |
| 151 | + |
| 152 | +``` |
| 153 | +storage.buckets.get |
| 154 | +storage.objects.list |
| 155 | +storage.buckets.getObjectInsights |
| 156 | +storage.buckets.get |
| 157 | +storage.objects.create |
| 158 | +storageinsights.reportConfigs.get |
| 159 | +storageinsights.reportConfigs.create |
| 160 | +storageinsights.reportConfigs.list |
| 161 | +storageinsights.reportConfigs.update |
| 162 | +storage.objects.get |
| 163 | +storageinsights.reportDetails.get |
| 164 | +storageinsights.reportDetails.list |
| 165 | +``` |
| 166 | + |
| 167 | +After granting the necessary permissions, Datadog can create the inventory report configuration with your setup details. |
| 168 | + |
| 169 | +{{% /tab %}} |
| 170 | +{{< /tabs >}} |
| 171 | + |
| 172 | +### Step 5: Add the Storage Object Viewer role to your Datadog service account |
| 173 | + |
| 174 | +Grant Datadog permission to access and extract the generated inventory reports from Google. This permission should be on the destination bucket where the inventory reports are stored. |
| 175 | + |
| 176 | +1. Select the destination bucket for your inventory reports |
| 177 | +2. In the bucket details page, click the Permissions tab |
| 178 | +3. Under Permissions, click Grant Access to add a new principal |
| 179 | +4. Principal: Enter the Datadog Service Account email |
| 180 | +5. Role: Select Storage Object Viewer (`roles/storage.objectViewer`) |
| 181 | + |
| 182 | +### Post-setup steps |
| 183 | + |
| 184 | +After completing the setup steps, fill out the [post-setup][3] form with the following required information: |
| 185 | +1. Name of the destination bucket holding the inventory files |
| 186 | +2. Name of the service account with the granted permissions |
| 187 | +3. Prefix where the files are stored in the destination bucket (if any) |
| 188 | +4. Name of the source bucket you want to monitor (the bucket producing inventory files) |
| 189 | +5. Google Cloud location of the destination bucket holding the inventory files |
| 190 | +6. Google Cloud ProjectID containing the buckets |
| 191 | +7. Datadog org name |
| 192 | + |
| 193 | +### Validation |
| 194 | + |
| 195 | +To verify your setup: |
| 196 | +1. Wait for the first inventory report to generate (up to 24 hours for daily reports or 7 days for weekly reports). |
| 197 | +2. Check the destination bucket for inventory files. |
| 198 | +3. Confirm the Datadog integration can access the files. |
| 199 | +4. Navigate to **Infrastructure** > **Storage Management** > **Installation Recommendations** to see if your configured bucket appears in the list. |
| 200 | + |
| 201 | +### Troubleshooting |
| 202 | + |
| 203 | +If you encounter any issues or need assistance: |
| 204 | +- Use only one destination bucket for all inventory files per Google Cloud project. |
| 205 | +- Verify all permissions are correctly configured. |
| 206 | +- If issues persist, [contact Datadog][1] with your bucket details, Google Cloud Project ID, and Datadog org name. |
| 207 | + |
| 208 | +[1]: mailto:storage-monitoring@datadoghq.com |
| 209 | +[2]: https://cloud.google.com/storage/docs/insights/using-inventory-reports#enable_the_api |
| 210 | +[3]: https://forms.gle/c7b8JiLENDaUEqGk8 |
0 commit comments