CloudWatch Monitoring & Alerting

Setting Up CloudWatch Monitoring for VPC Resources

ℹ️ What is CloudWatch Monitoring?
Amazon CloudWatch gives you monitoring and observability for your AWS resources. For a VPC environment, CloudWatch helps you track network performance, security events, and resource usage so you can ensure optimal operation.

Key Metrics to Monitor

🔍 VPC-Related Metrics:

  • NAT Gateway: Bandwidth utilization, packet drop count, connection attempts
  • VPN Connections: Tunnel state, data transfer metrics
  • EC2 Instances: Network performance, CPU, memory utilization
  • VPC Flow Logs: Security events, traffic patterns

Setting Up NAT Gateway Monitoring

  1. Access the CloudWatch console:

    • Go to the CloudWatch console
    • Select Metrics from the left navigation menu
    • Click All metrics
  2. Browse the NAT Gateway metrics:

    • Click AWS/NATGateway
    • Select NAT Gateway Metrics
    • Select your NAT Gateway IDs

Create VPC Create VPC

  1. Key NAT Gateway metrics to monitor:
    • BytesInFromDestination: Data received from the destination
    • BytesOutToDestination: Data sent to the destination
    • PacketDropCount: Packets dropped by the NAT Gateway
    • ActiveConnectionCount: Active connections through the NAT Gateway

Create VPC

Create VPC

Create VPC

Creating CloudWatch Alarms

  1. Create an alarm for NAT Gateway packet drops:
    • Select the PacketDropCount metric
    • Click Create alarm

Create VPC

  1. Configure the alarm condition:
    • Statistic: Select Sum
    • Period: Select 5 minutes
    • Threshold type: Select Static
    • Condition: Select Greater than
    • Threshold value: Enter 100 (adjust to fit your needs)

Create VPC

Create VPC

  1. Configure the alarm action:
    • Alarm state trigger: Select In alarm
    • SNS topic: Create a new topic or select an existing one
    • Topic name: Enter VPC-Alerts
    • Email endpoints: Enter your email address
    • Click Next

Create VPC

Create VPC

  1. Name and create the alarm:
    • Alarm name: Enter NAT-Gateway-Packet-Drops
    • Alarm description: Enter Alert when NAT Gateway drops packets
    • Click Next, then click Create alarm.

Create VPC

Create VPC

Create VPC

Analyzing VPC Flow Logs

  1. Create a custom metric from Flow Logs:
    • Go to the CloudWatch console
    • Select Log groups
    • Find /aws/vpc/flowlogs
    • Click Create metric filter

Create VPC

  1. Configure the metric filter for rejected connections:
    • Filter pattern: Enter [version, account, eni, source, destination, srcport, destport, protocol, packets, bytes, windowstart, windowend, action="REJECT", flowlogstatus]
    • Select log data to test: Select the network interfaces attached to Public Subnet - SG
    • Test pattern: Click to test against sample data
    • Click Next

Create VPC Create VPC Create VPC Create VPC

  1. Define the metric details:
    • Filter name: Enter Rejected-Connections
    • Metric namespace: Enter VPC/Security
    • Metric name: Enter RejectedConnections
    • Metric value: Enter 1
    • Click Create metric filter

Create VPC Create VPC Create VPC

Create VPC

Creating a Dashboard

  1. Create a CloudWatch Dashboard:
    • Go to Dashboards
    • Click Create dashboard
    • Dashboard name: Enter VPC-Monitoring-Dashboard
    • Click Create dashboard

Create VPC Create VPC

  1. Add widgets to the dashboard:
    • Click Add widget
    • Select the Line chart type
    • Click Configure

Create VPC

  1. Configure the dashboard widget:
    • Metrics: Add the NAT Gateway metrics
    • Browse: Select the metrics you need
    • Click Create widget

Create VPC Create VPC Create VPC

Create VPC

  • Repeat the same process for the VPN metrics and EC2 metrics

Production Monitoring Best Practices

🔍 Essential Alarms for Production:

NAT Gateway Alarms:
  - PacketDropCount > threshold
  - ErrorPortAllocation > 0
  - ActiveConnectionCount > 80% of limit

VPN Connection Alarms:
  - TunnelState != UP
  - TunnelIpAddress changes

EC2 Instance Alarms:
  - CPUUtilization > 80%
  - NetworkPacketsIn/Out anomalies
  - StatusCheckFailed > 0

💡 Monitoring Strategy:

  • Proactive: Set up predictive alarms before issues occur
  • Comprehensive: Monitor all critical components
  • Actionable: Make sure alarms lead to specific remediation steps
  • Cost-Aware: Balance monitoring coverage against cost

🔒 Security Monitoring:

Flow Log Patterns to Monitor:
  - High volume of rejected connections
  - Unusual outbound traffic patterns
  - Connections to suspicious IP addresses
  - Port scanning attempts
  - Data exfiltration indicators

📊 Performance Baselines:

  • Establish normal operating ranges for all metrics
  • Set up anomaly detection for unusual patterns
  • Create custom metrics for business-specific KPIs
  • Implement automated responses where appropriate

💰 Cost Optimization:

  • Use metric filters to reduce log storage costs
  • Set appropriate retention periods for different log types
  • Leverage CloudWatch Insights for complex queries
  • Consider exporting data to S3 for long-term analysis

⚡ Operational Excellence:

  • Create runbooks for common alarm scenarios
  • Implement automated remediation where possible
  • Regularly review and tune alarm thresholds
  • Integrate with your incident management system