prometheus-splash 0.7.0 → 0.8.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +61 -1
  3. data/README.md +400 -178
  4. data/config/splash.yml +45 -5
  5. data/lib/splash/backends.rb +8 -1
  6. data/lib/splash/backends/file.rb +1 -1
  7. data/lib/splash/cli.rb +2 -1
  8. data/lib/splash/cli/commands.rb +100 -16
  9. data/lib/splash/cli/config.rb +12 -1
  10. data/lib/splash/cli/daemon.rb +41 -1
  11. data/lib/splash/cli/logs.rb +144 -48
  12. data/lib/splash/cli/process.rb +145 -52
  13. data/lib/splash/cli/transfers.rb +213 -0
  14. data/lib/splash/cli/webadmin.rb +3 -3
  15. data/lib/splash/commands.rb +85 -19
  16. data/lib/splash/config.rb +145 -52
  17. data/lib/splash/config/flush.rb +2 -2
  18. data/lib/splash/constants.rb +7 -3
  19. data/lib/splash/daemon/metrics.rb +6 -6
  20. data/lib/splash/daemon/orchestrator.rb +76 -36
  21. data/lib/splash/daemon/orchestrator/grammar.rb +16 -1
  22. data/lib/splash/dependencies.rb +6 -1
  23. data/lib/splash/exiter.rb +1 -1
  24. data/lib/splash/helpers.rb +12 -3
  25. data/lib/splash/loggers/cli.rb +2 -10
  26. data/lib/splash/logs.rb +94 -16
  27. data/lib/splash/processes.rb +91 -16
  28. data/lib/splash/transfers.rb +229 -0
  29. data/lib/splash/webadmin.rb +3 -3
  30. data/lib/splash/webadmin/api/routes/commands.rb +2 -2
  31. data/lib/splash/webadmin/api/routes/config.rb +95 -2
  32. data/lib/splash/webadmin/api/routes/logs.rb +32 -17
  33. data/lib/splash/webadmin/api/routes/process.rb +21 -9
  34. data/lib/splash/webadmin/api/routes/sequences.rb +2 -2
  35. data/lib/splash/webadmin/main.rb +3 -0
  36. data/lib/splash/webadmin/portal/controllers/commands.rb +2 -0
  37. data/lib/splash/webadmin/portal/controllers/documentation.rb +2 -0
  38. data/lib/splash/webadmin/portal/controllers/home.rb +24 -0
  39. data/lib/splash/webadmin/portal/controllers/logs.rb +57 -1
  40. data/lib/splash/webadmin/portal/controllers/processes.rb +61 -3
  41. data/lib/splash/webadmin/portal/controllers/proxy.rb +12 -3
  42. data/lib/splash/webadmin/portal/controllers/restclient.rb +6 -1
  43. data/lib/splash/webadmin/portal/controllers/sequences.rb +2 -0
  44. data/lib/splash/webadmin/portal/public/css/ultragreen.css +6 -0
  45. data/lib/splash/webadmin/portal/public/favicon.ico +0 -0
  46. data/lib/splash/webadmin/portal/views/commands.slim +1 -1
  47. data/lib/splash/webadmin/portal/views/documentation.slim +1 -1
  48. data/lib/splash/webadmin/portal/views/home.slim +53 -9
  49. data/lib/splash/webadmin/portal/views/layout.slim +2 -2
  50. data/lib/splash/webadmin/portal/views/log_form.slim +24 -0
  51. data/lib/splash/webadmin/portal/views/log_history.slim +24 -0
  52. data/lib/splash/webadmin/portal/views/logs.slim +93 -21
  53. data/lib/splash/webadmin/portal/views/nav.slim +1 -1
  54. data/lib/splash/webadmin/portal/views/not_found.slim +1 -1
  55. data/lib/splash/webadmin/portal/views/process_form.slim +21 -0
  56. data/lib/splash/webadmin/portal/views/process_history.slim +24 -0
  57. data/lib/splash/webadmin/portal/views/processes.slim +73 -3
  58. data/lib/splash/webadmin/portal/views/proxy.slim +5 -2
  59. data/lib/splash/webadmin/portal/views/restclient.slim +7 -4
  60. data/lib/splash/webadmin/portal/views/restclient_result.slim +24 -20
  61. data/lib/splash/webadmin/portal/views/sequences.slim +1 -1
  62. data/prometheus-splash.gemspec +7 -4
  63. data/ultragreen_roodi_coding_convention.yml +4 -4
  64. metadata +71 -8
