Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

After installing the CloudWatch Agent, the user needs to be configured before it can be startedstarts. It can be configured in two ways: by manually creating a config file or using the wizard (In which the user needs to answer a series of questions). It generates a config file.

...

1. Manually create config.json

The log agent uses the config file located at the below path:

...

Code Block
{
     "agent": {
         "run_as_user": "root"
     },
     "logs": {
         "logs_collected": {
             "files": {
                 "collect_list": [
                     {
                         "file_path": "/var/log/apache2/error.log",
                         "log_group_name": "apache-error-log",
                         "log_stream_name": "{instance_id}"
                     }
                 ]
             }
         }
     }
 }


In the above config file, "file_path" is the path to the log file from which the user wants to collect data from. For the naming of Log Group and Log Streams, log_group_name and log_stream_name can be used respectively in the CloudWatch.

2. Wizard

Follow the below command to start the wizard run:

Code Block
$ sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-config-wizard

In the wizard run, there are a number of questions as the Log Agent used to collect system-level metrics, so users need to answer these questions and can ignore the questions that are not related to collecting logs. While using the wizard, users can always take the generated config file and then manually add it to any additional instances. 

Start the Agent

Run the below command to run the Agent.

Code Block
$ sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c file:/opt/aws/amazon-cloudwatch-agent/bin/config.json -s