forked from NeCTAR-RC/heat-templates
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathceilometer_demo.yaml
240 lines (202 loc) · 7.9 KB
/
ceilometer_demo.yaml
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
# see the heat template heat-templates/hot/asg_of_servers.yaml for an idea on how to present some of the outputs?
heat_template_version: 2014-10-16
# This is a template that aims to demonstrate the connection between Heat and Ceilometer.
description: |
Creates a Ceilometer alarmed stress tester application: and another application that is notified when the alarms fire.
parameters:
key_name:
type: string
description: Name of an existing KeyPair to enable SSH access to the instances
instance_type:
type: string
description: The NeCTAR flavour the webserver is to run on
default: m2.xsmall
constraints:
- allowed_values: [m2.xsmall, m2.small, m1.small]
description:
Must be a valid NeCTAR flavour, limited to the smaller ones available
image_name:
type: string
description: Name of the image to use for the instance to be created.
default: 'Ubuntu 14.04'
constraints:
- allowed_values: [ 'Ubuntu 14.04', 'Ubuntu 15.04' ]
description:
Must be a valid NeCTAR image name, limited to the LTS Ubuntu releases
resources:
cpu_alarm_high:
type: OS::Ceilometer::Alarm
properties:
description: Scale-up if the average CPU > 30% for 10 minute
meter_name: cpu_util
statistic: avg
period: 600
evaluation_periods: 1
threshold: 30
ok_actions:
- str_replace:
template: https://IpAddress/8080/alarm/all_ok
params:
IpAddress: { get_attr: [alarm_monitor, PublicIp] }
insufficient_data_actions:
- str_replace:
template: https://IpAddress/8080/alarm/insufficient_data
params:
IpAddress: { get_attr: [alarm_monitor, PublicIp] }
alarm_actions:
- str_replace:
template: https://IpAddress/8080/alarm/scale_up_now
params:
IpAddress: { get_attr: [alarm_monitor, PublicIp] }
matching_metadata: { metadata.user_metadata.groupname : { get_resource: stress_server_group } }
comparison_operator: gt
cpu_alarm_low:
type: OS::Ceilometer::Alarm
properties:
description: Scale-down if the average CPU < 15% for 1 minute
meter_name: cpu_util
statistic: avg
period: 60
evaluation_periods: 1
threshold: 15
alarm_actions:
- str_replace:
template: https://IpAddress/8080/alarm/scale_down
params:
IpAddress: { get_attr: [alarm_monitor, PublicIp]}
matching_metadata: { metadata.user_metadata.groupname: { get_resource: stress_server_group } }
comparison_operator: lt
# the following will break if you have maxed out your security group limit (10).
web_server_security_group:
type: AWS::EC2::SecurityGroup
properties:
GroupDescription: Enable HTTP access via port 8080 plus SSH access
SecurityGroupIngress:
-
IpProtocol: "icmp"
FromPort: "-1"
ToPort: "-1"
CidrIp: "0.0.0.0/0"
-
IpProtocol: "tcp"
FromPort: "22"
ToPort: "22"
CidrIp: "0.0.0.0/0"
-
IpProtocol: "tcp"
FromPort: "8080"
ToPort: "8080"
CidrIp: "0.0.0.0/0"
stress_server_group:
type: AWS::AutoScaling::AutoScalingGroup
properties:
AvailabilityZones: [ melbourne, monash, QRIScloud, NCI, intersect, sa, tasmania ]
LaunchConfigurationName: { get_resource: launch_configuration }
MinSize: 1
MaxSize: 1
Tags:
- {Key: metering.server_group, Value: stress_server_group}
launch_configuration:
type: AWS::AutoScaling::LaunchConfiguration
properties:
ImageId:
Fn::Select:
- { get_param: image_name }
-
'Ubuntu 14.04': 2a882d9c-3185-414c-9683-a4646b5c785e
'Ubuntu 15.04': fc48b5bb-e67d-4e39-b9ba-b6725c8b0c88
InstanceType: { get_param: instance_type }
KeyName: { get_param: key_name }
SecurityGroups: [ { get_resource: web_server_security_group } ]
UserData:
str_replace:
params:
wc_notify: { get_attr: ['wait_handle', 'curl_cli'] }
template: |
#!/bin/bash -v
apt-get update && sudo apt-get -y upgrade
apt-get -y install git
# time to sit back and smoke that cigar...
apt-get -y install maven
# then java 8
apt-get -y install python-software-properties
add-apt-repository ppa:webupd8team/java -y
apt-get -q -y update
# from http://askubuntu.com/questions/190582/installing-java-automatically-with-silent-option
echo debconf shared/accepted-oracle-license-v1-1 select true | debconf-set-selections
echo debconf shared/accepted-oracle-license-v1-1 seen true | debconf-set-selections
apt-get install oracle-java8-installer -y
# set it as the default..
apt-get install oracle-java8-set-default
#install stress
apt-get -y install stress
git clone https://github.com/MartinPaulo/SparkStressTester.git
cd SparkStressTester
./start.sh &
wc_notify --data-binary '{"status": "SUCCESS"}'
alarm_monitor:
type: AWS::EC2::Instance
properties:
# an ubuntu image with heat-cfntools installed
ImageId:
Fn::Select:
- { get_param: image_name }
-
'Ubuntu 14.04': 2a882d9c-3185-414c-9683-a4646b5c785e
'Ubuntu 15.04': fc48b5bb-e67d-4e39-b9ba-b6725c8b0c88
InstanceType: { get_param: instance_type }
KeyName: { get_param: key_name }
SecurityGroups: [ { get_resource: web_server_security_group } ]
# the following is written to /var/lib/cloud/data/cfn-userdata
# note the call to cfn-init which causes the AWS::CloudFomration::Init to be actioned
UserData:
str_replace:
params:
wc_notify: { get_attr: ['wait_handle', 'curl_cli'] }
template: |
#!/bin/bash -v
apt-get update && sudo apt-get -y upgrade
apt-get -y install git
# time to sit back and smoke that cigar...
apt-get -y install maven
# then java 8
apt-get -y install python-software-properties
add-apt-repository ppa:webupd8team/java -y
apt-get -q -y update
# from http://askubuntu.com/questions/190582/installing-java-automatically-with-silent-option
echo debconf shared/accepted-oracle-license-v1-1 select true | debconf-set-selections
echo debconf shared/accepted-oracle-license-v1-1 seen true | debconf-set-selections
apt-get install oracle-java8-installer -y
# set it as the default..
apt-get install oracle-java8-set-default
git clone https://github.com/MartinPaulo/SparkProject.git
cd SparkProject
./start.sh &
wc_notify --data-binary '{"status": "SUCCESS"}'
wait_handle:
# http://docs.openstack.org/developer/heat/template_guide/openstack.html#OS::Heat::WaitConditionHandle
type: OS::Heat::WaitConditionHandle
wait_condition:
# http://docs.openstack.org/developer/heat/template_guide/openstack.html#OS::Heat::WaitCondition
type: OS::Heat::WaitCondition
depends_on: [ alarm_monitor, launch_configuration ]
properties:
handle: { get_resource: wait_handle }
count: 2
# we'll give it 10 minutes
timeout: 600
outputs:
monitor_url:
description: The URL of the montitoring website
value:
str_replace:
template: http://IpAddress:8080
params:
IpAddress: { get_attr: [alarm_monitor, PublicIp] }
website_url:
description: URL for the stressed server
value:
str_replace:
template: http://IpAddress:8080
params:
IpAddress: { get_attr: [stress_server_group, InstanceList] }