Created
March 16, 2011 18:51
-
-
Save jesseproudman/873067 to your computer and use it in GitHub Desktop.
Logic for simple Auto Scale setup
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
require 'rubygems'; require 'active_resource'; require 'new_relic_api' | |
servers = File.open("server_count.txt", "r").first.to_i | |
instances_per_server = 6 | |
cpu_burn_for_system = 1000.0 * 0.20 | |
NewRelicApi.api_key = "<Your API Key>" | |
account = NewRelicApi::Account.find(:first); | |
application = account.applications[3]; | |
metrics = application.threshold_values; | |
response_time = metrics.select{|m| m.name == "Response Time" }.first.metric_value | |
throughput = metrics.select{|m| m.name == "Throughput" }.first.metric_value | |
rps = throughput / 60 | |
instances = servers * instances_per_server | |
rps_per_instance = rps / instances | |
cpu_burn_per_second = rps_per_instance * response_time | |
if cpu_burn_per_second > 1.0 - cpu_burn_for_system | |
puts "Need More Power." | |
puts "Start up a block with Fog!" | |
servers += 1 | |
else | |
puts "At or Over Capacity" | |
puts "Shut down the block." | |
servers -= 1 | |
end | |
# Save servers to a persistent store | |
File.open("server_count.txt", 'w') { |f| f.write( servers ) } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment