Skip to content

Instantly share code, notes, and snippets.

@thimslugga
Forked from hitman99/gpu_stats.sh
Last active August 16, 2018 17:02
Show Gist options
  • Save thimslugga/0be95a6f58d932aa28fb44567dd63090 to your computer and use it in GitHub Desktop.
Save thimslugga/0be95a6f58d932aa28fb44567dd63090 to your computer and use it in GitHub Desktop.
CloudWatch metrics for GPU on EC2 G3 instance
#!/bin/bash
# Get region
AZ=$(bash -c "curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone")
REGION=${AZ::-1}
IFS=', ' read -r -a STATS <<< `nvidia-smi --query-gpu=temperature.gpu,memory.used,memory.free,utilization.gpu,utilization.memory --format=csv,nounits,noheader`
#echo ${STATS[@]}
# Send values to CloudWatch
aws cloudwatch --region $REGION put-metric-data --metric-name Temperature --namespace GPUStats --value ${STATS[0]}
aws cloudwatch --region $REGION put-metric-data --metric-name MemoryUsed --namespace GPUStats --unit Megabytes --value ${STATS[1]}
aws cloudwatch --region $REGION put-metric-data --metric-name MemoryFree --namespace GPUStats --unit Megabytes --value ${STATS[2]}
aws cloudwatch --region $REGION put-metric-data --metric-name GPUUtilization --namespace GPUStats --value ${STATS[3]}
aws cloudwatch --region $REGION put-metric-data --metric-name MemoryUtilization --namespace GPUStats --value ${STATS[4]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment