SetUp CloudWatch Monitoring for an Apache Web Server Errors

Apache Logo

SetUp CloudWatch Monitoring for an Apache Web Server

In this write up we will configure a Web Server to ship its error logs
/var/log/apache2/error.log
off to AWS CloudWatch.
You will need to setup and IAM access key or an IAM Roles to give he server permission to ship the logs off to CloudWatch

AWS LogoApache Logo
/var/log/apache2/error.log

Install CloudWatch Agent

curl https://s3.amazonaws.com/aws-cloudwatch/downloads/latest/awslogs-agent-setup.py -O

sudo python ./awslogs-agent-setup.py --region us-east-1

Configure CloudWatch Agent (IAM Key)

Step 1 of 5: Installing pip ...libyaml-dev does not exist in system python-dev does not exist in system DONE

Step 2 of 5: Downloading the latest CloudWatch Logs agent bits ... DONE

Step 3 of 5: Configuring AWS CLI ... 
AWS Access Key ID [None]: 
XXXXXXXXXXXXXXXXXXXX
AWS Secret Access Key [None]:
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Default region name [us-east-1]: 
Default output format [None]: 

Step 4 of 5: Configuring the CloudWatch Logs Agent ... 
Path of log file to upload [/var/log/syslog]:
/var/log/apache2/error.log
Destination Log Group name [/var/log/apache2/error.lol]: 

Choose Log Stream name:
  1. Use EC2 instance id.
  2. Use hostname.
  3. Custom.
Enter choice [1]: 1

Choose Log Event timestamp format:
  1. %b %d %H:%M:%S    (Dec 31 23:59:59)
  2. %d/%b/%Y:%H:%M:%S (10/Oct/2000:13:55:36)
  3. %Y-%m-%d %H:%M:%S (2008-09-08 11:52:54)
  4. Custom
Enter choice [1]: 3

Choose initial position of upload:
  1. From start of file.
  2. From end of file.
Enter choice [1]: 1
More log files to configure? [Y]: N

Step 5 of 5: Setting up agent as a daemon ...DONE
------------------------------------------------------
- Configuration file successfully saved at: /var/awslogs/etc/awslogs.conf
- You can begin accessing new log events after a few moments at https://console.aws.amazon.com/cloudwatch/home?region=us-east-1#logs:
- You can use 'sudo service awslogs start|stop|status|restart' to control the daemon.
- To see diagnostic information for the CloudWatch Logs Agent, see /var/log/awslogs.log
- You can rerun interactive setup using 'sudo python ./awslogs-agent-setup.py --region us-east-1 --only-generate-config'
------------------------------------------------------

You can vie the log by following the link provided
https://console.aws.amazon.com/cloudwatch/home?region=us-east-1#logs:

View Log in CloudWatch

CloudWatch>Log groups>/var/log/apache2/error.log>i-00000000000000000
  • https://httpd.apache.org/
,