Class: LitmusPaper::TerminalOutput

Inherits:
Object
  • Object
show all
Defined in:
lib/litmus_paper/terminal_output.rb

Class Method Summary collapse

Class Method Details

._health_color(health) ⇒ Object



39
40
41
42
43
44
45
46
47
# File 'lib/litmus_paper/terminal_output.rb', line 39

def self._health_color(health)
  if health == 0
    return :red
  elsif health < 80
    return :yellow
  else
    return :green
  end
end

.service_statusObject



6
7
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
# File 'lib/litmus_paper/terminal_output.rb', line 6

def self.service_status
  max_service_length = (LitmusPaper.services.keys << "Service").max { |a, b| a.length <=> b.length }.length

  output = "Litmus Paper #{LitmusPaper::VERSION}\n\n"
  output += sprintf(" %s │ %s │ %s │ %s\n", "Service".ljust(max_service_length), "Reported", "Measured", "Health")
  output += sprintf(" %s │ %s │ %s │ %s\n", "Name".ljust(max_service_length), "Health".ljust(8), "Health".ljust(8), "Forced?")
  output += "" * (max_service_length + 2) + "" + "" * 10 + "" + "" * 10 + "" + "" * 9 + "\n"

  LitmusPaper.services.keys.sort.each do |service_name|
    health = LitmusPaper.services[service_name].current_health
    measured_health = health.measured_health.to_s.rjust(3)
    reported_health = health.value.to_s.rjust(3)
    service_forced = if health.forced?
                       message = "Yes,"
                       forced_reason, forced_health = health.forced_reason.split("\n")
                       if forced_health
                         message += " Health: #{forced_health}"
                       end
                        message += " Reason: #{forced_reason}"
                     else
                       "No"
                     end
    output += sprintf(" %-#{max_service_length}s   %s   %s   %s\n",
                      service_name,
                      reported_health.center(8).colorize(_health_color(health.value)),
                      measured_health.center(8),
                      service_forced,
                     )
  end

  return output
end