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

Version Path
kontena-cli-0.15.5 lib/kontena/cli/services/monitor_command.rb
kontena-cli-0.15.5.rc2 lib/kontena/cli/services/monitor_command.rb
kontena-cli-0.15.5.rc1 lib/kontena/cli/services/monitor_command.rb
kontena-cli-0.15.4 lib/kontena/cli/services/monitor_command.rb
kontena-cli-0.15.4.rc2 lib/kontena/cli/services/monitor_command.rb
kontena-cli-0.15.4.rc1 lib/kontena/cli/services/monitor_command.rb
kontena-cli-0.15.4.pre1 lib/kontena/cli/services/monitor_command.rb
kontena-cli-0.15.3 lib/kontena/cli/services/monitor_command.rb
kontena-cli-0.15.2 lib/kontena/cli/services/monitor_command.rb
kontena-cli-0.15.1 lib/kontena/cli/services/monitor_command.rb
kontena-cli-0.15.0 lib/kontena/cli/services/monitor_command.rb
kontena-cli-0.15.0.rc3 lib/kontena/cli/services/monitor_command.rb
kontena-cli-0.15.0.rc2 lib/kontena/cli/services/monitor_command.rb
kontena-cli-0.15.0.rc1 lib/kontena/cli/services/monitor_command.rb
kontena-cli-0.14.7 lib/kontena/cli/services/monitor_command.rb
kontena-cli-0.14.6 lib/kontena/cli/services/monitor_command.rb
kontena-cli-0.14.5 lib/kontena/cli/services/monitor_command.rb
kontena-cli-0.14.4 lib/kontena/cli/services/monitor_command.rb
kontena-cli-0.14.3 lib/kontena/cli/services/monitor_command.rb
kontena-cli-0.14.2 lib/kontena/cli/services/monitor_command.rb