module Fintop::Printer
Contains functions that gather and print operational data on local Finagle processes.
Public Instance Methods
apply(finagle_procs)
click to toggle source
Given an array of Fintop::Probe::FinagleProcess
objects, gather data and print output.
@param finagle_procs [Array<FinagleProcess>]
# File lib/fintop/printer.rb, line 14 def apply(finagle_procs) if finagle_procs.empty? puts 'Finagle processes: 0' exit end # Create a hash of pid=>ThreadsData objects. threads_data_hash = Hash[ finagle_procs.map { |finp| [finp.pid, Fintop::ThreadsData.new(finp.admin_port)] } ] metrics_hash = Hash[ finagle_procs.map { |finp| [finp.pid, Fintop::Metrics.apply(finp)] } ] print_header(threads_data_hash) finagle_procs.each { |finp| threads_data = threads_data_hash[finp.pid] metrics = metrics_hash[finp.pid] tx_bytes, rx_bytes = [0, 0] metrics.values.each { |scoped_metrics| scoped_metrics.each { |k, v| if not (k =~ /\/sent_bytes$/).nil? tx_bytes = v / 1024 elsif not (k =~ /\/received_bytes$/).nil? rx_bytes = v / 1024 end } } printf( @@row_format_str, finp.pid, finp.admin_port, metrics['jvm']['num_cpus'].to_f, threads_data.num_threads, threads_data.num_non_daemon, threads_data.num_runnable, threads_data.num_waiting, threads_data.num_timed_waiting, tx_bytes, rx_bytes ) } end
print_help()
click to toggle source
Print help output.
# File lib/fintop/printer.rb, line 73 def print_help puts 'usage: fintop [-v|--version] [-h|--help] [-a]' puts puts 'Options:' printf(@@option_format_str, '-a', 'Display info about other users\' ' \ 'Finagle processes as well as your own') printf(@@option_format_str, '-v, --version', 'Print the version number of Fintop being run') printf(@@option_format_str, '-h, --help', 'Print help output') puts puts 'Column Labels:' @@columns.each { |label, description| printf(@@column_label_format_str, label, description) } end
print_version()
click to toggle source
Print fintop version.
# File lib/fintop/printer.rb, line 67 def print_version require 'fintop/version' puts "fintop version #{Fintop::VERSION}" end
Private Instance Methods
print_header(threads_data_hash)
click to toggle source
Print a total process/thread synopsis and column headers.
@param threads_data_hash [Hash<Fixnum, ThreadsData>] a hash of pids and their corresponding ThreadsData
objects.
# File lib/fintop/printer.rb, line 113 def print_header(threads_data_hash) total_threads = threads_data_hash.values.map { |t| t.num_threads }.inject(:+) runnable_threads = threads_data_hash.values.map { |t| t.num_runnable }.inject(:+) waiting_threads = threads_data_hash.values.map { |t| t.num_waiting + t.num_timed_waiting }.inject(:+) puts "Finagle processes: #{threads_data_hash.size}, "\ "Threads: #{total_threads} total, "\ "#{runnable_threads} runnable, "\ "#{waiting_threads} waiting" puts printf(@@row_format_str, *(@@columns.map { |label, desc| label })) end