Last active
December 2, 2023 20:18
-
-
Save jamesmoriarty/43aa22e94b21c1a5023b4d581fcaeb58 to your computer and use it in GitHub Desktop.
Google Cloud Platform delete custom metrics via REST api
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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