class Dogscaler::Instance
Public Class Methods
new()
click to toggle source
# File lib/dogscaler/instance.rb, line 16 def initialize @checks = [] end
Public Instance Methods
asg()
click to toggle source
# File lib/dogscaler/instance.rb, line 23 def asg @asg ||= aws.get_asg(self.autoscale_group, self.asg_tag_filters) end
autoscalegroupname()
click to toggle source
# File lib/dogscaler/instance.rb, line 43 def autoscalegroupname asg.auto_scaling_group_name end
aws()
click to toggle source
# File lib/dogscaler/instance.rb, line 27 def aws @aws ||= Dogscaler::AwsClient.new end
capacity()
click to toggle source
# File lib/dogscaler/instance.rb, line 79 def capacity asg.desired_capacity end
change()
click to toggle source
# File lib/dogscaler/instance.rb, line 129 def change @change || process_change end
change=(value)
click to toggle source
# File lib/dogscaler/instance.rb, line 114 def change=(value) @change = value end
checks()
click to toggle source
# File lib/dogscaler/instance.rb, line 31 def checks @checks end
cooldown()
click to toggle source
# File lib/dogscaler/instance.rb, line 19 def cooldown self.cooldown_period || 60 end
grow()
click to toggle source
# File lib/dogscaler/instance.rb, line 106 def grow capacity + grow_by.to_i.abs end
grow?()
click to toggle source
# File lib/dogscaler/instance.rb, line 94 def grow? self.checks.any? {|c| c.status > 0 } end
max_instances()
click to toggle source
# File lib/dogscaler/instance.rb, line 35 def max_instances asg.max_size end
min_instances()
click to toggle source
# File lib/dogscaler/instance.rb, line 39 def min_instances asg.min_size end
preflight_checks(state)
click to toggle source
# File lib/dogscaler/instance.rb, line 47 def preflight_checks(state) # Quick fail filters # Don't do anything if we're already at the capactiy we think we should be if self.change == self.capacity logger.debug "Instance count: #{self.change} matches capacity: #{self.capacity}" return false end # Don't do anything if we have scaled recently if Time.now - state.get(self.autoscalegroupname) < self.cooldown logger.debug "We've scaled too soon, cooling down" return false end # Don't do anything if the new value is lower than the minimium if self.change < self.min_instances logger.debug "New size: #{self.change} smaller than min count: #{self.min_instances}" return false end # Don't do anything if the new value is higher than the maximum if self.change > self.max_instances logger.debug "New size: #{self.change} larger than max count: #{self.max_instances}" if self.capacity == self.max_instances logger.debug "Already at max, doing nothing" return false else logger.debug "Updating to the max: #{self.max_instances}" self.change = self.max_instances return true end end true end
process_change()
click to toggle source
# File lib/dogscaler/instance.rb, line 118 def process_change if self.grow? change = self.grow elsif self.shrink? change = self.shrink else change = capacity end change end
process_checks()
click to toggle source
# File lib/dogscaler/instance.rb, line 83 def process_checks dd_client = Dogscaler::Datadog.new(Settings.datadog) self.queries.each do |i| check = Dogscaler::Check.new() check.attributes = i.symbolize_keys check.points = dd_client.process(i['query']) check.reduce! @checks << check end end
shrink()
click to toggle source
# File lib/dogscaler/instance.rb, line 102 def shrink capacity + -shrink_by.to_i.abs end
shrink?()
click to toggle source
# File lib/dogscaler/instance.rb, line 98 def shrink? self.checks.any? {|c| c.status < 0 } end
update_capacity(options)
click to toggle source
# File lib/dogscaler/instance.rb, line 110 def update_capacity(options) aws.set_capacity(self, options) end