MultiCloud Classroom notes 28/Nov/2026

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:

  1. Namespace – conatiner for metrics (Ex: aws/ec2, Cwagent , Myapp)
  2. metrics – A time order set of data points Ex: (cpu utilization)
  3. Dimension – Name/value pair EX: InstanceID=i-bdsfbfkjbsac, (post, get, patch, delete= methd)
  4. logs group – collection of logs steam, shared retension and permissions
  5. logs steam – squance of events from one source.
  6. Metric-filtter – rule that turns log text patterns into a numeric matrics
  7. 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

  1. create vm and enable cloudwatch agent and run above sample code and generate logs

Leave a comment

Turn on JavaScript to leave a comment.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Please turn AdBlock off
Animated Social Media Icons by Acurax Responsive Web Designing Company
Exit mobile version
%%footer%%