项目作者: williamchanrico

项目描述 :
A small side-project to automate autoscale configurations in Alibaba Cloud
高级语言: Python
项目地址: git://github.com/williamchanrico/alicloud-autoscale.git
创建时间: 2018-08-27T01:02:05Z
项目社区:https://github.com/williamchanrico/alicloud-autoscale

开源协议:GNU General Public License v3.0

下载


Alicloud Autoscale

A small side-project to automate autoscale configurations in Alibaba Cloud.

How It Works

  • Scan all existing Scaling Rules, Scaling Groups, and Event-trigger Tasks.
  • Compare all Scaling Rules with selected config files (default is ./config/normal/*.yaml)
  • Will only change the rules if they differ, or create new ones if they don’t exist in aliyun (corresponding scaling groups must exist though)
  • Check if MinInstance and MaxInstance is specified in each rules, for rules that have those values, make sure their scaling group in aliyun has the same min/max instance size
  • Compare all Event-trigger Tasks with selected config files, skip if there are no difference
  • Will make sure that every scaling rule has their Event-trigger Tasks with correct configurations
  • Will ask if user wants to delete invalid Event-trigger Tasks

Few things to note:

  • The script assumes that all rules follow this naming convention, app-name-upscale and app-name-downscale
  • Unlisted rule in the selected yaml file will use the default-autoscale/default-downscale values instead

Usage

Default config dir is ./config/normal, so adding your-app-name.yaml there is fine.

Follow the example in ./config/normal/default.yaml

  1. $ python2 autoscale-rules-mode.py --help
  2. usage: autoscale-rules-mode.py [-h] [-m MODE] [-l LIMIT] [-s] [-v] [-n]
  3. [--version] access_key_id access_key_secret region_id
  4. positional arguments:
  5. access_key_id Accesskey ID for aliyun account
  6. access_key_secret AccessKey secret for aliyun account
  7. region_id ID of the region where the service is called
  8. optional arguments:
  9. -h, --help Show this help message and exit
  10. -m MODE, --mode MODE Autoscale event-trigger task mode config
  11. -l LIMIT, --limit LIMIT Limit target rules
  12. -o LOG_FILE, --log-file LOG_FILE Absolute path for log file, default:
  13. 'log/autoscale_rules_mode.log'
  14. -s, --skip-sync Skip synching cached_rules.yaml for faster runtime if
  15. you're sure that no rules has been changed in aliyun
  16. -v, --verbose Verbosity (-v, -vv, etc)
  17. -n, --noconfirm Skip interactive prompts (yes to all)
  18. --version Show program's version number and exit

Dependencies

Using python 2.7.15

$ pip2 install -r requirements.txt

  • aliyun-python-sdk-core==2.8.7
  • aliyun-python-sdk-ess==2.2.5
  • pycryptodome==3.6.6
  • PyYAML==3.13

Example

  1. $ python2 autoscale-rules-mode.py --mode normal your_access_key your_secret_key region
  2. Initializing API client object using the configured access key
  3. Loading selected mode config from config/normal/*.yaml
  4. Loading scaling groups information from aliyun
  5. Loading current rules from aliyun (cached_rules.yaml is ignored)
  6. Loading event-trigger tasks information from aliyun
  7. There are total of 136 scaling rules detected
  8. Modifying scaling rules:
  9. SKIPPED 'go-cartapp-upscale': No difference between the current and the new rule
  10. SKIPPED 'node-frontend-discovery-home-downscale': No difference between the current and the new rule
  11. ...
  12. These rules are not found in aliyun:
  13. go-test-unadded-upscale: Should belong to ScalingGroup=go-test-unadded
  14. WARNING 'go-test-unadded': Scaling group doesn't exists
  15. go-testapp-downsdfadkf: Please check the naming convention (appname-upscale/appname-downscale)
  16. Processing found event triggered task in aliyun:
  17. SKIPPED 'go-cartapp-upscale': No difference between the current and the new event trigger task rule
  18. SKIPPED 'go-wallet-upscale': No difference between the current and the new event trigger task rule
  19. ...
  20. List of event-trigger tasks in aliyun that are useless (no scaling rule attached to it) or not following our naming convention:
  21. INVALID 'go-testapp-upscale': Event trigger task in aliyun, you can choose to delete it at the end of this script
  22. You can delete those event-trigger tasks that are useless (no scaling rule attached to it) or not following our naming convention here:
  23. INVALID 'go-testapp-upscale': Delete it? [Y/n]
  24. CHANGED 'go-testapp-upscale': Deleted event trigger task
  25. Caching all changed rules into cached_rules.yaml

Debugging Log Example

  1. [06/09/2018 08:40:18 AM] Modified Scaling Group Size go-testapp:
  2. OLD => MinInstance: 0, MaxInstance: 1
  3. NEW => MinInstance: 0, MaxInstance: 3
  4. [03/09/2018 04:17:57 PM] Created Event-trigger Task go-goldmerchant-upscale: {'Threshold': 60.0, 'TriggerAfter': 3, 'ComparisonOperator': '>=', 'Cooldown': 60, 'AdjustmentType': 'PercentChangeInCapacity', 'MetricItem': 'CpuUtilization', 'RefreshCycleSeconds': 60, 'Condition': 'Average', 'AdjustmentValue': 65}
  5. [03/09/2018 04:17:58 PM] Disabled Event-trigger Task: asg-t4nawf0lvwrygfltfnca_8d480f9e-97ce-4b26-94f0-549e03a65c9a
  6. [03/09/2018 04:17:59 PM] Deleted Event-trigger task: {'MetricItem': 'CpuUtilization', 'Statistics': 'Average', 'Name': 'go-goldmerchant-upscale', 'alarmActions': {'alarmAction': ['ari:acs:ess:ap-southeast-1:1208559439424161:scalingrule/asr-t4n3691dmt1t3xi5007b']}, 'TriggerAfter': 3, 'EvaluationCount': 3, 'Period': 60, 'MetricType': 'system', 'ComparisonOperator': '>=', 'State': 'OK', 'Enable': False, 'AlarmTaskId': 'asg-t4nawf0lvwrygfltfnca_38de7bd0-bac5-492b-91c0-fc1686252028', 'ScalingGroupId': 'asg-t4nawf0lvwrygfltfnca', 'valid_name': True, 'Threshold': 65.0, 'RefreshCycleSeconds': 60, 'MetricName': 'CpuUtilization', 'Condition': 'Average', 'Dimensions': {'Dimension': [{'DimensionValue': 'asg-t4nawf0lvwrygfltfnca', 'DimensionKey': 'scaling_group'}, {'DimensionValue': '1208559439424161', 'DimensionKey': 'userId'}]}}

Version

  1. $ python2 autoscale-rules-mode.py --version
  2. autoscale-rules-mode.py (version 0.2.4)