Last active
April 5, 2024 02:50
-
-
Save ellisbrown/daeb16164561b5e30b8aa31f54aebca6 to your computer and use it in GitHub Desktop.
List total TPU usage in a GCP project
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 | |
#params | |
PROJECT=my-project | |
ZONE=us-central2-b | |
# Command to list TPU resources | |
output=$(gcloud alpha compute tpus queued-resources list \ | |
--project $PROJECT \ | |
--zone $ZONE) | |
echo "$output" | |
echo "" # Add a blank line for readability | |
# Use awk to extract the numeric parts of the accelerator types and count TPUs | |
echo "$output" | awk ' | |
BEGIN { | |
sum = 0 | |
count = 0 | |
} | |
$4 ~ /^v4-/ { | |
split($4, a, "-") | |
sum += a[2] | |
count++ | |
} | |
END { | |
print "Total num TPU nodes:", sum | |
print "Count of TPUs:", count | |
} | |
' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment