Sha256: c127729071efd83357b22e773abac255e26156ee3a85cda4e6fba557b3173749

Contents?: true

Size: 1.78 KB

Versions: 34

Compression:

Stored size: 1.78 KB

Contents

require_relative 'services_helper'

module Kontena::Cli::Services
  class MonitorCommand < Kontena::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/#{parse_service_id(name)}")
        result = client(token).get("services/#{parse_service_id(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['instances']} 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 = :bright_black
            else
              color = :yellow
            end
            print pastel.send(color, "■")
          end
          puts ''
        end
        sleep interval.to_f
      end
    end

    def clear_terminal
      print "\e[H\e[2J"
    end
  end
end

Version data entries

34 entries across 34 versions & 2 rubygems

Version Path
krates-1.7.11 lib/kontena/cli/services/monitor_command.rb
krates-1.7.10 lib/kontena/cli/services/monitor_command.rb
krates-1.7.9 lib/kontena/cli/services/monitor_command.rb
krates-1.7.8 lib/kontena/cli/services/monitor_command.rb
krates-1.7.7 lib/kontena/cli/services/monitor_command.rb
krates-1.7.6 lib/kontena/cli/services/monitor_command.rb
krates-1.7.5 lib/kontena/cli/services/monitor_command.rb
krates-1.7.4 lib/kontena/cli/services/monitor_command.rb
krates-1.7.3 lib/kontena/cli/services/monitor_command.rb
krates-1.7.2 lib/kontena/cli/services/monitor_command.rb
krates-1.7.1 lib/kontena/cli/services/monitor_command.rb
krates-1.7.0 lib/kontena/cli/services/monitor_command.rb
krates-1.6.9 lib/kontena/cli/services/monitor_command.rb
krates-1.6.8 lib/kontena/cli/services/monitor_command.rb
krates-1.6.7 lib/kontena/cli/services/monitor_command.rb
krates-1.6.6 lib/kontena/cli/services/monitor_command.rb
krates-1.6.5 lib/kontena/cli/services/monitor_command.rb
krates-1.6.4 lib/kontena/cli/services/monitor_command.rb
krates-1.6.3 lib/kontena/cli/services/monitor_command.rb
krates-1.6.2 lib/kontena/cli/services/monitor_command.rb