首页 > 代码库 > OpenStack-Heat中的Autoscaling - AWS的autoscaling
OpenStack-Heat中的Autoscaling - AWS的autoscaling
在Heat中完全使用aws的语法创建一套autoscaling的template。
流程:
Create LaunchConfig (Create basic instance, send mem status to ALARM) ->
Create ASGroup (Define instance num range) ->
Create ScaleUpPolicy (+1 instance when mem_alarm_high) ->
Create MEMAlarmHigh (Monitor mem status) ->
Create ScaleDownPolicy (-1 instance when mem_alarm_low) ->
Create MEMAlarmLow (monitor mem status)
Template模板:
"ASGroup" : {
"Type" : "AWS::AutoScaling::AutoScalingGroup",
"Properties" : {
"AvailabilityZones" : ["nova"],
"LaunchConfigurationName" : { "Ref" : "LaunchConfig" },
"MinSize" : "1",
"MaxSize" : "10"
}
},
"ScaleUpPolicy" : {
"Type" : "AWS::AutoScaling::ScalingPolicy",
"Properties" : {
"AdjustmentType" : "ChangeInCapacity",
"AutoScalingGroupName" : { "Ref" : "ASGroup" },
"Cooldown" : "60",
"ScalingAdjustment" : "1"
}
},
"MEMAlarmHigh": {
"Type": "AWS::CloudWatch::Alarm",
"Properties": {
"AlarmDescription": "Scale-up if MEM > 70% for 1 minute",
"MetricName": "MemoryUtilization",
"Namespace": "system/linux",
"Statistic": "Average",
"Period": "60",
"EvaluationPeriods": "1",
"Threshold": "70",
"AlarmActions": [ { "Ref": "ScaleUpPolicy" } ],
"Dimensions": [
{
"Name": "AutoScalingGroupName",
"Value": { "Ref": "ASGroup" }
}
],
"ComparisonOperator": "GreaterThanThreshold"
}
},
"ScaleDownPolicy" : {
"Type" : "AWS::AutoScaling::ScalingPolicy",
"Properties" : {
"AdjustmentType" : "ChangeInCapacity",
"AutoScalingGroupName" : { "Ref" : "ASGroup" },
"Cooldown" : "60",
"ScalingAdjustment" : "-1"
}
},
"MEMAlarmLow": {
"Type": "AWS::CloudWatch::Alarm",
"Properties": {
"AlarmDescription": "Scale-down if MEM < 30% for 1 minute",
"MetricName": "MemoryUtilization",
"Namespace": "system/linux",
"Statistic": "Average",
"Period": "60",
"EvaluationPeriods": "1",
"Threshold": "30",
"AlarmActions": [ { "Ref": "ScaleDownPolicy" } ],
"Dimensions": [
{
"Name": "AutoScalingGroupName",
"Value": { "Ref": "ASGroup" }
}
],
"ComparisonOperator": "LessThanThreshold"
}
},
"LaunchConfig" : {
"Type" : "AWS::AutoScaling::LaunchConfiguration",
"Metadata" : {
"AWS::CloudFormation::Init" : {
"config" : {
"files" : {
"/etc/cfn/cfn-credentials" : {
"content" : { "Fn::Join" : ["", [
"AWSAccessKeyId=", { "Ref" : "LSFKeys" }, "\n",
"AWSSecretKey=", {"Fn::GetAtt": ["LSFKeys",
"SecretAccessKey"]}, "\n"
]]},
"mode" : "000400",
"owner" : "root",
"group" : "root"
},
"/tmp/stats-crontab.txt" : {
"content" : { "Fn::Join" : ["", [
"MAIL=\"\"\n",
"\n",
"* * * * * /opt/aws/bin/cfn-push-stats --watch ",
{ "Ref" : "MEMAlarmHigh" }, " --mem-util\n",
"* * * * * /opt/aws/bin/cfn-push-stats --watch ",
{ "Ref" : "MEMAlarmLow" }, " --mem-util\n"
]]},
"mode" : "000600",
"owner" : "root",
"group" : "root"
}
}
}
}
},
"Properties": {
"ImageId": "rhel6u4",
"InstanceType": "m1.small",
"KeyName": "poc",
"UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [
"#!/bin/bash -v\n",
"/opt/aws/bin/cfn-init -s ", { "Ref" : "AWS::StackName" },
" -r VMWARELaunchConfig ",
" --region ", { "Ref" : "AWS::Region" }, "\n",
"crontab /tmp/stats-crontab.txt\n",
]]}}
}
}
},
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。