Sha256: 4e9b74c1781d36a5fba17898cc42c2c66b7bc41f6b15d0e6a223c09d4b42254a
Contents?: true
Size: 1.77 KB
Versions: 32
Compression:
Stored size: 1.77 KB
Contents
require_relative 'services_helper' module Kontena::Cli::Services class MonitorCommand < Clamp::Command include Kontena::Cli::Common include Kontena::Cli::GridOptions include ServicesHelper parameter "NAME", "Service name" option "--interval", "SECONDS", "How often view is refreshed", default: 2 def execute require_api_url token = require_token loop do nodes = {} service = client(token).get("services/#{current_grid}/#{name}") result = client(token).get("services/#{current_grid}/#{name}/containers") result['containers'].each do |container| nodes[container['node']['name']] ||= [] nodes[container['node']['name']] << container end clear_terminal puts "service: #{name} (#{result['containers'].size}/#{service['container_count']} instances)" puts "strategy: #{service['strategy']}" puts "status: #{service['state']}" puts "stateful: #{service['stateful'] == true ? 'yes' : 'no' }" puts "nodes:" node_names = nodes.keys.sort node_names.each do |name| containers = nodes[name] puts " #{name} (#{containers.size} instances)" print " " containers.each do |container| color = container['status'] if container['status'] == 'running' color = :green elsif container['status'] == 'killed' color = :red elsif container['status'] == 'stopped' color = :gray else color = :yellow end print "■".colorize(color) end puts '' end sleep interval.to_f end end def clear_terminal print "\e[H\e[2J" end end end
Version data entries
32 entries across 32 versions & 1 rubygems