@@ -12,65 +12,77 @@ module CLISplash
12
12
  # Thor method : unning Splash configured processes monitors analyse
13
13
  desc "analyse", "analyze processes defined in Splash config"
14
14
  def analyse
15
- log = get_logger
16
- results = ProcessScanner::new
17
- res = results.analyse
18
- log.info "Splash Configured process records :"
19
- full_status = true
20
- results.output.each do |result|
21
- if result[:status] == :running then
22
- log.ok "Process : #{result[:process]} : running"
23
- log.item "Detected patterns : "
24
- result[:patterns].each do |pattern|
25
- log.arrow "/#{pattern}/"
15
+ if is_root? then
16
+ log = get_logger
17
+ results = ProcessScanner::new
18
+ res = results.analyse
19
+ log.info "Splash Configured process records :"
20
+ full_status = true
21
+ results.output.each do |result|
22
+ if result[:status] == :running then
23
+ log.ok "Process : #{result[:process]} : running"
24
+ log.item "Detected patterns : "
25
+ result[:patterns].each do |pattern|
26
+ log.arrow "/#{pattern}/"
27
+ end
28
+ log.item "CPU usage in % : #{result[:cpu]} "
29
+ log.item "Memory usage in % : #{result[:mem]} "
30
+ else
31
+ log.ko "Process : #{result[:process]} : inexistant"
32
+ log.item "Detected patterns : "
33
+ result[:patterns].each do |pattern|
34
+ log.arrow "/#{pattern}/"
35
+ end
26
36
  end
27
- log.item "CPU usage in % : #{result[:cpu]} "
28
- log.item "Memory usage in % : #{result[:mem]} "
29
- else
30
- log.ko "Process : #{result[:process]} : inexistant"
31
- log.item "Detected patterns : "
32
- result[:patterns].each do |pattern|
33
- log.arrow "/#{pattern}/"
34
- end
35
- end
36
37
 
37
- full_status = false unless result[:status] == :running
38
- end
38
+ full_status = false unless result[:status] == :running
39
+ end
39
40
 
40
- if full_status then
41
- log.ok "Global status : no error found"
41
+ if full_status then
42
+ log.ok "Global status : no error found"
43
+ else
44
+ log.error "Global status : some error found"
45
+ end
46
+ splash_exit case: :quiet_exit
42
47
  else
43
- log.error "Global status : some error found"
48
+ splash_exit case: :not_root, :more => "Process analysis"
44
49
  end
45
- splash_exit case: :quiet_exit
46
50
  end
47
51
 
48
52
 
49
53
  # Thor method : running Splash configured processes monitors analyse and sending to Prometheus Pushgateway
50
54
  desc "monitor", "monitor processes defined in Splash config"
51
55
  def monitor
52
- log = get_logger
53
- log.level = :fatal if options[:quiet]
54
- result = ProcessScanner::new
55
- result.analyse
56
- splash_exit result.notify
56
+ if is_root? then
57
+ log = get_logger
58
+ log.level = :fatal if options[:quiet]
59
+ result = ProcessScanner::new
60
+ result.analyse
61
+ splash_exit result.notify
62
+ else
63
+ splash_exit case: :not_root, :more => "Process analysis"
64
+ end
57
65
  end
58
66
 
59
67
  # Thor method : display a specific Splash configured process monitor
60
68
  desc "show PROCESS", "show Splash configured process record for PROCESS"
61
69
  def show(record)
