class Nexaas::Auditor::StatisticsTrackers::Stathat

Constants

ShortRunningProcessNamesRegex

Regex to determine if the current process is a short lived kind of script.

Attributes

logger[R]

Public Class Methods

new(key, namespace=nil) click to toggle source
# File lib/nexaas/auditor/statistics_trackers/stathat.rb, line 8
def initialize(key, namespace=nil)
  @key = key.to_s
  @namespace = namespace.to_s
  @logger = Nexaas::Auditor.configuration.logger
  if Nexaas::Auditor.configuration.statistics_service == 'stathat'
    require 'stathat'
  end
  raise ArgumentError, "required Stathat EZ Key not found" if @key == ''
end

Private Instance Methods

send_track(type, full_name, value) click to toggle source
# File lib/nexaas/auditor/statistics_trackers/stathat.rb, line 28
def send_track(type, full_name, value)
  # the default StatHat::API Ruby methods are asynchronous. If you are
  # using this gem in a script that is short-lived, you can use
  # StatHat::SyncAPI to make synchronous calls to StatHat.
  klass = (short_running_process? ? ::StatHat::SyncAPI : ::StatHat::API)

  logger.debug("[#{self.class}] calling #{klass}.ez_post_#{type}('#{full_name}', '#{@key}', #{value})")
  klass.send("ez_post_#{type}", full_name, @key, value)
end
short_running_process?() click to toggle source
# File lib/nexaas/auditor/statistics_trackers/stathat.rb, line 24
def short_running_process?
  $0 =~ ShortRunningProcessNamesRegex
end