Unified CloudWatch Agent
Learn to deploy and configure the Unified CloudWatch Agent for collecting system metrics, logs, and monitoring individual processes.
What You'll Learn
Introduction to the Unified CloudWatch Agent
The Unified CloudWatch Agent is a powerful tool that runs on your EC2 instances (and on-premises servers) to collect system-level metrics that AWS doesn't provide by default, like RAM usage and disk space. It can also collect logs from your applications and send them to CloudWatch Logs. Without an agent, no logs from inside your EC2 instance will be sent to CloudWatch Logs.
Key Point
The Unified CloudWatch Agent enables collection of system metrics (RAM, disk) and application logs that AWS doesn't provide automatically.
Key Terms
A single agent that collects both system-level metrics and logs from EC2 instances and on-premises servers
The default namespace in CloudWatch where metrics collected by the Unified CloudWatch Agent are stored
AWS service for storing configuration data, used to centrally manage CloudWatch Agent configurations
Unified CloudWatch Agent Architecture
How the agent works across different environments
CloudWatch
Receives metrics and logs
EC2 Instance
With Unified CW Agent
Data Types
Metrics + Logs
On-Premises Server
With Unified CW Agent
What the Unified CloudWatch Agent Collects
- Memory (RAM) utilization and available memory
- Disk space utilization across all mounted volumes
- Swap space usage
- CPU metrics at a more granular level
- Network interface statistics
- Process-level metrics (via procstat plugin)
- Application and system logs
Installing and Configuring the Agent
Install the Agent
Download and install the Unified CloudWatch Agent using SSM Run Command, manually via the command line, or through your configuration management tool.
Create Configuration
Use the agent configuration wizard or create a JSON configuration file specifying which metrics and logs to collect.
Store in Parameter Store
Optionally store the configuration in SSM Parameter Store for centralized management across multiple instances.
Configure IAM Permissions
Ensure the EC2 instance role has CloudWatchAgentServerPolicy or equivalent permissions for pushing metrics and logs.
Start the Agent
Start the agent service, referencing the configuration from Parameter Store or a local file.
IAM Permissions Required
The EC2 instance role must have proper IAM permissions for the agent to work: • CloudWatchAgentServerPolicy (AWS managed policy) or • Custom policy with cloudwatch:PutMetricData and logs:PutLogEvents permissions
Default Namespace
The default namespace for metrics collected by the Unified CloudWatch Agent is 'CWAgent'. You can customize this in the agent configuration if needed. Look for metrics under this namespace in the CloudWatch console.
The procstat Plugin
The procstat plugin is a powerful feature of the Unified CloudWatch Agent that lets you monitor individual processes. You can track how much CPU time and memory specific processes are using. This is invaluable for debugging application performance issues or ensuring critical processes are running within expected parameters.
Key Point
The procstat plugin enables monitoring of individual process metrics like CPU and memory usage.
Process Selection Methods for procstat
| Method | Description | Example | |
|---|---|---|---|
| pid_file | By PID file path | Select process by its PID file | /var/run/nginx.pid |
| exe | By executable name | RegEx match on process name | "exe": "nginx" |
| pattern | By command line | RegEx match on command line | "pattern": "config.*/myapp" |
You can use any combination of these methods to select which processes to monitor
procstat Metrics Examples
- procstat_cpu_time: Total CPU time used by the process
- procstat_cpu_usage: CPU usage percentage
- procstat_memory_rss: Resident Set Size (physical memory)
- procstat_memory_vms: Virtual Memory Size
- procstat_read_bytes: Bytes read by the process
- procstat_write_bytes: Bytes written by the process
Metric Prefix
All metrics collected by the procstat plugin begin with the 'procstat' prefix, making them easy to identify and filter in CloudWatch. For example: procstat_cpu_time, procstat_cpu_usage, procstat_memory_rss.
procstat Configuration Example
Problem
You need to monitor CPU and memory usage for your Nginx web server process
Solution
Why This Works
This configuration uses the 'exe' method to find all processes with 'nginx' in the name and collects CPU time, CPU usage percentage, and resident memory metrics for them.
CloudWatch Agent: Supports Both Linux and Windows
| Platform | Installation | Configuration | |
|---|---|---|---|
| Linux | RPM, DEB, or SSM | JSON config file | Same metrics available |
| Windows | MSI installer or SSM | JSON config file | Same metrics available |
The Unified CloudWatch Agent works consistently across Linux and Windows servers
Pause & Ponder
How would you use the Unified CloudWatch Agent to monitor a microservices architecture?
- •Consider which system metrics are most important for each service type
- •Think about how procstat could help identify resource-hungry processes
- •How would you centralize configuration management across many instances?
Ready to Start Learning?
Dive deeper into this lesson with our interactive learning experience. Complete the quiz and earn 65 XP!
Start This LessonContinue Your Journey
EC2 Instance Type Management
Learn how to change EC2 instance types and understand the requirements for resiz...
Lesson 2EC2 Placement Groups
Master EC2 placement group strategies to optimize instance placement for perform...
Lesson 3EC2 SSH Connectivity & Troubleshooting
Master SSH connections to EC2 instances, including traditional SSH, EC2 Instance...