62
- log = get_logger
63
- process_recordset = get_config.processes.select{|item| item[:process] == record }
64
- unless process_recordset.empty? then
65
- record = process_recordset.first
66
- log.item "Process monitor : #{record[:process]}"
67
- log.arrow "patterns :"
68
- record[:patterns].each do |pattern|
69
- log.flat " - /#{pattern}/"
70
+ if is_root? then
71
+ log = get_logger
72
+ process_recordset = get_config.processes.select{|item| item[:process] == record }
73
+ unless process_recordset.empty? then
74
+ record = process_recordset.first
75
+ log.item "Process monitor : #{record[:process]}"
76
+ log.arrow "patterns :"
77
+ record[:patterns].each do |pattern|
78
+ log.flat " - /#{pattern}/"
79
+ end
80
+ splash_exit case: :quiet_exit
81
+ else
82
+ splash_exit case: :not_found, :more => "Process not configured"
70
83
  end
71
- splash_exit case: :quiet_exit
72
84
  else
73
- splash_exit case: :not_found, :more => "Process not configured"
85
+ splash_exit case: :not_root, :more => "Process analysis"
74
86
  end
75
87
  end
76
88
 
@@ -82,20 +94,101 @@ module CLISplash
82
94
  LONGDESC
83
95
  option :detail, :type => :boolean, :aliases => "-D"
84
96
  def list
85
- log = get_logger
86
- log.info "Splash configured process records :"
87
- process_recordset = get_config.processes
88
- log.ko 'No configured process found' if process_recordset.empty?
89
- process_recordset.each do |record|
90
- log.item "Process monitor : #{record[:process]}"
91
- if options[:detail] then
92
- log.arrow "patterns :"
93
- record[:patterns].each do |pattern|
94
- log.flat " - /#{pattern}/"
97
+ if is_root? then
98
+ log = get_logger
99
+ log.info "Splash configured process records :"
100
+ process_recordset = get_config.processes
101
+ log.ko 'No configured process found' if process_recordset.empty?
102
+ process_recordset.each do |record|
103
+ log.item "Process monitor : #{record[:process]}"
104
+ if options[:detail] then
105
+ log.arrow "patterns :"
106
+ record[:patterns].each do |pattern|
107
+ log.flat " - /#{pattern}/"
108
+ end
95
109
  end
96
110
  end
111
+ splash_exit case: :quiet_exit
112
+ else
113
+ splash_exit case: :not_root, :more => "Process analysis"
114
+ end
115
+ end
116
+
117
+ # Thor method : display the full list of Splash configured process monitors
118
+ desc "get_result PROCESS", "Get last or specific process monitoring report"
119
+ long_desc <<-LONGDESC
120
+ Get last or specific process monitoring report\n
121
+ with --date <DATE>, a date format string (same as in history ouput)
122
+ LONGDESC
123
+ option :date, :type => :string, :aliases => "-D"
124
+ def get_result(process)
125
+ if is_root? then
126
+ log = get_logger
127
+ log.info "Process : #{process}"
128
+ config = get_config
129
+ records = ProcessRecords::new(process).get_all_records
130
+ if options[:date] then
131
+ wanted = records.select{|key,value| key.keys.first == options[:date]}.first
132
+ else
133
+ wanted = records.last
134
+ end
135
+ if wanted.nil? then
136
+ splash_exit case: :not_found, more: "Process never monitored"
137
+ else
138
+ record =wanted.keys.first
139
+ value=wanted[record]
140
+ log.item record
141
+ log.arrow "Status : #{value[:status].to_s}"
142
+ log.arrow "CPU Percent : #{value[:cpu_percent]}"
143
+ log.arrow "MEM Percent : #{value[:mem_percent]}"
144
+ end
145
+ else
146
+ splash_exit case: :not_root, :more => "Process get result"
147
+ end
148
+ end
149
+
150
+
151
+ # Thor method : show logs monitoring history
152
+ long_desc <<-LONGDESC
153
+ show Process monitoring history for LABEL\n
154
+ LONGDESC
155
+ option :table, :type => :boolean, :aliases => "-t"
156
+ desc "history PROCESS", "show process monitoring history"
157
+ def history(process)
158
+ if is_root? then
159
+ log = get_logger
160
+ log.info "Process : #{process}"
161
+ config = get_config
162
+ if options[:table] then
163
+ table = TTY::Table.new do |t|
164
+ t << ["Start Date", "Status", "CPU Percent", "MEM Percent"]
165
+ t << ['','','','']
166
+ ProcessRecords::new(process).get_all_records.each do |item|
167
+ record =item.keys.first
168
+ value=item[record]
169
+ t << [record, value[:status].to_s, value[:cpu_percent], value[:mem_percent]]
170
+ end
171
+ end
172
+ if check_unicode_term then
173
+ puts table.render(:unicode)
174
+ else
175
+ puts table.render(:ascii)
176
+ end
177
+
178
+ else
179
+ ProcessRecords::new(process).get_all_records.each do |item|
180
+ record =item.keys.first
181
+ value=item[record]
182
+ log.item record
183
+ log.arrow "Status : #{value[:status].to_s}"
184
+ log.arrow "CPU Percent : #{value[:cpu_percent]}"
185
+ log.arrow "MEM Percent : #{value[:mem_percent]}"
186
+ end
187
+ end
188
+ splash_exit case: :quiet_exit
189
+ else
190
+ splash_exit case: :not_root, :more => "Process analysis"
97
191
  end
98
- splash_exit case: :quiet_exit
99
192
  end
100
193
 
101
194
  end
@@ -0,0 +1,213 @@
1
+ # coding: utf-8
2
+
3
+ # module for all Thor subcommands
4
+ module CLISplash
5
+
6
+ # Thor inherited class for transfers management
7
+ class Transfers < Thor
8
+ include Splash::Transfers
9
+ include Splash::Helpers
10
+ include Splash::Exiter
11
+ include Splash::Loggers
12
+ include Splash::Transfers
13
+
14
+
15
+ # Thor method : running transfer prepare
16
+ long_desc <<-LONGDESC
17
+ Prepare transfer with RSA Public key for NAME\n
18
+ Warning : interactive command only (prompt for passwd)
19
+ LONGDESC
20
+ desc "prepare", "Prepare transfers with RSA Public key"
21
+ def prepare(name)
22
+ acase = run_as_root :prepare_tx, name
23
+ splash_exit acase
24
+ end
25
+
26
+ # Thor method : Execute all transfers
27
+ long_desc <<-LONGDESC
28
+ Execute all transfers\n
29
+ Warning : interactive command only (prompt for passwd)
30
+ LONGDESC
31
+ desc "full_execute", "Execute all transfers"
32
+ def full_execute
33
+ acase = run_as_root :run_txs
34
+ splash_exit acase
35
+ end
36
+
37
+ # Thor method : Get specific result for a transfers
38
+ long_desc <<-LONGDESC
39
+ Get specific result for a transfers\n
40
+ LONGDESC
41
+ option :date, :type => :string, :aliases => "-d"
42
+ desc "get_result TRANSFER", "Get specific result for a transfers "
43
+ def get_result(name)
44
+ log = get_logger
45
+ log.item "Transfer : #{name}"
46
+ config = get_config
47
+ data = TxRecords::new(name).get_all_records.select {|item|
48
+ record =item.keys.first
49
+ value=item[record]
50
+ record == options[:date]}.first
51
+ if data.nil? then
52
+ log.ko "Result for #{name} on date #{options[:date]} not found"
53
+ splash_exit case: :not_found, :more => "Result inexistant"
54
+ else
55
+ record = options[:date]
56
+ value = data[record]
57
+ failed = (value[:count].nil? or value[:done].nil?)? 'undef': value[:count].to_i - value[:done].count
58
+ if value[:end_date].nil? then
59
+ log.item "Event : #{record} STATUS : #{value[:status]}"
60
+ else
61
+ log.item "Tx Begin : #{record} => end : #{value[:end_date]} STATUS : #{value[:status]}"
62
+ end
63
+ log.arrow "Tx Time : #{value[:time]}" unless value[:time].nil?
64
+ log.arrow "nb files : #{value[:count]}" unless value[:count].nil?
65
+ unless value[:wanted].nil?
66
+ log.arrow "Files wanted :" unless value[:wanted].empty?
67
+ value[:wanted].each do |file|
68
+ log.flat " * #{file}"
69
+ end
70
+ end
71
+ unless value[:done].nil?
72
+ log.arrow "Files done :" unless value[:done].empty?
73
+ value[:done].each do |file|
74
+ log.flat " * #{file}"
75
+ end
76
+ end
77
+ unless failed then
78
+ log.arrow "Nb failure : #{failed}"
79
+ end
80
+
81
+ end
82
+ splash_exit case: :quiet_exit
83
+ end
84
+
85
+ # Thor method : show specfic transfers history
86
+ long_desc <<-LONGDESC
87
+ show transfers history for transfer NAME\n
88
+ LONGDESC
89
+ option :table, :type => :boolean, :aliases => "-t"
90
+ desc "history", "Show transfers history"
91
+ def history(name)
92
+ log = get_logger
93
+ log.item "Transfer : #{name}"
94
+ config = get_config
95
+ if options[:table] then
96
+ table = TTY::Table.new do |t|
97
+ t << ["Start Date", "End date", "time", "Files count","File count error","Status"]
98
+ t << ['','','','','','']
99
+ TxRecords::new(name).get_all_records.each do |item|
100
+ record =item.keys.first
101
+ value=item[record]
102
+ start_date = record
103
+ end_date = (value[:end_date].nil?)? '': value[:end_date]
104
+ time = (value[:time].nil?)? '': value[:time]
105
+ count = (value[:count].nil?)? '': value[:count]
106
+ failed = (value[:count].nil? or value[:done].nil?)? '': value[:count].to_i - value[:done].count
107
+ status = value[:status]
108
+ t << [start_date, end_date, time, count, failed, status]
109
+
110
+ end
111
+ end
112
+ if check_unicode_term then
113
+ puts table.render(:unicode)
114
+ else
115
+ puts table.render(:ascii)
116
+ end
117
+
118
+ else
119
+ TxRecords::new(name).get_all_records.each do |item|
120
+ record =item.keys.first
121
+ value=item[record]
122
+ failed = (value[:count].nil? or value[:done].nil?)? 'undef': value[:count].to_i - value[:done].count
123
+ if value[:end_date].nil? then
124
+ log.item "Event : #{record} STATUS : #{value[:status]}"
125
+ else
126
+ log.item "Tx Begin : #{record} => end : #{value[:end_date]} STATUS : #{value[:status]}"
127
+ end
128
+ log.arrow "Tx Time : #{value[:time]}" unless value[:time].nil?
129
+ log.arrow "nb files : #{value[:count]}" unless value[:count].nil?
130
+ unless value[:wanted].nil?
131
+ log.arrow "Files wanted :" unless value[:wanted].empty?
132
+ value[:wanted].each do |file|
133
+ log.flat " * #{file}"
134
+ end
135
+ end
136
+ unless value[:done].nil?
137
+ log.arrow "Files done :" unless value[:done].empty?
138
+ value[:done].each do |file|
139
+ log.flat " * #{file}"
140
+ end
141
+ end
142
+ unless failed then
143
+ log.arrow "Nb failure : #{failed}"
144
+ end
145
+
146
+ end
147
+ end
148
+ splash_exit case: :quiet_exit
149
+ end
150
+
151
+
152
+ # Thor method : display a specific Splash configured transfer
153
+ desc "show TRANSFER", "show Splash configured transfer TRANSFER"
154
+ def show(transfer)
155
+ log = get_logger
156
+ transfer_record_set = get_config.transfers.select{|item| item[:name] == transfer.to_sym }
157
+ unless transfer_record_set.empty? then
158
+ record = transfer_record_set.first
159
+ log.info "Splash transfer : #{record[:name]}"
160
+ log.item "Description : /#{record[:desc]}/"
161
+ log.item "Type : #{record[:type].to_s}"
162
+ log.item "Backup file after copy : #{record[:backup].to_s}"
163
+ log.item "Local spool"
164
+ log.arrow "Path : #{record[:local][:path]}"
165
+ log.arrow "User : #{record[:local][:user]}"
166
+ log.item "Remote spool"
167
+ log.arrow "Path : #{record[:remote][:path]}"
168
+ log.arrow "User : #{record[:remote][:user]}"
169
+ log.arrow "Host : #{record[:remote][:host]}"
170
+ log.item "Post execution"
171
+ log.arrow "Remote command : #{record[:post][:remote_command]}" unless record[:post][:remote_command].nil?
172
+ log.arrow "Local command : #{record[:post][:local_command]}" unless record[:post][:local_command].nil?
173
+ splash_exit case: :quiet_exit
174
+ else
175
+ splash_exit case: :not_found, :more => "log not configured"
176
+ end
177
+ end
178
+
179
+ # Thor method : display the full list of Splash configured transfers
180
+ desc "list", "List all Splash configured transfers"
181
+ long_desc <<-LONGDESC
182
+ Show configured transfers\n
183
+ with --detail, show transfers details
184
+ LONGDESC
185
+ option :detail, :type => :boolean, :aliases => "-D"
186
+ def list
187
+ log = get_logger
188
+ log.info "Splash configured transfer :"
189
+ tx_record_set = get_config.transfers
190
+ log.ko 'No configured transfers found' if tx_record_set.empty?
191
+ tx_record_set.each do |record|
192
+ log.item "Transfer : #{record[:name]} Description : #{record[:desc]}"
193
+ if options[:detail] then
194
+ log.arrow "Type : #{record[:type].to_s}"
195
+ log.arrow "Backup file after copy : #{record[:backup].to_s}"
196
+ log.arrow "Local spool"
197
+ log.flat " * Path : #{record[:local][:path]}"
198
+ log.flat " * User : #{record[:local][:user]}"
199
+ log.arrow "Remote spool"
200
+ log.flat " * Path : #{record[:remote][:path]}"
201
+ log.flat " * User : #{record[:remote][:user]}"
202
+ log.flat " * Host : #{record[:remote][:host]}"
203
+ log.arrow "Post execution"
204
+ log.flat " * Remote command : #{record[:post][:remote_command]}" unless record[:post][:remote_command].nil?
205
+ log.flat " * Local command : #{record[:post][:local_command]}" unless record[:post][:local_command].nil?
206
+ end
207
+ end
208
+ splash_exit case: :quiet_exit
209
+ end
210
+
211
+ end
212
+
213
+ end
@@ -14,14 +14,14 @@ module CLISplash
14
14
  # Thor method : stopping Splash Webadmin
15
15
  desc "stop", "Stopping Splash Webadmin Daemon"
16
16
  def stop
17
- acase = run_as_root :stopdaemon, options
17
+ acase = run_as_root :stopweb, options
18
18
  splash_exit acase
19
19
  end
20
20
 
21
21
  # Thor method : getting execution status of Splashd
22
22
  desc "status", "Splash WebAdmin Daemon status"
23
23
  def status
24
- acase = run_as_root :statusdaemon, options
24
+ acase = run_as_root :statusweb, options
25
25
  splash_exit acase
26
26
  end
27
27
 
@@ -37,7 +37,7 @@ module CLISplash
37
37
  LONGDESC
38
38
  desc "start", "Splash WebAdmin Daemon status"
39
39
  def start
40
- acase = run_as_root :startdaemon
40
+ acase = run_as_root :startweb
41
41
  splash_exit acase
42
42
  end
43
43