Class: Ragdoll::CLI::Stats

Inherits:
Object
  • Object
show all
Defined in:
lib/ragdoll/cli/commands/stats.rb

Instance Method Summary collapse

Instance Method Details

#call(options) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/ragdoll/cli/commands/stats.rb', line 8

def call(options)
  client = StandaloneClient.new

  puts 'Retrieving system statistics'
  puts "Options: #{options.to_h}" unless options.to_h.empty?
  puts

  stats = client.stats

  if stats.nil? || stats.empty?
    puts 'No statistics available.'
    return
  end

  case options[:format]
  when 'json'
    puts JSON.pretty_generate(stats)
  when 'plain'
    stats.each do |key, value|
      puts "#{key.to_s.tr('_', ' ').capitalize}: #{value}"
    end
  else
    # Table format (default)
    puts 'System Statistics:'
    puts
    puts 'Metric'.ljust(30) + 'Value'
    puts '-' * 50

    stats.each do |key, value|
      metric = key.to_s.tr('_', ' ').capitalize.ljust(30)
      puts "#{metric}#{value}"
    end
  end
end