module ElbPing::Display
This is responsible for all things that send to stdout. It is mostly only used by ‘ElbPing::CLI`
Public Class Methods
Print debug information to the screen
Arguments:
-
exception: (Exception object)
# 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
Print error message to the screen
Arguments:
-
msg: (string) Message to display
# File lib/elbping/display.rb, line 20 def self.error(msg) self.out "ERROR: #{msg}" end
Print message to the screen. Mostly used in case someone ever wants to override it.
Arguments:
-
msg: (string) Message to display
# File lib/elbping/display.rb, line 11 def self.out(msg) puts msg end
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
-
# 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
Display
summary of requests, responses, and latencies (for aggregate and per-node)
Arguments:
-
stats: (
ElbPing::Stats
)
# 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