- Newest
- Most votes
- Most comments
To get GPU metrics for each individual GPU card attached to your EC2 instance, you need to modify your CloudWatch query to include the 'index' dimension. This dimension represents the individual GPU index within the instance.
Here's how you can modify your existing code to retrieve metrics for individual GPUs:
-
First, determine the number of GPUs on your instance. For a g5.48xlarge, this would be 8 GPUs (indexed 0-7).
-
Then, iterate through each GPU index and make a separate CloudWatch query for each:
for gpu_index in range(8): # Adjust the range based on the number of GPUs metrics = cloudwatch_client.get_metric_statistics( Namespace='CWAgent', MetricName='nvidia_smi_utilization_gpu', Dimensions=[ {'Name': 'InstanceId', 'Value': instance_id}, {'Name': 'index', 'Value': str(gpu_index)} ], StartTime=start_time, EndTime=end_time, Period=3600, # 1-hour period Statistics=['Average'] ) # Process the metrics for each GPU here
By including the 'index' dimension and iterating through each GPU index, you'll be able to retrieve the individual utilization for each GPU on your instance.
Remember that to get these per-GPU metrics, you need to ensure that your CloudWatch agent is configured to collect them. In your CloudWatch agent configuration file, make sure you have the "nvidia_gpu" field under the "metrics_collected" section, and it should include the metrics you want to collect, such as "utilization_gpu".
If you're using the Deep Learning AMI, you can use the pre-configured service that collects all available GPU metrics. You can enable this by running:
sudo systemctl enable dlami-cloudwatch-agent@all
sudo systemctl start dlami-cloudwatch-agent@all
This will ensure that detailed metrics for each GPU are being collected and sent to CloudWatch, allowing you to query them as described above.
Sources
Send NVIDIA GPU metrics from EC2 instances to CloudWatch | AWS re:Post
Monitor GPUs with CloudWatch - Deep Learning AMI

I tried the above, but the adding
returns None as metrics. However, I can see index as a dimension on the corresponding logs in Cloudwatch.