class AwsPocketknife::Cli::Ecs
Public Instance Methods
clone_service(cluster, service_name)
click to toggle source
# File lib/aws_pocketknife/cli/ecs.rb, line 77 def clone_service(cluster, service_name) resp = AwsPocketknife::Ecs.clone_service cluster: cluster, name: service_name puts "" puts "Response: " puts "" AwsPocketknife::Ecs.nice_print(object: resp.to_h) end
desc_service(cluster, service_name)
click to toggle source
# File lib/aws_pocketknife/cli/ecs.rb, line 67 def desc_service(cluster, service_name) service = AwsPocketknife::Ecs.describe_services cluster: cluster, name: service_name if service.nil? puts "service #{service_name} not found" else AwsPocketknife::Ecs.nice_print(object: service.to_h) end end
drain_instances(cluster, names)
click to toggle source
# File lib/aws_pocketknife/cli/ecs.rb, line 87 def drain_instances(cluster, names) resp = AwsPocketknife::Ecs.drain_instances cluster: cluster, names: names puts "" puts "Response: " puts "" AwsPocketknife::Ecs.nice_print(object: resp.to_a) end
list_clusters()
click to toggle source
# File lib/aws_pocketknife/cli/ecs.rb, line 10 def list_clusters() clusters = AwsPocketknife::Ecs.list_clusters headers = ["name", "status", "services", "containers_count","running_tasks_count", "pending_tasks_count",] data = [] if clusters.nil? puts "No clusters found. Check your region" else #AwsPocketknife::Ecs.nice_print(object: clusters) clusters.each do |cluster| info = cluster[:info] data << [cluster[:name], info.status, info.active_services_count, info.registered_container_instances_count, info.running_tasks_count, info.pending_tasks_count ] end AwsPocketknife::Ecs.pretty_table(headers: headers, data: data) end end
list_instance_tasks(cluster, name)
click to toggle source
# File lib/aws_pocketknife/cli/ecs.rb, line 97 def list_instance_tasks(cluster, name) resp = AwsPocketknife::Ecs.list_container_tasks cluster: cluster, container_name: name headers = ["name", "started_at", "stopped_at", "last_status", "task"] data = [] if resp.nil? puts "No tasks found" else resp.tasks.each do |task| data << [task.task_definition_arn.split('/')[1], task.started_at, task.stopped_at, task.last_status, task.task_arn.split('/')[1]] end AwsPocketknife::Ecs.pretty_table(headers: headers, data: data) end end
list_instances(cluster)
click to toggle source
# File lib/aws_pocketknife/cli/ecs.rb, line 112 def list_instances(cluster) instances = AwsPocketknife::Ecs.list_container_instances cluster: cluster headers = ["name", "ec2_instance_id", "agent_connected", "pending_tasks_count","running_tasks_count", "status", "cpu (units)", "mem (MiB)" ] headers_2 = ["active", "draining", "tasks pending", "tasks running", "cpu_reserved / cpu_total", "mem_reserved / mem_total" ] data = [] data_2 = [] if instances.nil? puts "No instances found" else count_active = 0 count_draining = 0 mem_cluster_total = 0.0 mem_cluster_res_total = 0.0 mem_percentage = 0.0 cpu_cluster_total = 0.0 cpu_cluster_res_total = 0.0 cpu_percentage = 0.0 pending_tasks_count_total = 0 running_tasks_count_total = 0 instances.each do |instance| info = instance[:info] cpu_total = info.registered_resources[0].integer_value mem_total = info.registered_resources[1].integer_value cpu_available = info.remaining_resources[0].integer_value mem_available = info.remaining_resources[1].integer_value connected = info.agent_connected data << [instance[:name], info.ec2_instance_id, connected, info.pending_tasks_count, info.running_tasks_count, info.status, "#{cpu_available} / #{cpu_total}", "#{mem_available} / #{mem_total}" ] pending_tasks_count_total = pending_tasks_count_total + info.pending_tasks_count running_tasks_count_total = running_tasks_count_total + info.running_tasks_count mem_cluster_total = mem_cluster_total + mem_total if info.status == "ACTIVE" mem_cluster_res_total = mem_cluster_res_total + mem_available if info.status == "ACTIVE" mem_percentage = (((mem_cluster_total - mem_cluster_res_total)/mem_cluster_total) * 100).round(2) cpu_cluster_total = cpu_cluster_total + cpu_total if info.status == "ACTIVE" cpu_cluster_res_total = cpu_cluster_res_total + cpu_available if info.status == "ACTIVE" cpu_percentage = (((cpu_cluster_total - cpu_cluster_res_total)/cpu_cluster_total) * 100).round(2) count_active = count_active + 1 if info.status == "ACTIVE" count_draining = count_draining + 1 if info.status == "DRAINING" end data_2 << [count_active, count_draining, pending_tasks_count_total, running_tasks_count_total, "#{(cpu_cluster_total - cpu_cluster_res_total).round(0)} / #{cpu_cluster_total.round(0)} (#{cpu_percentage} %)", "#{(mem_cluster_total - mem_cluster_res_total).round(0)} / #{mem_cluster_total.round(0)} (#{mem_percentage} %)" ] AwsPocketknife::Ecs.pretty_table(headers: headers, data: data) puts "" puts "" AwsPocketknife::Ecs.pretty_table(headers: headers_2, data: data_2) end end
list_services(cluster)
click to toggle source
# File lib/aws_pocketknife/cli/ecs.rb, line 30 def list_services(cluster) services = AwsPocketknife::Ecs.list_services cluster: cluster headers = ["name", "status", "desired_count","running_count", "pending_count", "task_definition", "maximum_percent", "minimum_healthy_percent", "cpu (units)", "mem (MiB)", "mem_reservation (MiB)"] data = [] if services.nil? puts "No service found" else mem_total = 0 mem_res_total = 0 cpu_total = 0 services.each do |service| info = service[:info] task_def = service[:task_definition] data << [service[:name], info.status, info.desired_count, info.running_count, info.pending_count, info.task_definition.split('/')[1], info.deployment_configuration.maximum_percent, info.deployment_configuration.minimum_healthy_percent, task_def.cpu, task_def.memory, task_def.memory_reservation ] cpu_total = cpu_total + task_def.cpu unless task_def.cpu.nil? mem_total = mem_total + task_def.memory unless task_def.memory.nil? mem_res_total = (mem_res_total + task_def.memory_reservation) unless task_def.memory_reservation.nil? end puts "" puts "Memory is the hard limit (in MiB) of memory to present to the container. If your container attempts to exceed the memory specified here, the container is killed." puts "Memory reservation is the soft limit (in MiB) of memory to reserve for the container. When system memory is under contention, Docker attempts to keep the container memory to this soft limit" puts "" AwsPocketknife::Ecs.pretty_table(headers: headers, data: data) puts "" puts "CPU TOTAL: #{cpu_total} Units" puts "MEM TOTAL: #{mem_total} MiB" puts "MEM RES TOTAL: #{mem_res_total} MiB" puts "" end end