Configuring Apache EC2 instance - Amazon CloudWatch Monitoring Framework

Configuring Apache EC2 instance

This solution currently only supports Apache workloads. The dashboard deployed by the solution assumes that your instances are configured correctly and sends the appropriate metrics and logs to Amazon CloudWatch. If your EC2 instances do not send metrics and logs in the appropriate format, they will not appear on the dashboard.

For more information about metrics and logs, refer to Apache key performance indicators.

Amazon CloudWatch agent for Apache

Refer to the default configuration in the apache.json, infra.json, and httpd.conf files to ensure that your EC2 instance CloudWatch agent is sending metrics and logs in the appropriate format.

The following example code is from the apache.json file. This file identifies the appropriate process-level metrics being sent to Amazon CloudWatch.

"metrics_collected": { "procstat": [ { "exe": "httpd", "measurement": [ "cpu_usage", "memory_rss", "memory_vms", "read_bytes", "write_bytes", "read_count", "write_count" ] } ]

The following example code is also from the apache.json and it identifies the access log file path and CloudWatch log group name.

"logs": { "logs_collected": { "files": { "collect_list": [ { "file_path": "/var/log/www/error/*", "log_group_name": "/cw-monitoring-framework/apache/error", "log_stream_name": "{instance_id}" }, { "file_path": "/var/log/www/access/*", "log_group_name": "/cw-monitoring-framework/apache/access", "log_stream_name": "{instance_id}" } ] } } }

httpd.conf for Apache workload

The following code example shows the appropriate log format in the httpd.conf file to support dashboard queries.

<IfModule logio_module> # You need to enable mod_logio.c to use %I and %O LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio LogFormat "{ \"time\":\"%{%Y-%m-%d}tT%{%T}t.%{msec_frac}tZ\", \"process\":\"%D\", \"filename\":\"%f\", \"remoteIP\":\"%a\", \"host\":\"%V\", \"request\":\"%U\", \"query\":\"%q\", \"method\":\"%m\", \"status\":\"%>s\", \"responseTime\":\"%D\", \"bytesReceived\":\"%I\", \"bytesSent\":\"%O\", \"userAgent\":\"%{User-agent}i\",\"referer\":\"%{Referer}i\"}" cloudwatch </IfModule>

Optionally, you can use a SSM run command to configure your instances with needed configurations. For more information, refer to AWS Systems Manager Run Command in the AWS Systems Manager User Guide.

Add or remove EC2 instance tags

To add or remove EC2 instances from the dashboard, you can add or remove the pre-determined tag at any point. These changes should be updated on the dashboard in approximately five minutes.

To add an Amazon EC2 tag:

  1. Sign in to the Amazon EC2 console.

  2. Select the instance you want to onboard to the dashboard

  3. Select the Tags tab. Choose Manage tags.

  4. Choose Add tag to the instance and provide the key-value pair you provided during deployment. If you used default value with deployment, it would look as follows

Figure 5: Add a tag

6. Click Save.

To remove an Amazon EC2 tag:

  1. Sign in to the Amazon EC2 console

  2. Select the instance you want to onboard to the dashboard

  3. Select the Tags tab. Choose Manage tags.

  4. Identify the workload specific tag, choose Remove.

  5. Choose Save.