Skip to content

Commit

Permalink
Merge pull request #65 from astral303/enable_monitoring
Browse files Browse the repository at this point in the history
Add ability to enable detailed CloudWatch monitoring for current instance
  • Loading branch information
cwebberOps committed Oct 22, 2014
2 parents 2ecb615 + 221d91e commit a23992a
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,18 @@ Attribute Parameters
be a single ID as a string or multiple IDs in an array. If no
`resource_id` is specified the name attribute will be used.

## instance_monitoring.rb

Actions:

* `enable` - Enable detailed CloudWatch monitoring for this instance (Default).
* `disable` - Disable detailed CloudWatch monitoring for this instance.

Attribute Parameters:

* `aws_secret_access_key`, `aws_access_key` - passed to
`Opscode::AWS:Ec2` to authenticate, required, unless using IAM roles for authentication.

Usage
=====

Expand Down Expand Up @@ -418,6 +430,12 @@ is a wrapper around `remote_file` and supports the same resource attributes as `
end


## aws_instance_monitoring

Allows detailed CloudWatch monitoring to be enabled for the current instance.

aws_instance_monitoring "enable detailed monitoring"

License and Author
==================

Expand Down
35 changes: 35 additions & 0 deletions providers/instance_monitoring.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
include Opscode::Aws::Ec2

def whyrun_supported?
true
end

action :enable do
if is_monitoring_enabled
Chef::Log.debug("Monitoring is already enabled for this instance")
else
converge_by("enable monitoring for this instance") do
Chef::Log.info("Enabling monitoring for this instance")
ec2.monitor_instances(instance_id)
end
end
end

action :disable do
if is_monitoring_enabled
converge_by("disable monitoring for this instance") do
Chef::Log.info("Disabling monitoring for this instance")
ec2.unmonitor_instances(instance_id)
end
else
Chef::Log.debug("Monitoring is already disabled for this instance")
end
end

private

def is_monitoring_enabled()
monitoring_state = ec2.describe_instances(instance_id)[0][:monitoring_state]
Chef::Log.info("Current monitoring state for this instance is #{monitoring_state}")
return monitoring_state == "enabled"
end
11 changes: 11 additions & 0 deletions resources/instance_monitoring.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
def initialize(*args)
super
@action = :enable
end

actions :enable, :disable

state_attrs :aws_access_key

attribute :aws_access_key, :kind_of => String
attribute :aws_secret_access_key, :kind_of => String

0 comments on commit a23992a

Please sign in to comment.