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.

print_version() click to toggle source

Print fintop version.

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.