Skip to content

Commit

Permalink
Porting of V5 YT-CC-1328 engineyard/ey-cookbooks-stable-v5#384
Browse files Browse the repository at this point in the history
  • Loading branch information
Dimitris Dalianis committed May 18, 2019
1 parent dec5aeb commit 42a6bd3
Show file tree
Hide file tree
Showing 7 changed files with 453 additions and 1 deletion.
3 changes: 3 additions & 0 deletions cookbooks/collectd/attributes/defaults.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
default['swap_crit_threshold'] = "0.70"

default['collectd']['version'] = "5.7.2-2ubuntu1"

# Enable monitoring of EC2/EBS credit balances only on T instances (T2, T3)
default['collectd']['enable_credit_balances_monitoring'] = (size =~ /^t[a-z0-9]+\./)
3 changes: 3 additions & 0 deletions cookbooks/collectd/files/default/ec2credits.types.db
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
cpu_credits balance:GAUGE:0:U, usage:GAUGE:0:U
cpu_surplus_credits balance:GAUGE:0:U, charged:GAUGE:0:U
ebs_iops_burst balance:GAUGE:0:100.1
36 changes: 36 additions & 0 deletions cookbooks/collectd/libraries/ec2_credit_thresholds.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
class EC2CreditThresholds

def initialize(apps_data)
all_env_vars = merged_app_env_vars(apps_data)
set_ec2_credit_thresholds(all_env_vars)
end

attr_reader :cpu_credit_ok, :cpu_credit_warn, :cpu_credit_alert,
:vol_burst_ok, :vol_burst_warn, :vol_burst_alert

private

def merged_app_env_vars(apps_data)
apps_data
.map do |app_data|
metadata = app_data['components'].find {|component| component['key'] == 'app_metadata'}
return {} unless metadata && metadata['environment_variables']
Hash[
metadata['environment_variables'].collect do |var_hash|
[ var_hash['name'], ::Base64.strict_decode64(var_hash['value']) ]
end
]
end
.reduce({}, :merge)
end

def set_ec2_credit_thresholds(all_env_vars)
@cpu_credit_ok = all_env_vars.fetch('EY_EC2_CPU_CREDITS_THRESHOLD_OK', 40)
@cpu_credit_warn = all_env_vars.fetch('EY_EC2_CPU_CREDITS_THRESHOLD_WARN', 30)
@cpu_credit_alert = all_env_vars.fetch('EY_EC2_CPU_CREDITS_THRESHOLD_ALERT', 15)
@vol_burst_ok = all_env_vars.fetch('EY_IOPS_BURST_BALANCE_THRESHOLD_OK', 40)
@vol_burst_warn = all_env_vars.fetch('EY_IOPS_BURST_BALANCE_THRESHOLD_WARN', 30)
@vol_burst_alert = all_env_vars.fetch('EY_IOPS_BURST_BALANCE_THRESHOLD_ALERT', 15)
end

end
4 changes: 3 additions & 1 deletion cookbooks/collectd/recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
end

include_recipe 'collectd::httpd'
include_recipe 'collectd::ec2_credit_balances'

template "/engineyard/bin/ey-alert.rb" do
owner 'root'
Expand Down Expand Up @@ -91,7 +92,8 @@
:load_failure => node['collectd']['load']['failure'],
:swap_thresholds => SwapThresholds.new,
:short_version => short_version,
:disk_thresholds => DiskThresholds.new
:disk_thresholds => DiskThresholds.new,
:enable_credit_balances_monitoring => node['collectd']['enable_credit_balances_monitoring']
}
}
)
Expand Down
46 changes: 46 additions & 0 deletions cookbooks/collectd/recipes/ec2_credit_balances.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
if node['collectd']['enable_credit_balances_monitoring'] then

# Install dependencies
enable_package 'dev-python/boto3' do
version '1.3.0'
end
enable_package 'dev-python/botocore' do
version '1.4.19'
end
enable_package 'dev-python/jmespath' do
version '0.9.0'
end
package 'dev-python/boto3' do
action :install
end
package 'dev-python/requests' do
action :install
end

managed_template "/engineyard/bin/check_for_ec2_credit_balances.py" do
source "check_for_ec2_credit_balances.py.erb"
owner node["owner_name"]
group node["owner_name"]
mode 0755
variables({
:ec2_thresholds => EC2CreditThresholds.new(node['dna']['engineyard']['environment']['apps'])
})
end

# The script stores internal state here
directory "/tmp/check_ec2_credit_balances" do
owner node["owner_name"]
group node["owner_name"]
mode 0755
recursive true
end

cookbook_file "/etc/engineyard/ec2credits.types.db" do
source "ec2credits.types.db"
owner node["owner_name"]
group node["owner_name"]
backup 0
mode 0644
end

end # node['collectd']['enable_credit_balances_monitoring']
Loading

0 comments on commit 42a6bd3

Please sign in to comment.