feat(lab-03): complete Phase 4 - Compute & EC2 lab
Phase Plans (5 files): - 04-RESEARCH.md: Domain research on Docker limits, healthchecks, EC2 parallels - 04-VALIDATION.md: Success criteria and validation strategy - 04-01-PLAN.md: Test infrastructure (RED phase) - 04-02-PLAN.md: Diátxis documentation - 04-03-PLAN.md: Infrastructure implementation (GREEN phase) Test Scripts (6 files, 1300+ lines): - 01-resource-limits-test.sh: Validate INF-03 compliance - 02-healthcheck-test.sh: Validate healthcheck configuration - 03-enforcement-test.sh: Verify resource limits with docker stats - 04-verify-infrastructure.sh: Infrastructure verification - 99-final-verification.sh: End-to-end student verification - run-all-tests.sh: Test orchestration with fail-fast - quick-test.sh: Fast validation (<30s) Documentation (11 files, 2500+ lines): Tutorials (3): - 01-set-resource-limits.md: EC2 instance types, Docker limits syntax - 02-implement-healthchecks.md: ELB health check parallels - 03-dependencies-with-health.md: depends_on with service_healthy How-to Guides (4): - check-resource-usage.md: docker stats monitoring - test-limits-enforcement.md: Stress testing CPU/memory - custom-healthcheck.md: HTTP, TCP, database healthchecks - instance-type-mapping.md: Docker limits → EC2 mapping Reference (3): - compose-resources-syntax.md: Complete deploy.resources reference - healthcheck-syntax.md: All healthcheck parameters - ec2-instance-mapping.md: Instance type mapping table Explanation (1): - compute-ec2-parallels.md: Container=EC2, Limits=Instance Type, Healthcheck=ELB Infrastructure: - docker-compose.yml: 5 services (web, app, worker, db, stress-test) All services: INF-03 compliant (cpus + memory limits) All services: healthcheck configured EC2 parallels: t2.nano, t2.micro, t2.small, t2.medium, m5.large - Dockerfile: Alpine 3.19 + stress tools + non-root user Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
94
labs/lab-03-compute/how-to-guides/check-resource-usage.md
Normal file
94
labs/lab-03-compute/how-to-guides/check-resource-usage.md
Normal file
@@ -0,0 +1,94 @@
|
||||
# How-to: Verificare l'Utilizzo delle Risorse
|
||||
|
||||
Come monitorare l'utilizzo CPU e memoria dei container Docker.
|
||||
|
||||
## Utilizzo Base
|
||||
|
||||
### Snapshot Singolo
|
||||
|
||||
```bash
|
||||
docker stats --no-stream
|
||||
```
|
||||
|
||||
Output:
|
||||
```
|
||||
CONTAINER NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
|
||||
12345 lab03-web 0.01% 2.5MiB / 1GiB 0.24% 1.2kB / 0B 0B / 0B 2
|
||||
```
|
||||
|
||||
### Monitoraggio in Tempo Reale
|
||||
|
||||
```bash
|
||||
docker stats
|
||||
```
|
||||
|
||||
Premi `Ctrl+C` per uscire.
|
||||
|
||||
### Container Specifico
|
||||
|
||||
```bash
|
||||
docker stats lab03-web
|
||||
```
|
||||
|
||||
## Formattazione Avanzata
|
||||
|
||||
### Solo Container e CPU/Memoria
|
||||
|
||||
```bash
|
||||
docker stats --format "table {{.Container}}\t{{.CPUPerc}}\t{{.MemUsage}}"
|
||||
```
|
||||
|
||||
### Output senza header
|
||||
|
||||
```bash
|
||||
docker stats --no-stream --format "{{.Container}}: {{.CPUPerc}}, {{.MemUsage}}"
|
||||
```
|
||||
|
||||
### Output CSV
|
||||
|
||||
```bash
|
||||
docker stats --no-stream --format "{{.Container}},{{.CPUPerc}},{{.MemUsage}}"
|
||||
```
|
||||
|
||||
## Interpretare l'Output
|
||||
|
||||
### CPU Percentage
|
||||
- `0.01%` - Container idle
|
||||
- `50%` - Container usa mezza CPU
|
||||
- `100%` - Container usa 1 CPU completa
|
||||
- `>100%` - Container usa più di 1 CPU (multi-core)
|
||||
|
||||
### Memory Usage
|
||||
- `2.5MiB / 1GiB` - Usati 2.5 MB su 1 GB di limite
|
||||
- `512MiB / 512MiB` - Al limite (potrebbe causare OOM)
|
||||
- `980MiB / 1GiB` - Vicino al limite (watch!)
|
||||
|
||||
### Memory Percentage
|
||||
- `<50%` - Sotto l'half del limite (OK)
|
||||
- `50-80%` - Nella norma (monitorare)
|
||||
- `>80%` - Vicino al limite (attenzione)
|
||||
- `>95%` - A rischio di OOM kill
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Container usa 0% CPU
|
||||
Container potrebbe essere idle o bloccato. Verifica:
|
||||
```bash
|
||||
docker exec lab03-web ps aux
|
||||
```
|
||||
|
||||
### Memory usage alto
|
||||
Identifica il processo che usa più memoria:
|
||||
```bash
|
||||
docker exec lab03-web ps aux --sort=-%mem | head -5
|
||||
```
|
||||
|
||||
### Container OOM killed
|
||||
Cerca "OOM" nei log:
|
||||
```bash
|
||||
docker inspect lab03-web --format '{{.State.OOMKilled}}'
|
||||
```
|
||||
|
||||
## Vedi Anche
|
||||
- How-to: Testare Limits Enforcement
|
||||
- Reference: Compose Resources Syntax
|
||||
Reference in New Issue
Block a user