Created
September 15, 2011 13:25
-
-
Save balepc/1219214 to your computer and use it in GitHub Desktop.
Scout plugin for checking HTTP statuses on AWS EC2
This file contains hidden or 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
# EC2 Http servers health status | |
# * Number of running instances | |
# * Average response time | |
class Ec2HttpHealth < Scout::Plugin | |
needs 'right_aws' | |
needs 'timeout' | |
OPTIONS=<<-EOS | |
access_key_id: | |
name: AWS Access Key ID | |
secret_access_key: | |
name: AWS Secret Access Key | |
name_pattern: | |
name: Name pattern on your EC2 instances | |
default: app slave | |
http_port: | |
name: HTTP port to ping | |
default: 81 | |
request_uri: | |
name: URI to request | |
default: /health/pulse | |
EOS | |
def check_status(host, port, uri) | |
timer = Time.now | |
http = Net::HTTP.new(host, port) | |
request = Net::HTTP::Get.new(uri) | |
response = http.request(request) | |
response.is_a?(Net::HTTPOK) | |
return response.is_a?(Net::HTTPOK), Time.now - timer | |
end | |
def build_report | |
pattern = option(:name_pattern) | |
port = option(:http_port) | |
uri = option(:request_uri) | |
connection = RightAws::Ec2.new(option(:access_key_id), option(:secret_access_key), :logger=>nil) | |
instances_count = 0 | |
timer = 0 | |
connection.describe_instances.each do |instance| | |
name = instance[:tags]["Name"] | |
public_dns = instance[:dns_name] | |
if name.downcase.include?(pattern) | |
status_ok, time = check_status(public_dns, port, uri) | |
unless status_ok | |
alert("Instance #{public_dns} is not working properly!") | |
else | |
instances_count += 1 | |
timer += time | |
end | |
end | |
end | |
report :instances_count => instances_count, :average_response_time => timer / instances_count | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment