Class: Splash::Processes::ProcessScanner

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

Overview

Processes scanner and notifier

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 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

#initializeSplash::Processes::ProcessScanner

ProcessScanner Constructor : initialize prometheus metrics



96
97
98
99
# File 'lib/splash/processes.rb', line 96

def initialize
  @processes_target = Marshal.load(Marshal.dump(get_config.processes))
  @config = get_config
end

Instance Method Details

#analyseHash

start process analyse for process target in config

Returns:

  • (Hash)

    Exiter case :quiet_exit



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/splash/processes.rb', line 104

def analyse
  @processes_target.each do |record|
    list =  get_processes patterns: record[:patterns], full: true
    if list.empty?
      record[:status] = :inexistant
      record[:cpu] = 0
      record[:mem] = 0
    else
      record[:status] = :running
      record[:cpu] = list[0]['%CPU']
      record[:mem] = list[0]['%MEM']
    end
  end
  return {:case => :quiet_exit }
end

#notify(options = {}) ⇒ Hash

start notification on prometheus for metrics

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :session (String)

    a session number for log daemon

Returns:

  • (Hash)

    Exiter case :quiet_exit



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/splash/processes.rb', line 130

def notify(options = {})
  log = get_logger
  unless verify_service url: @config.prometheus_pushgateway_url then
    return  { :case => :service_dependence_missing, :more => "Prometheus Notification not send." }
  end
  session = (options[:session]) ? options[:session] : log.get_session
  log.info "Sending metrics to Prometheus Pushgateway", session
  @processes_target.each do |item|
    processrec = ProcessRecords::new item[:process]
    missing = (item[:status] == :missing)? 1 : 0
    val = (item[:status] == :running )? 1 : 0
    processrec.purge(item[:retention])
    processrec.add_record :status => item[:status],
                     :cpu_percent => item[:cpu],
                     :mem_percent => item[:mem] ,
                     :process => item[:process]
    processmonitor = ProcessNotifier::new({name: item[:process], status: val , cpu_percent: item[:cpu], mem_percent: item[:mem]})
    if processmonitor.notify then
      log.ok "Sending metrics for process #{item[:process]} to Prometheus Pushgateway", session
    else
      log.ko "Failed to send metrics for process #{item[:process]} to Prometheus Pushgateway", session
    end
  end
  return {:case => :quiet_exit }
end

#outputHash

pseudo-accessor on @processes_target

Returns:

  • (Hash)

    the processes structure



122
123
124
# File 'lib/splash/processes.rb', line 122

def output
  return @processes_target
end