class Metrics
Singleton to capture and log metrics
Constants
- DEFAULT_METRICS_DIR
- DEFAULT_METRICS_FILE
Attributes
default_log_directory[RW]
default_log_file[RW]
Public Class Methods
instance()
click to toggle source
# File lib/site_prism_plus/metrics.rb, line 32 def self.instance @@instance end
Private Class Methods
new()
click to toggle source
# File lib/site_prism_plus/metrics.rb, line 11 def initialize @default_log_directory = DEFAULT_METRICS_DIR if ENV['SITEPRISM_PLUS_RESULT_DIR'] if Dir.exist?(ENV['SITEPRISM_PLUS_RESULT_DIR']) @default_log_directory = ENV['SITEPRISM_PLUS_RESULT_DIR'] end else results_folder = DEFAULT_METRICS_DIR + '/results' unless Dir.exist? (results_folder) Dir.mkdir(results_folder) end @default_log_directory = results_folder end @default_log_file = @default_log_directory + "/" + DEFAULT_METRICS_FILE if ENV['SITEPRISM_PLUS_RESULT_FILE'] @default_log_file = @default_log_directory + "/" + ENV['SITEPRISM_PLUS_RESULT_FILE'] end @stime = nil @etime = nil end
Public Instance Methods
clear_file()
click to toggle source
# File lib/site_prism_plus/metrics.rb, line 36 def clear_file if File.exist?(@default_log_file) File.delete(@default_log_file) end end
end_time()
click to toggle source
# File lib/site_prism_plus/metrics.rb, line 46 def end_time @etime = Time.now end
log_error_metric(page, action, tag)
click to toggle source
# File lib/site_prism_plus/metrics.rb, line 59 def log_error_metric(page, action, tag) return unless ENV['SITEPRISM_METRICS_ENABLED'] CSV.open(@default_log_file, "a") do |csv| csv << [page, action, tag] end end
log_metric(page, action, tag)
click to toggle source
# File lib/site_prism_plus/metrics.rb, line 50 def log_metric(page, action, tag) return unless ENV['SITEPRISM_METRICS_ENABLED'] @etime = Time.now time_laps = @etime - @stime CSV.open(@default_log_file, "a") do |csv| csv << [page, action, tag, time_laps] end end
start_time()
click to toggle source
# File lib/site_prism_plus/metrics.rb, line 42 def start_time @stime = Time.now end