Cloud watch:
- aws providing service to monitoring and observability
features: VM, EKS, Lambda, db…etc
- metrics – Performing operations (cpu, network, disk and memory)
- logs – what application saying (INfo, error, status, timestamp, access log)
- Alarms – know when its break – (Notifications, Email when error or metric reach max)
- Dashboards – Visual youe graphs and logs table using metric and logs
Key Terms:
- Namespace – conatiner for metrics (Ex: aws/ec2, Cwagent , Myapp)
- metrics – A time order set of data points Ex: (cpu utilization)
- Dimension – Name/value pair EX: InstanceID=i-bdsfbfkjbsac, (post, get, patch, delete= methd)
- logs group – collection of logs steam, shared retension and permissions
- logs steam – squance of events from one source.
- Metric-filtter – rule that turns log text patterns into a numeric matrics
- Cwagent – software on the vm, ship logs and extra metrics
cloud watch flow for EC2

Default vs agent
| Capability |
Default (no agent) |
With CloudWatch Agent |
| CPU utilization |
Yes |
Yes |
| Network in/out |
Yes |
Yes |
| Disk I/O (EBS) |
Yes |
Yes |
| Memory usage |
No |
Yes |
| Disk space used % |
No |
Yes |
| Application logs |
No |
Yes |
| Metric interval |
5 min (1 min with detailed monitoring) |
Down to 1 s (high-resolution) |
| why |
measured by hypervisor |
run inside the OS |

create app_logs.py
import json
import time
import random
import uuid
import logging
from datetime import datetime, timezone
# Application configuration
APP_NAME = "demo-web-app"
LOG_FILE = "application.log"
# Configure Python logging
logging.basicConfig(
filename=LOG_FILE,
level=logging.INFO,
format="%(message)s"
)
# Sample APIs
apis = [
"/api/users",
"/api/orders",
"/api/products",
"/api/payments",
"/api/login",
"/api/logout",
"/health"
]
methods = ["GET", "POST", "PUT", "DELETE"]
levels = ["INFO", "INFO", "INFO", "WARNING", "ERROR"]
while True:
level = random.choice(levels)
status = random.choice([200, 200, 201, 400, 404, 500, 503])
latency = random.randint(20, 3000)
# Generate realistic log messages
if status >= 500:
message = "Internal server error"
elif status >= 400:
message = "Client request failed"
else:
message = "Request processed successfully"
log_data = {
"timestamp": datetime.now(timezone.utc).isoformat(),
"application": APP_NAME,
"environment": "development",
"level": level,
"request_id": str(uuid.uuid4()),
"method": random.choice(methods),
"path": random.choice(apis),
"status_code": status,
"response_time_ms": latency,
"message": message,
"host": "app-server-01",
"service": "backend"
}
log_entry = json.dumps(log_data)
# Write logs to file
logging.info(log_entry)
# Print logs to console
print(log_entry)
time.sleep(2)
Run python3 app_logs.py > /var/logs/app.logs
# output
{
"timestamp": "2026-11-28T03:00:00+00:00",
"application": "demo-web-app",
"environment": "development",
"level": "ERROR",
"request_id": "abc-123-xyz",
"method": "POST",
"path": "/api/payments",
"status_code": 500,
"response_time_ms": 2500,
"message": "Internal server error",
"host": "app-server-01",
"service": "backend"
}
Task
- create vm and enable cloudwatch agent and run above sample code and generate logs
-