Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add elbs instance state to status #75

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/moonshot/creds_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,9 @@ def as_client
def s3_client
Aws::S3::Client.new
end

def elb_client
Aws::ElasticLoadBalancing::Client.new
end
end
end
20 changes: 18 additions & 2 deletions lib/moonshot/stack_asg_printer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,10 @@ def create_instance_table(asg_info)
current_lc = asg_info.launch_configuration_name
ec2_info = get_addl_info(asg_info.instances.map(&:instance_id))
asg_info.instances.map do |asg_instance|
elb_instance_state = elb_instance_health(asg_info, asg_instance.instance_id)
row = instance_row(asg_instance,
ec2_info[asg_instance.instance_id])
ec2_info[asg_instance.instance_id],
elb_instance_state)
row << if current_lc == asg_instance.launch_configuration_name
'(launch config up to date)'.green
else
Expand All @@ -110,17 +112,31 @@ def create_instance_table(asg_info)
end
end

def instance_row(asg_instance, ec2_instance)
def instance_row(asg_instance, ec2_instance, instance_elb_state)
[
asg_instance.instance_id,
# @todo What about ASGs with only private IPs?
ec2_instance.public_ip_address,
'(ASG):',
lifecycle_color(asg_instance.lifecycle_state),
'(ELB):',
lifecycle_color(instance_elb_state),
health_color(asg_instance.health_status),
uptime_format(ec2_instance.launch_time)
]
end

def elb_instance_health(asg_info, instance_id)
asg_info.load_balancer_names.map do |load_balancer_name|
elb_client.describe_instance_health(
load_balancer_name: load_balancer_name,
instances: [{
instance_id: instance_id
}]
).instance_states.first.state
end.compact.first
end

def uptime_format(launch_time)
# %td is "total days", instead of counting up again to weeks.
Duration.new(Time.now.to_i - launch_time.to_i)
Expand Down