cs.oldnet

All sheets / Observability

CloudWatch & X-Ray

AWS-native metrics, logs, alarms and tracing.

CloudWatch metrics

  • Namespace → metric name → dimensions (e.g. AWS/Lambda, Errors, FunctionName=x).
  • Standard resolution 1 min; high resolution 1 s (custom metrics).
  • Statistics: Sum, Average, Min, Max, SampleCount, percentiles (p99).
  • Embedded Metric Format (EMF): emit metrics via structured logs, no API calls.
console.log(JSON.stringify({
  _aws: { Timestamp: Date.now(), CloudWatchMetrics: [{ Namespace: 'Checkout',
    Dimensions: [['Service']], Metrics: [{ Name: 'Latency', Unit: 'Milliseconds' }] }] },
  Service: 'api', Latency: 123,
}));

Key metrics to know

ServiceWatch
LambdaErrors, Throttles, Duration, ConcurrentExecutions, IteratorAge
SQSApproximateNumberOfMessagesVisible, ApproximateAgeOfOldestMessage
ALBHTTPCode_Target_5XX_Count, TargetResponseTime, UnHealthyHostCount
ECSCPUUtilization, MemoryUtilization, RunningTaskCount
API Gateway5XXError, 4XXError, Latency, IntegrationLatency
DynamoDBThrottledRequests, ConsumedRead/WriteCapacityUnits
RDSCPUUtilization, DatabaseConnections, FreeStorageSpace, ReplicaLag

Alarms

  • States: OK, ALARM, INSUFFICIENT_DATA. Evaluate N of M datapoints.
  • Actions: SNS, Auto Scaling, EC2 actions, Systems Manager.
  • Composite alarms combine alarms (reduce noise).
  • Anomaly detection bands for seasonal metrics.
  • Treat missing data explicitly (notBreaching for sparse error metrics).

Logs Insights

fields @timestamp, @message, level, traceId
| filter level = "ERROR" and service = "checkout"
| sort @timestamp desc
| limit 50

stats count(*) as errors by bin(5m), service

filter @type = "REPORT"
| stats avg(@duration), pct(@duration, 99), max(@maxMemoryUsed / 1000 / 1000) by bin(1h)

parse @message "user=* action=*" as user, action | stats count() by action

Metric filters turn log patterns into metrics; subscription filters stream logs to Lambda/Firehose/OpenSearch.

X-Ray

  • Traces → segments (per service) → subsegments (downstream calls).
  • Annotations: indexed, filterable (annotation.customer = "acme"). Metadata: not indexed.
  • Service map shows dependencies, latency and error rates per edge.
  • Sampling rules: default first request/sec + 5% of additional.
  • Enable: Lambda active tracing, API Gateway tracing, ECS sidecar daemon or ADOT collector.
  • Filter expressions: service("checkout") AND responsetime > 2, fault = true.

Other CloudWatch features

  • Synthetics canaries for uptime/user flows.
  • RUM for browser performance.
  • ServiceLens / Application Signals: SLOs and service health from metrics + traces.
  • Container Insights and Lambda Insights for deeper runtime metrics.
  • Dashboards across accounts/regions; cross-account observability.