class RestFtpDaemon::ReporterWorker

Protected Instance Methods

worker_after() click to toggle source
# File lib/rest-ftp-daemon/workers/reporter.rb, line 21
def worker_after
  # Sleep for a few seconds
  worker_status WORKER_STATUS_WAITING
  sleep @config[:timer]
end
worker_init() click to toggle source
# File lib/rest-ftp-daemon/workers/reporter.rb, line 8
def worker_init
  # Load corker conf
  config_section :reporter

  # Other configuration options
  @feature_newrelic = Conf.feature?(:newrelic)

  # Check that everything is OK
  return "reporter disabled"  if disabled?(@config[:timer])
  return "invalid timer"      unless @config[:timer].to_i > 0
  return false
end
worker_process() click to toggle source
# File lib/rest-ftp-daemon/workers/reporter.rb, line 27
def worker_process
  # Announce we are working
  worker_status WORKER_STATUS_REPORTING

  # Report metrics
  do_metrics
end

Private Instance Methods

do_metrics() click to toggle source
# File lib/rest-ftp-daemon/workers/reporter.rb, line 37
def do_metrics
  # Get common metrics and dump them to logs
  log_debug "begin metrics sample"
  metrics = Metrics.sample

  # Skip following if no valid metrics collected
  unless metrics.is_a? Hash
    log_error "unable to collect metrics"
    return
  end
  log_info "collected metrics (newrelic: #{@feature_newrelic.inspect})", metrics

  # Transpose metrics to NewRelic metrics
  report_newrelic(metrics) if @feature_newrelic
end
report_newrelic(metrics) click to toggle source
# File lib/rest-ftp-daemon/workers/reporter.rb, line 53
def report_newrelic metrics
  metrics_newrelic = {}
  metrics.each do |group, pairs|
    pairs.each do |key, value|
      name = "rftpd/#{group}/#{key}"
      ::NewRelic::Agent.record_metric(name, value)
      metrics_newrelic[name] = value
    end
  end

  # Don't dump metrics unless we're debugging
  newrelic_app_name = Conf.at(:newrelic, :app_name)
  msg_newrelic = "reported metrics to NewRelic [#{newrelic_app_name}]"
  if @config[:debug]
    log_debug msg_newrelic, metrics_newrelic
  else
    log_info msg_newrelic
  end

end