From ec8255e6dd87fed91b77620741b83324fc64d8ed Mon Sep 17 00:00:00 2001 From: Gu Yingbo Date: Wed, 29 Jul 2015 15:11:14 +0800 Subject: [PATCH] Add asg(Auto Scaling Groups) and sqs support for plumbum namespace. --- plumbum.py | 20 +++++++++++++++++++- sample_templates/asg.yml.j2 | 19 +++++++++++++++++++ sample_templates/sqs.yml.j2 | 18 ++++++++++++++++++ 3 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 sample_templates/asg.yml.j2 create mode 100644 sample_templates/sqs.yml.j2 diff --git a/plumbum.py b/plumbum.py index 33e24a1..815c62b 100644 --- a/plumbum.py +++ b/plumbum.py @@ -5,7 +5,7 @@ Options: template path to the jinja2 template - namespace AWS namespace. Currently supports: elasticache, elb, ec2, rds + namespace AWS namespace. Currently supports: elasticache, elb, ec2, rds, asg, sqs region AWS region [default: us-east-1] options key value combinations, they can be tags or any other property @@ -37,6 +37,8 @@ import boto.ec2.elb import boto.rds import boto.elasticache +import boto.ec2.autoscale +import boto.sqs import jinja2 @@ -140,11 +142,27 @@ def list_elasticache(region, filter_by_kwargs): return clusters +def list_autoscaling_group(region, filter_by_kwargs): + """List all Auto Scaling Groups.""" + conn = boto.ec2.autoscale.connect_to_region(region) + groups = conn.get_all_groups() + return lookup(groups, filter_by=filter_by_kwargs) + + +def list_sqs(region, filter_by_kwargs): + """List all SQS Queues.""" + conn = boto.sqs.connect_to_region(region) + queues = conn.get_all_queues() + return lookup(queues, filter_by=filter_by_kwargs) + + list_resources = { 'ec2': list_ec2, 'elb': list_elb, 'rds': list_rds, 'elasticache': list_elasticache, + 'asg': list_autoscaling_group, + 'sqs': list_sqs, } diff --git a/sample_templates/asg.yml.j2 b/sample_templates/asg.yml.j2 new file mode 100644 index 0000000..61cfe40 --- /dev/null +++ b/sample_templates/asg.yml.j2 @@ -0,0 +1,19 @@ +# Sample config.yaml +# +Auth: + region: "{{ region }}" +Metrics: +{% for asg in resources %} +- Namespace: "AWS/EC2" + MetricName: "CPUUtilization" + Statistics: + - "Maximum" + - "Average" + Unit: "Percent" + Dimensions: + AutoScalingGroupName: {{ asg.name }} +{% endfor %} +Options: + Count: 3 + Period: 5 + Formatter: 'cloudwatch.aws.asg.{{ region }}.%(dimension)s.%(MetricName)s.%(statistic)s.%(Unit)s' diff --git a/sample_templates/sqs.yml.j2 b/sample_templates/sqs.yml.j2 new file mode 100644 index 0000000..9b97cbe --- /dev/null +++ b/sample_templates/sqs.yml.j2 @@ -0,0 +1,18 @@ +# Sample config.yaml +# +Auth: + region: "{{ region }}" +Metrics: +{%- for sqs in resources %} +- Namespace: "AWS/SQS" + MetricName: "NumberOfMessagesReceived" + Statistics: + - "Sum" + Unit: "Count" + Dimensions: + QueueName: {{ sqs.name }} +{%- endfor %} +Options: + Count: 5 + Period: 5 + Formatter: 'cloudwatch.%(Namespace)s.{{ region }}.%(dimension)s.%(MetricName)s.%(statistic)s.%(Unit)s'