GCP Node Preempt Events for Project runwhen-nonprod-sandbox¶
Troubleshooting Commands¶
List all nodes in an active prempt operation for GCP Project runwhen-nonprod-sandbox
¶
What does it do?
This command activates a service account authentication and then lists all preempted compute instances within a specific time frame in a Google Cloud Platform project.
Command
gcloud compute operations list --filter='operationType:(compute.instances.preempted)' --format=json --project=runwhen-nonprod-sandbox | jq -r --arg now "$(date -u +%s)" '[.[] | select((.startTime | sub("\\.[0-9]+"; "") | strptime("%Y-%m-%dT%H:%M:%S%z") | mktime) > ($now | tonumber - (30*60)))] '
Learn more
This multi-line content is auto-generated and used for educational purposes. Copying and pasting the multi-line text might not function as expected.
# Activate service account using the key file specified in the environment variable GOOGLE_APPLICATION_CREDENTIALS
gcloud auth activate-service-account --key-file=$GOOGLE_APPLICATION_CREDENTIALS &&
# List all compute operations with operationType of preempted instances in JSON format for the specified Google Cloud Platform project
gcloud compute operations list --filter='operationType:(compute.instances.preempted)' --format=json --project=${GCP_PROJECT_ID} |
# Use jq to filter and format the output based on start time and age
jq -r --arg now "$(date -u +%s)" '[.[] | select((.startTime | sub("\\.[0-9]+"; "") | strptime("%Y-%m-%dT%H:%M:%S%z") | mktime) > ($now | tonumber - (${AGE}*60)))] '
This multi-line command is helpful for newer or less experienced devops engineers as it breaks down the original command into smaller steps with descriptive comments for each step. This helps them understand what each part of the command is doing and how it contributes to the overall functionality.