Xoxoftware - XOXO Creative Studio | Web & Mobile App Development | Fred Cheung | Hong Kong
AWSMonitoring

Amazon CloudWatch

Monitoring and observability — collect metrics, logs, and traces from AWS resources and applications with alarms, dashboards, and automated actions.

Overview

Amazon CloudWatch is the central monitoring and observability service for AWS — it collects metrics, logs, and events from AWS resources and applications, provides dashboards for visualisation, and triggers alarms and automated actions based on thresholds or anomalies.


Core Concepts

ConceptDescription
MetricA time-ordered series of data points (e.g., CPUUtilization, NetworkIn)
NamespaceContainer for metrics belonging to a service (e.g., AWS/EC2, AWS/RDS)
DimensionName-value pair that identifies a metric (e.g., InstanceId=i-1234)
StatisticAggregation applied over a period: Average, Sum, Min, Max, SampleCount, pNN
PeriodLength of time for each data point (default 60 s for basic; 1 s for detailed)
AlarmWatches a metric and triggers an action when a threshold is breached
Composite AlarmCombines multiple alarms with AND/OR logic to reduce alarm noise
Log GroupCollection of log streams that share retention, access, and monitoring settings
Log StreamSequence of log events from a single source (e.g., one EC2 instance)
Custom MetricApplication-defined metric published via PutMetricData API or CloudWatch Agent
Metric FilterExtracts metric values from log data using pattern matching

CloudWatch Metrics

Default vs Detailed Monitoring

Monitoring LevelResolutionCostExamples
Basic5-minuteFreeEC2 CPU, Network, Disk (host-level)
Detailed1-minuteChargedEnabled per service (EC2: $2.10/instance/month)
High-Resolution1-secondChargedCustom metrics with StorageResolution=1

Key Default Metrics by Service

ServiceIncluded MetricsNOT Included (need agent)
EC2CPUUtilization, NetworkIn/Out, DiskReadOps, StatusCheckFailedMemory, Disk space, Process count
RDSCPUUtilization, DatabaseConnections, FreeableMemory, IOPSOS-level metrics (enhanced)
ELBRequestCount, TargetResponseTime, HealthyHostCountN/A
LambdaInvocations, Duration, Errors, Throttles, ConcurrentExecutionsN/A

Exam Trap: EC2 does NOT report memory utilization or disk space as default metrics. The CloudWatch Agent must be installed to collect these.


CloudWatch Agent

EC2 Instance / On-Premises Server
    └── CloudWatch Agent (installed)
        ├── Collects: Memory %, Disk %, Swap, Netstat, Processes
        ├── Collects: Application logs → Log Groups
        └── Publishes: Custom metrics → CloudWatch Metrics
  • Installed via SSM Run Command or manually
  • Configured with a JSON configuration file (stored in SSM Parameter Store)
  • Supports both EC2 instances and on-premises servers
  • Unified CloudWatch Agent replaces older CloudWatch Logs Agent and custom scripts

CloudWatch Alarms

Alarm StateMeaning
OKMetric is within the defined threshold
ALARMMetric has breached the threshold
INSUFFICIENT_DATANot enough data to determine state

Alarm Actions

Action TargetDescription
SNS NotificationSend alert to email, SMS, Lambda, or SQS
Auto ScalingScale out/in a group based on metric threshold
EC2 ActionStop, terminate, reboot, or recover an instance
Systems ManagerRun an SSM automation document

Alarm Evaluation

  • Period: How long each data point covers (e.g., 300 s)
  • Evaluation Periods: How many consecutive periods must breach the threshold
  • Datapoints to Alarm: Minimum breaching points within the evaluation window (M of N)

CloudWatch Logs

Application → CloudWatch Agent → Log Group → Log Stream

                                     ├── Metric Filter → Custom Metric → Alarm
                                     ├── Subscription Filter → Lambda / Kinesis / OpenSearch
                                     ├── Export to S3 (async, batch)
                                     └── Logs Insights (ad-hoc queries)

Key Features

FeatureDescription
RetentionConfigurable: 1 day to 10 years, or never expire
Metric FilterPattern-based extraction of numeric values from log lines
Subscription FilterReal-time stream of log data to Lambda, Kinesis, or OpenSearch
Logs InsightsInteractive query language for ad-hoc log analysis
Cross-accountSend logs to a central account via subscription filters
Export to S3Async batch export for long-term archival (not real-time)
Live TailReal-time streaming view of incoming log events in console

CloudWatch Logs Insights

Query language for analysing log data:

fields @timestamp, @message
| filter @message like /ERROR/
| stats count(*) as errorCount by bin(5m)
| sort errorCount desc
| limit 20
  • Supports filtering, aggregation, sorting, and visualisation
  • Queries multiple log groups simultaneously
  • Results can be exported or added to dashboards

CloudWatch Dashboards

  • Custom visualisations with graphs, metrics, alarms, and text widgets
  • Cross-account and cross-region widgets supported
  • Automatic dashboards for common services (EC2, Lambda, etc.)

Common Use Cases

  • Infrastructure monitoring — Track CPU, memory, disk, and network metrics for EC2, RDS, and ECS with threshold alarms.
  • Application log analysis — Centralise application logs and use Logs Insights for debugging and trend analysis.
  • Auto-scaling trigger — CloudWatch alarm on CPU or custom metric triggers Auto Scaling policy to add/remove instances.
  • Anomaly detection — Machine learning-based anomaly detection on metrics to alert on unusual patterns.
  • Cross-account observability — Aggregate metrics and logs from multiple accounts into a central monitoring account.

SAA/SAP Exam Tips

SAA Tip: "Monitor memory utilization on EC2" → Install CloudWatch Agent. Default EC2 metrics do NOT include memory or disk space.

SAA Tip: "Real-time log processing" → CloudWatch Logs Subscription Filter to Lambda or Kinesis. S3 export is async/batch — not real-time.

SAP Tip: Composite alarms reduce alarm noise by combining multiple alarms with AND/OR logic — avoiding alert fatigue when multiple related metrics fire simultaneously.


Cross-Cloud Equivalents

ProviderService / SolutionNotes
AWSAmazon CloudWatchBaseline
AzureAzure Monitor + Log AnalyticsAzure Monitor ≈ metrics; Log Analytics ≈ Logs
GCPGoogle Cloud Monitoring + Cloud LoggingSeparate metrics and logging services
On-PremisesPrometheus + Grafana, Datadog, Splunk, ELK StackSelf-managed or SaaS observability

Pricing Model

DimensionUnitNotes
Custom metricsPer metric/monthFirst 10 free; $0.30/metric after
Detailed monitoringPer instance/month$2.10/instance for 1-minute resolution
DashboardsPer dashboard/monthFirst 3 free; $3/dashboard after
AlarmsPer alarm/monthStandard $0.10; high-resolution $0.30
Logs ingestionPer GB ingested+ storage per GB/month after retention period
Logs Insights queriesPer GB scannedCharged per query based on data scanned
API requestsPer 1,000 requestsGetMetricData, PutMetricData, etc.

  • AWS X-Ray — distributed tracing for application performance analysis
  • AWS Config — configuration compliance (different from performance monitoring)
  • Amazon EC2 — primary source of infrastructure metrics
  • Auto Scaling — CloudWatch alarms drive scaling policies
Built by Fred Cheung @CookedRicer · Powered by Fumadocs & Github Copilot

On this page