
Capturing Metrics from a Specific Namespace in AWS Container Insights
How to capture metrics only from a specific namespace in AWS Container Insights for an EKS cluster
Published Mar 5, 2025
To capture metrics only from a specific namespace in AWS Container Insights for an EKS cluster, follow these steps:
The CloudWatch Agent collects metrics from all namespaces by default, but you can modify the agent’s configuration to include only specific namespaces.
1 Edit the CloudWatch Agent ConfigMap
- Identify and edit the CloudWatch Agent ConfigMap (
cwagent-config
) in your cluster:
kubectl edit configmap cwagent-config -n amazon-cloudwatch
2 Modify the
logs
and metrics
sections- Add the
namespace
filter undermetrics_collected.prometheus
:
{
"agent": {
"region": "your-region"
},
"logs": {
"metrics_collected": {
"prometheus": {
"cluster_name": "your-cluster",
"prometheus_config_path": "/etc/prometheusconfig/prometheus.yaml",
"ecs_service_discovery": {
"enable": true
},
"include_namespaces": [
"your-namespace"
]
}
}
}
}
3 Apply the updated ConfigMap
- Save your changes and apply the updated configuration:
kubectl apply -f cwagent-config.yaml -n amazon-cloudwatch
4 Restart the CloudWatch Agent DaemonSet
- Restart the DaemonSet to apply the new configuration:
kubectl rollout restart daemonset cloudwatch-agent -n amazon-cloudwatch
After applying the changes, verify that metrics are only collected from the specific namespace:
kubectl logs -l app=cloudwatch-agent -n amazon-cloudwatch --tail
=100- Check CloudWatch logs to ensure only the desired namespace's metrics are being reported.