Skip to content

Instantly share code, notes, and snippets.

@jamesmoriarty
Last active December 2, 2023 20:18
Show Gist options
  • Save jamesmoriarty/43aa22e94b21c1a5023b4d581fcaeb58 to your computer and use it in GitHub Desktop.
Save jamesmoriarty/43aa22e94b21c1a5023b4d581fcaeb58 to your computer and use it in GitHub Desktop.
Google Cloud Platform delete custom metrics via REST api
#!/bin/bash
set -x
set -e
project="XXX"
prefix="http"
metrics=$(
curl \
-X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://monitoring.googleapis.com/v3/projects/$project/metricDescriptors?filter=metric.type%3Dstarts_with(%22custom.googleapis.com/$prefix%22)&fields=metricDescriptors.type" \
| jq --raw-output '.metricDescriptors[].type'
)
while read -r metric; do
curl \
--fail \
-X DELETE \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://monitoring.googleapis.com/v3/projects/$project/metricDescriptors/$metric"
done <<< "$metrics"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment