Class: CLISplash::Processes

Inherits:
Thor
  • Object
show all
Includes:
Splash::Config, Splash::Exiter, Splash::Processes
Defined in:
lib/splash/cli/process.rb

Overview

Thor inherited class for Processes management

Constant Summary

Constants included from Splash::Exiter

Splash::Exiter::EXIT_MAP

Constants included from Splash::Loggers

Splash::Loggers::ALIAS, Splash::Loggers::LEVELS

Constants included from Splash::Constants

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

Instance Method Summary collapse

Methods included from Splash::Exiter

#splash_exit, #splash_return

Methods included from Splash::Loggers

#change_logger, #get_logger, #get_session

Methods included from Splash::Config

#get_config, #rehash_config

Methods included from Splash::ConfigUtilities

#addservice, #checkconfig, #flush_backend, #setupsplash

Methods included from Splash::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

Instance Method Details

#analyseObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/splash/cli/process.rb', line 14

def analyse
  if is_root? then
    log  = get_logger
    results = ProcessScanner::new
    res = results.analyse
    log.info "Splash Configured process records :"
    full_status = true
    results.output.each do |result|
      if result[:status] == :running then
        log.ok "Process : #{result[:process]} : running"
        log.item "Detected patterns : "
        result[:patterns].each do |pattern|
          log.arrow "/#{pattern}/"
        end
        log.item "CPU usage in % : #{result[:cpu]} "
        log.item "Memory usage in % : #{result[:mem]} "
      else
        log.ko "Process : #{result[:process]} : inexistant"
        log.item "Detected patterns : "
        result[:patterns].each do |pattern|
          log.arrow "/#{pattern}/"
        end
      end

      full_status = false unless result[:status] == :running
    end

    if full_status then
      log.ok "Global status : no error found"
    else
      log.error "Global status : some error found"
    end
    splash_exit case: :quiet_exit
  else
    splash_exit case: :not_root, :more => "Process analysis"
  end
end

#get_result(process) ⇒ Object



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/splash/cli/process.rb', line 124

def get_result(process)
  if is_root? then
    log = get_logger
    log.info "Process : #{process}"
    config = get_config
    records = ProcessRecords::new(process).get_all_records
    if options[:date] then
      wanted = records.select{|key,value| key.keys.first == options[:date]}.first
    else
      wanted = records.last
    end
    if wanted.nil? then
      splash_exit case: :not_found, more: "Process never monitored"
    else
      record =wanted.keys.first
      value=wanted[record]
      log.item record
      log.arrow "Status : #{value[:status].to_s}"
      log.arrow "CPU Percent : #{value[:cpu_percent]}"
      log.arrow "MEM Percent : #{value[:mem_percent]}"
    end
  else
    splash_exit case: :not_root, :more => "Process get result"
  end
end

#history(process) ⇒ Object



157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# File 'lib/splash/cli/process.rb', line 157

def history(process)
  if is_root? then
    log = get_logger
    log.info "Process : #{process}"
    config = get_config
    if options[:table] then
      table = TTY::Table.new do |t|
        t << ["Start Date", "Status", "CPU Percent", "MEM Percent"]
        t << ['','','','']
        ProcessRecords::new(process).get_all_records.each do |item|
          record =item.keys.first
          value=item[record]
          t << [record, value[:status].to_s, value[:cpu_percent], value[:mem_percent]]
        end
      end
      if check_unicode_term  then
        puts table.render(:unicode)
      else
        puts table.render(:ascii)
      end

    else
      ProcessRecords::new(process).get_all_records.each do |item|
        record =item.keys.first
        value=item[record]
        log.item record
        log.arrow "Status : #{value[:status].to_s}"
        log.arrow "CPU Percent : #{value[:cpu_percent]}"
        log.arrow "MEM Percent : #{value[:mem_percent]}"
      end
    end
    splash_exit case: :quiet_exit
  else
    splash_exit case: :not_root, :more => "Process analysis"
  end
end

#listObject



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/splash/cli/process.rb', line 96

def list
  if is_root? then
    log = get_logger
    log.info "Splash configured process records :"
    process_recordset = get_config.processes
    log.ko 'No configured process found' if process_recordset.empty?
    process_recordset.each do |record|
      log.item "Process monitor : #{record[:process]}"
      if options[:detail] then
        log.arrow "patterns :"
        record[:patterns].each do |pattern|
          log.flat "   - /#{pattern}/"
        end
      end
    end
    splash_exit case: :quiet_exit
  else
    splash_exit case: :not_root, :more => "Process analysis"
  end
end

#monitorObject



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/splash/cli/process.rb', line 55

def monitor
  if is_root? then
    log = get_logger
    log.level = :fatal if options[:quiet]
    result = ProcessScanner::new
    result.analyse
    splash_exit result.notify
  else
    splash_exit case: :not_root, :more => "Process analysis"
  end
end

#show(record) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/splash/cli/process.rb', line 69

def show(record)
  if is_root? then
    log = get_logger
    process_recordset = get_config.processes.select{|item| item[:process] == record }
    unless process_recordset.empty? then
      record = process_recordset.first
      log.item "Process monitor : #{record[:process]}"
      log.arrow "patterns :"
      record[:patterns].each do |pattern|
        log.flat "   - /#{pattern}/"
      end
      splash_exit case: :quiet_exit
    else
      splash_exit case: :not_found, :more => "Process not configured"
    end
  else
    splash_exit case: :not_root, :more => "Process analysis"
  end
end