首页 > 代码库 > Lab_4_SysOps_Monitoring_Linux_v2.5

Lab_4_SysOps_Monitoring_Linux_v2.5

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/bashyum -y updateyum -y install httpd phpchkconfig httpd on/etc/init.d/httpd startmkdir /var/awslogsmkdir /var/awslogs/stateyum -y install awslogscat > /etc/awslogs/awslogs.conf <<EOF[general]state_file = /var/awslogs/state/agent-state[HttpAccessLog]file = /var/log/httpd/access_loglog_group_name = HttpAccessLoglog_stream_name = {instance_id}datetime_format = %b %d %H:%M:%S[HttpErrorLog]file = /var/log/httpd/error_loglog_group_name = HttpErrorLoglog_stream_name = {instance_id}datetime_format = %b %d %H:%M:%SEOFREGION=$(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.confservice awslogs startchkconfig 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 instancesmem=$(ps -C httpd -O rss | gawk ‘{ count ++; sum += $2 }; END {count --; print sum/1024 ;};‘)3.3.2 Verify $memecho $mem3.3.3 Retrieve the instance ID of the current instanceinstance_id=$(curl -s -w ‘\n‘ http://169.254.169.254/latest/meta-data/instance-id)3.3.4 Verify $instance_idecho $instance_id3.3.5 Define your custom metricaws 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.

Lab_4_SysOps_Monitoring_Linux_v2.5