Lab_4_SysOps_Monitoring_Linux_v2.5

时间:2023-12-10 17:43:32
System Operations - Lab 4: Monitoring with CloudWatch (Linux) - 2.5
================================================================================================================== Using this command reference. ================================================================================================================== 1. Locate the section you need. Each section in this file matches a section in the lab instructions. 2. Replace items in angle brackets - < > - with appropriate values. For example, in this command you would replace the value - <JobFlowID> - (including the brackets) with the parameter indicated in the lab instructions: elastic-mapreduce --list <JobFlowID>. You can also use find and replace to change bracketed parameters in bulk. 3. Do NOT enable the Word Wrap feature in Windows Notepad or the text editor you use to view this file. ++++1. Create Your Web Server++++ ==================================================================================================================
1.1 Create IAM Policy
================================================================================================================== 1.1.5 Use the following custom policy {
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"autoscaling:Describe*",
"cloudwatch:*",
"logs:*",
"sns:*"
],
"Effect": "Allow",
"Resource": "*"
}
]
} ==================================================================================================================
1.4 Create Web Server
================================================================================================================== 1.4.1 Review the user data script #!/bin/bash
yum -y update
yum -y install httpd php
chkconfig httpd on
/etc/init.d/httpd start mkdir /var/awslogs
mkdir /var/awslogs/state yum -y install awslogs cat > /etc/awslogs/awslogs.conf <<EOF
[general]
state_file = /var/awslogs/state/agent-state [HttpAccessLog]
file = /var/log/httpd/access_log
log_group_name = HttpAccessLog
log_stream_name = {instance_id}
datetime_format = %b %d %H:%M:%S [HttpErrorLog]
file = /var/log/httpd/error_log
log_group_name = HttpErrorLog
log_stream_name = {instance_id}
datetime_format = %b %d %H:%M:%S
EOF REGION=$(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone | sed -n 's/.$//p')
sed -i "s/us-east-1/$REGION/g" /etc/awslogs/awscli.conf service awslogs start
chkconfig awslogs on ++++2. Define CloudWatch Log Metrics++++ ==================================================================================================================
2.2 Create a CloudWatch Logs-Derived Metric
================================================================================================================== 2.2.4 Paste the following filter pattern into the Filter Pattern text box [ip, id, user, timestamp, request, status_code=404, size] ++++3. Generate a Custom Metric from an Instance++++ ==================================================================================================================
3.3 Generate HTTPd Memory Usage Metric
================================================================================================================== 3.3.1 Obtain current memory utilization of all HTTPd instances mem=$(ps -C httpd -O rss | gawk '{ count ++; sum += $2 }; END {count --; print sum/1024 ;};') 3.3.2 Verify $mem echo $mem 3.3.3 Retrieve the instance ID of the current instance instance_id=$(curl -s -w '\n' http://169.254.169.254/latest/meta-data/instance-id) 3.3.4 Verify $instance_id echo $instance_id 3.3.5 Define your custom metric aws cloudwatch put-metric-data --namespace HttpServerMetrics --metric-name HttpServerMemUtilization --dimension InstanceId=$instance_id --value $mem --unit "Megabytes" 漏 2016 Amazon Web Services, Inc. or its affiliates. All rights reserved.