Sha256: 13fbfac5cd601dcc0ecd2326b3167ed14c5ead39543e9691b200b3da8f950149

Contents?: true

Size: 1.73 KB

Versions: 12

Compression:

Stored size: 1.73 KB

Contents

require_relative 'services_helper'

module Kontena::Cli::Services
  class MonitorCommand < Clamp::Command
    include Kontena::Cli::Common
    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

12 entries across 12 versions & 1 rubygems

Version Path
kontena-cli-0.11.7 lib/kontena/cli/services/monitor_command.rb
kontena-cli-0.11.6 lib/kontena/cli/services/monitor_command.rb
kontena-cli-0.11.5 lib/kontena/cli/services/monitor_command.rb
kontena-cli-0.11.4 lib/kontena/cli/services/monitor_command.rb
kontena-cli-0.11.3 lib/kontena/cli/services/monitor_command.rb
kontena-cli-0.11.2 lib/kontena/cli/services/monitor_command.rb
kontena-cli-0.11.1 lib/kontena/cli/services/monitor_command.rb
kontena-cli-0.11.0 lib/kontena/cli/services/monitor_command.rb
kontena-cli-0.10.3 lib/kontena/cli/services/monitor_command.rb
kontena-cli-0.10.2 lib/kontena/cli/services/monitor_command.rb
kontena-cli-0.10.1 lib/kontena/cli/services/monitor_command.rb
kontena-cli-0.10.0 lib/kontena/cli/services/monitor_command.rb