Module: ElbPing::Display

Defined in:
lib/elbping/display.rb

Overview

This is responsible for all things that send to stdout. It is mostly only used by ‘ElbPing::CLI`

Class Method Summary collapse

Class Method Details

.debug(exception) ⇒ Object

Print debug information to the screen

Arguments:

  • exception: (Exception object)



29
30
31
32
33
34
# File 'lib/elbping/display.rb', line 29

def self.debug(exception)
  if ENV["DEBUG"]
    self.out "DEBUG: #{exception.message}"
    self.out "DEBUG: #{exception.backtrace}"
  end
end

.error(msg) ⇒ Object

Print error message to the screen

Arguments:

  • msg: (string) Message to display



20
21
22
# File 'lib/elbping/display.rb', line 20

def self.error(msg)
  self.out "ERROR: #{msg}"
end

.out(msg) ⇒ Object

Print message to the screen. Mostly used in case someone ever wants to override it.

Arguments:

  • msg: (string) Message to display



11
12
13
# File 'lib/elbping/display.rb', line 11

def self.out(msg)
  puts msg
end

.response(status) ⇒ Object

Format and display the ping data given a response

Arguments:

  • status: (hash) containing:

    • :node (string) IP address of node

    • :code (Fixnum || string || symbol) HTTP status code or symbol representing error during ping

    • :duration (Fixnum) Latency in milliseconds from ping

    • :exception (string, optional) Message to display from exception



45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/elbping/display.rb', line 45

def self.response(status)
  node = status[:node]
  code = status[:code]
  duration = status[:duration]
  exc = status[:exception]
  sslSubject = status[:sslSubject].join(',') if status[:sslSubject]
  sslExpires = status[:sslExpires]
  sslHostMatch = status[:sslHostMatch]

  exc_display = exc ? "exception=#{exc}" : ''
  ssl_display = (sslSubject and sslExpires) ? "ssl cn=#{sslSubject} match=#{sslHostMatch} expires=#{sslExpires}" : ''

  self.out "Response from: #{node.rjust(15)}: code=#{code.to_s} time=#{duration}ms #{ssl_display} #{exc_display}"
end

.summary(stats) ⇒ Object

Display summary of requests, responses, and latencies (for aggregate and per-node)

Arguments:

  • stats: (ElbPing::Stats)



65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/elbping/display.rb', line 65

def self.summary(stats)
  pinged_nodes = stats.nodes.keys.select { |n| stats.nodes[n][:requests] > 0 }
  pinged_nodes.each { |node|
    loss_pct = (stats.node_loss(node) * 100).to_i
    self.out "--- #{node} statistics ---"
    self.out "#{stats.nodes[node][:requests]} requests, #{stats.nodes[node][:responses]} responses, #{loss_pct}% loss"
    self.out "min/avg/max = #{stats.nodes[node][:latencies].min}/#{stats.nodes[node][:latencies].mean}/#{stats.nodes[node][:latencies].max} ms"
  }

  loss_pct = (stats.total_loss * 100).to_i
  self.out '--- total statistics ---'
  self.out "#{stats.total[:requests]} requests, #{stats.total[:responses]} responses, #{loss_pct}% loss, #{stats.nodes.size} nodes"
  self.out "min/avg/max = #{stats.total[:latencies].min}/#{stats.total[:latencies].mean}/#{stats.total[:latencies].max} ms"
end