-
Notifications
You must be signed in to change notification settings - Fork 0
/
Lab_4_SysOps_Monitoring_Linux_v2.5.txt
125 lines (80 loc) · 3.94 KB
/
Lab_4_SysOps_Monitoring_Linux_v2.5.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
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.