How to Monitor AWS ECS with Vigilmon
AWS Elastic Container Service (ECS) is a fully managed container orchestration service that runs Docker containers at scale. Whether you're using ECS with Fargate (serverless) or EC2 launch type, monitoring your containers and services requires more than just CloudWatch metrics.
This guide covers how to set up external monitoring for your ECS services using Vigilmon.
Why External Monitoring for ECS?
CloudWatch gives you internal metrics (CPU, memory, network), but it can't tell you:
- Is your service actually responding to user requests?
- Is the load balancer routing correctly?
- Is your health check returning the right response?
- Is your app slow even when container health checks pass?
Vigilmon monitors from outside AWS, giving you the user's perspective.
ECS Architecture and What to Monitor
Users → Route 53 → ALB → ECS Service → Tasks (containers)
↑
Target Group health checks
↑
Vigilmon external monitoring
Primary monitoring target: Your Application Load Balancer (ALB) endpoint, because:
- It represents what users actually hit
- It validates the full stack (ALB → ECS → container → app → DB)
- ALB DNS is stable even when tasks restart
Step 1: Add a Health Check to Your Container
For a Node.js service in ECS:
// src/health.js
const express = require('express');
const router = express.Router();
router.get('/health', async (req, res) => {
const checks = {};
let healthy = true;
// Check database (if applicable)
try {
await db.query('SELECT 1');
checks.db = 'ok';
} catch (e) {
checks.db = 'error';
healthy = false;
}
res.status(healthy ? 200 : 503).json({
status: healthy ? 'ok' : 'degraded',
checks,
taskId: process.env.ECS_CONTAINER_METADATA_URI, // ECS metadata
});
});
module.exports = router;
Step 2: Configure ECS Health Check in Task Definition
{
"containerDefinitions": [
{
"name": "myapp",
"image": "123456789.dkr.ecr.us-east-1.amazonaws.com/myapp:latest",
"healthCheck": {
"command": ["CMD-SHELL", "curl -f http://localhost:8080/health || exit 1"],
"interval": 30,
"timeout": 10,
"retries": 3,
"startPeriod": 60
},
"portMappings": [
{
"containerPort": 8080,
"protocol": "tcp"
}
]
}
]
}
Step 3: Configure ALB Target Group Health Check
In your CloudFormation or Terraform:
# Terraform
resource "aws_lb_target_group" "myapp" {
name = "myapp-tg"
port = 8080
protocol = "HTTP"
vpc_id = var.vpc_id
health_check {
enabled = true
path = "/health"
healthy_threshold = 2
unhealthy_threshold = 3
timeout = 10
interval = 30
matcher = "200"
}
target_type = "ip" # For Fargate
}
Step 4: Add External Monitoring in Vigilmon
- Sign up at vigilmon.online
- Click Add Monitor → HTTP/HTTPS Monitor
- URL:
https://your-alb-dns.us-east-1.elb.amazonaws.com/health(or your custom domain if Route 53 is configured) - Expected status: 200
- Expected keyword:
"status":"ok" - Check interval: 1 minute
- Alert via Slack, email, or PagerDuty webhook
Step 5: Monitor ECS Scheduled Tasks with Heartbeat
For ECS Scheduled Tasks (batch jobs, cron-based tasks), use a Vigilmon heartbeat monitor:
# ecs_task.py — scheduled task
import urllib.request
import os
def run_task():
# ... your task logic ...
# Ping Vigilmon heartbeat on success
try:
urllib.request.urlopen(
f"https://hb.vigilmon.online/{os.environ['VIGILMON_HB_ID']}"
)
except Exception:
pass # Don't fail the task if heartbeat fails
if __name__ == "__main__":
run_task()
Set the heartbeat expected interval in Vigilmon to match your ECS scheduled task frequency.
Multi-Region ECS Monitoring
If you run ECS in multiple AWS regions:
| Monitor | URL | Purpose |
|---|---|---|
| US East | https://us-east-api.example.com/health |
Primary region up |
| US West | https://us-west-api.example.com/health |
DR region up |
| EU West | https://eu-api.example.com/health |
EU region up |
Conclusion
AWS ECS is a powerful container platform, but CloudWatch alone won't tell you when your users can't reach your service. Vigilmon's external monitoring validates the full request path from the internet to your container — and alerts you within 60 seconds of failure.
Start monitoring your ECS services for free at vigilmon.online
Top comments (0)