'How to monitor disk space/file system usage of ecs cluster using fargate

I have created 2 tasks using Fargate and one ECS cluster which is using these 2 tasks in 2 different services. So in short one cluster: 2 services and each services are linked to their own tasks which linked to ECR repo. As per AWS ECS Fargate task storage concept each task got 10gb of docker layer storage with additional 4gb volume mounts. So i would like to monitor the file system storage consumed by containers. I was thinking if anyone can point me how can i attach another docker sidecar to a task which will monitor the consumption of storage by the container created by that task and send it to cloud watch? Each task definition doesn’t have any mount points. Even if task restarts and creates new instances this should apply but i dont want to persist the data even if it restarted.



Solution 1:[1]

I deployed side car that can source required custom data and push to CloudWatch as custom metric using AWS CLI.

https://github.com/saiteja313/amazon-cloudwatch-eks-fargate-metrics/blob/master/cloudwatch-fargate-metrics/cw-put-pod-metrics.sh#L23

Considering your use case, you can run a command like du -h ./ | grep [0-9]G as part of the script and push value to CloudWatch, create alarm if storage goes beyond certain threshold like 7 GB.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 sai