Class: Splash::Processes::ProcessRecords

Inherits:
Object
  • Object
show all
Includes:
Backends, Constants
Defined in:
lib/splash/processes.rb

Constant Summary

Constants included from Constants

Constants::AUTHOR, Constants::BACKENDS_STRUCT, Constants::CONFIG_FILE, Constants::COPYRIGHT, Constants::DAEMON_LOGMON_SCHEDULING, Constants::DAEMON_METRICS_SCHEDULING, Constants::DAEMON_PID_FILE, Constants::DAEMON_PROCESS_NAME, Constants::DAEMON_PROCMON_SCHEDULING, Constants::DAEMON_STDERR_TRACE, Constants::DAEMON_STDOUT_TRACE, Constants::DEFAULT_RETENTION, Constants::EMAIL, Constants::EXECUTION_TEMPLATE, Constants::EXECUTION_TEMPLATE_TOKENS_LIST, Constants::LICENSE, Constants::LOGGERS_STRUCT, Constants::PID_PATH, Constants::PROMETHEUS_ALERTMANAGER_URL, Constants::PROMETHEUS_PUSHGATEWAY_URL, Constants::PROMETHEUS_URL, Constants::TRACE_PATH, Constants::TRANSPORTS_STRUCT, Constants::VERSION, Constants::WEBADMIN_IP, Constants::WEBADMIN_PID_FILE, Constants::WEBADMIN_PID_PATH, Constants::WEBADMIN_PORT, Constants::WEBADMIN_PROCESS_NAME, Constants::WEBADMIN_PROXY, Constants::WEBADMIN_STDERR_TRACE, Constants::WEBADMIN_STDOUT_TRACE

Instance Method Summary collapse

Methods included from Backends

#get_backend, #list_backends

Methods included from Config

#get_config, #rehash_config

Methods included from ConfigUtilities

#addservice, #checkconfig, #flush_backend, #setupsplash

Methods included from Helpers

#check_unicode_term, #daemonize, #format_by_extensions, #format_response, #get_processes, #group_root, #install_file, #is_root?, #make_folder, #make_link, #run_as_root, #search_file_in_gem, #user_root, #verify_file, #verify_folder, #verify_link, #verify_service

Constructor Details

#initialize(name) ⇒ ProcessRecords

Returns a new instance of ProcessRecords.



50
51
52
53
# File 'lib/splash/processes.rb', line 50

def initialize(name)
  @name = name
  @backend = get_backend :process_trace
end

Instance Method Details

#add_record(record) ⇒ Object



76
77
78
79
80
# File 'lib/splash/processes.rb', line 76

def add_record(record)
  data = get_all_records
  data.push({ DateTime.now.to_s => record })
  @backend.put key: @name, value: data.to_yaml
end

#clearObject



55
56
57
# File 'lib/splash/processes.rb', line 55

def clear
  @backend.del({:key => @name}) if  @backend.exist?({key: @name})
end

#get_all_records(options = {}) ⇒ Object



82
83
84
# File 'lib/splash/processes.rb', line 82

def get_all_records(options={})
  return (@backend.exist?({key: @name}))? YAML::load(@backend.get({key: @name})) : []
end

#purge(retention) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/splash/processes.rb', line 59

def purge(retention)
  retention = {} if retention.nil?
  if retention.include? :hours then
    adjusted_datetime = DateTime.now - retention[:hours].to_f / 24
  elsif retention.include? :hours then
    adjusted_datetime = DateTime.now - retention[:days].to_i
  else
    adjusted_datetime = DateTime.now - DEFAULT_RETENTION
  end

  data = get_all_records

  data.delete_if { |item|
    DateTime.parse(item.keys.first) <= (adjusted_datetime)}
  @backend.put key: @name, value: data.to_yaml
end