Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to enable detailed CloudWatch monitoring for current instance #65

Merged
merged 1 commit into from
Oct 22, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,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 @@ -412,6 +424,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