-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Porting of V5 YT-CC-1328 engineyard/ey-cookbooks-stable-v5#384
- Loading branch information
Dimitris Dalianis
committed
May 18, 2019
1 parent
dec5aeb
commit 42a6bd3
Showing
7 changed files
with
453 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'] |
Oops, something went wrong.