prometheus-splash 0.8.0 → 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +1 -1
- data/config/splash.yml +14 -2
- data/lib/splash/cli/commands.rb +125 -5
- data/lib/splash/cli/logs.rb +108 -47
- data/lib/splash/cli/process.rb +112 -52
- data/lib/splash/cli/transfers.rb +10 -3
- data/lib/splash/commands.rb +85 -19
- data/lib/splash/constants.rb +3 -3
- data/lib/splash/logs.rb +90 -16
- data/lib/splash/processes.rb +87 -16
- data/lib/splash/transfers.rb +13 -8
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 60d3aa2e635dbea8022a1804e9886e495648ce777db2293442ae3a16bae7e25a
|
4
|
+
data.tar.gz: 14912be5e4171daae1ee7706f98ac7974c43a96d56e7daa58a1e9a40d46b60ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d66a48e63fd8940c6343113511e1ad91531037013a042a79348a755de74e6447a791854fa2ec82461c38695370402e30790ac7660fd75c0cc82c0f5ef788701d
|
7
|
+
data.tar.gz: 9d59657c45219e31af8a6c85fc137925ee03ccecc7a98e62848ba28540ec2e39df674fcd391b51334c4bc1252de487a5a55110a286707fee9a38e54bf85a3cfc
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -9,7 +9,7 @@ SPLASH is **Supervision with Prometheus of Logs and Asynchronous tasks orchestra
|
|
9
9
|
* Web : http://www.ultragreen.net
|
10
10
|
* Github : https://github.com/Ultragreen/prometheus-splash
|
11
11
|
* Rubygems : https://rubygems.org/gems/prometheus-splash
|
12
|
-
* DOC yardoc : https://www.rubydoc.info/gems/prometheus-splash/0.8.
|
12
|
+
* DOC yardoc : https://www.rubydoc.info/gems/prometheus-splash/0.8.1
|
13
13
|
|
14
14
|
Prometheus Logs and Batchs supervision over PushGateway
|
15
15
|
|
data/config/splash.yml
CHANGED
@@ -26,9 +26,15 @@
|
|
26
26
|
# :port: 6379
|
27
27
|
# #:auth: "mykey"
|
28
28
|
# :base: 1
|
29
|
-
:
|
29
|
+
:transfers_trace:
|
30
30
|
:type: :file
|
31
|
-
:path: /var/run/splash/
|
31
|
+
:path: /var/run/splash/transfers
|
32
|
+
:logs_trace:
|
33
|
+
:type: :file
|
34
|
+
:path: /var/run/splash/logs
|
35
|
+
:process_trace:
|
36
|
+
:type: :file
|
37
|
+
:path: /var/run/splash/process
|
32
38
|
|
33
39
|
:transports:
|
34
40
|
:active: :rabbitmq
|
@@ -122,15 +128,21 @@
|
|
122
128
|
- :label: :log_app_1
|
123
129
|
:log: /tmp/test
|
124
130
|
:pattern: ERROR
|
131
|
+
:retention:
|
132
|
+
:hours: 5
|
125
133
|
- :label: :log_app_2
|
126
134
|
:log: /tmp/test2
|
127
135
|
:pattern: ERROR
|
136
|
+
:retention:
|
137
|
+
:hours: 5
|
128
138
|
|
129
139
|
### configuration of monitored processes
|
130
140
|
:processes:
|
131
141
|
- :process: cron
|
132
142
|
:patterns:
|
133
143
|
- cron
|
144
|
+
:retention:
|
145
|
+
:hours: 5
|
134
146
|
|
135
147
|
|
136
148
|
###
|
data/lib/splash/cli/commands.rb
CHANGED
@@ -93,6 +93,9 @@ module CLISplash
|
|
93
93
|
option :at, :type => :string
|
94
94
|
option :in, :type => :string
|
95
95
|
def schedule(name)
|
96
|
+
unless is_root? then
|
97
|
+
splash_exit case: :not_root, :more => "Command scheduling"
|
98
|
+
end
|
96
99
|
log = get_logger
|
97
100
|
log.level = :fatal if options[:quiet]
|
98
101
|
hostname = (options[:hostname])? options[:hostname] : Socket.gethostname
|
@@ -129,6 +132,9 @@ module CLISplash
|
|
129
132
|
LONGDESC
|
130
133
|
option :hostname, :type => :string, :aliases => "-H"
|
131
134
|
def treeview(command)
|
135
|
+
unless is_root? then
|
136
|
+
splash_exit case: :not_root, :more => "Command treeview"
|
137
|
+
end
|
132
138
|
depht = 0
|
133
139
|
log = get_logger
|
134
140
|
if options[:hostname] then
|
@@ -179,6 +185,9 @@ module CLISplash
|
|
179
185
|
option :detail, :type => :boolean, :aliases => "-D"
|
180
186
|
option :hostname, :type => :string, :aliases => "-H"
|
181
187
|
def list
|
188
|
+
unless is_root? then
|
189
|
+
splash_exit case: :not_root, :more => "Command list"
|
190
|
+
end
|
182
191
|
log = get_logger
|
183
192
|
list = {}
|
184
193
|
if options[:hostname] then
|
@@ -227,6 +236,9 @@ module CLISplash
|
|
227
236
|
LONGDESC
|
228
237
|
option :hostname, :type => :string, :aliases => "-H"
|
229
238
|
def show(command)
|
239
|
+
unless is_root? then
|
240
|
+
splash_exit case: :not_root, :more => "Command show specifications"
|
241
|
+
end
|
230
242
|
log = get_logger
|
231
243
|
list = {}
|
232
244
|
if options[:hostname] then
|
@@ -265,6 +277,57 @@ module CLISplash
|
|
265
277
|
end
|
266
278
|
end
|
267
279
|
|
280
|
+
|
281
|
+
|
282
|
+
# Thor method : show commands executions history
|
283
|
+
long_desc <<-LONGDESC
|
284
|
+
show commands executions history for LABEL\n
|
285
|
+
LONGDESC
|
286
|
+
option :table, :type => :boolean, :aliases => "-t"
|
287
|
+
desc "history LABEL", "show commands executions history"
|
288
|
+
def history(command)
|
289
|
+
if is_root? then
|
290
|
+
log = get_logger
|
291
|
+
log.info "Log : #{command}#"
|
292
|
+
config = get_config
|
293
|
+
if options[:table] then
|
294
|
+
table = TTY::Table.new do |t|
|
295
|
+
t << ["Start Date","Status", "end_date", "Execution time","STDOUT empty ? ", "STDERR empty ? "]
|
296
|
+
t << ['','','','','','']
|
297
|
+
CmdRecords::new(command).get_all_records.each do |item|
|
298
|
+
record =item.keys.first
|
299
|
+
value=item[record]
|
300
|
+
t << [record, value[:status].to_s,
|
301
|
+
value[:end_date],
|
302
|
+
value[:exec_time],
|
303
|
+
value[:stdout].empty?,
|
304
|
+
value[:stdout].empty?]
|
305
|
+
end
|
306
|
+
end
|
307
|
+
if check_unicode_term then
|
308
|
+
puts table.render(:unicode)
|
309
|
+
else
|
310
|
+
puts table.render(:ascii)
|
311
|
+
end
|
312
|
+
|
313
|
+
else
|
314
|
+
CmdRecords::new(command).get_all_records.each do |item|
|
315
|
+
record =item.keys.first
|
316
|
+
value=item[record]
|
317
|
+
log.item record
|
318
|
+
log.arrow "Status : #{value[:status].to_s}"
|
319
|
+
log.arrow "End date : #{value[:end_date]}"
|
320
|
+
log.arrow "Execution time : #{value[:exec_time]}"
|
321
|
+
log.arrow "STDOUT empty ? : #{value[:stdout].empty?}"
|
322
|
+
log.arrow "STDERR empty ? : #{value[:stderr].empty?}"
|
323
|
+
end
|
324
|
+
end
|
325
|
+
splash_exit case: :quiet_exit
|
326
|
+
else
|
327
|
+
splash_exit case: :not_root, :more => "Command execution history"
|
328
|
+
end
|
329
|
+
end
|
330
|
+
|
268
331
|
# Thor method : getting information on the last execution of a command
|
269
332
|
desc "lastrun COMMAND", "Show last running result for specific configured command COMMAND"
|
270
333
|
long_desc <<-LONGDESC
|
@@ -273,6 +336,9 @@ module CLISplash
|
|
273
336
|
LONGDESC
|
274
337
|
option :hostname, :type => :string, :aliases => "-H"
|
275
338
|
def lastrun(command)
|
339
|
+
unless is_root? then
|
340
|
+
splash_exit case: :not_root, :more => "Command last execution report"
|
341
|
+
end
|
276
342
|
log = get_logger
|
277
343
|
backend = get_backend :execution_trace
|
278
344
|
redis = (backend.class == Splash::Backends::Redis)? true : false
|
@@ -294,7 +360,7 @@ module CLISplash
|
|
294
360
|
tp = Template::new(
|
295
361
|
list_token: get_config.execution_template_tokens,
|
296
362
|
template_file: get_config.execution_template_path)
|
297
|
-
tp.map YAML::load(res)
|
363
|
+
tp.map YAML::load(res).last.values.first
|
298
364
|
log.flat tp.output
|
299
365
|
else
|
300
366
|
log.ko "Command not already runned."
|
@@ -305,6 +371,58 @@ module CLISplash
|
|
305
371
|
end
|
306
372
|
end
|
307
373
|
|
374
|
+
|
375
|
+
# Thor method : getting information on one specific execution of a command
|
376
|
+
desc "onerun COMMAND", "Show running result for specific configured command COMMAND"
|
377
|
+
long_desc <<-LONGDESC
|
378
|
+
Show specific running result for specific configured command COMMAND\n
|
379
|
+
with --hostname <HOSTNAME>, an other Splash monitored server (only with Redis backend configured)
|
380
|
+
with --date <DATE>, a date format string (same as in history ouput)
|
381
|
+
|
382
|
+
LONGDESC
|
383
|
+
option :hostname, :type => :string, :aliases => "-H"
|
384
|
+
option :date, :type => :string, :aliases => "-D", :required => true
|
385
|
+
def onerun(command)
|
386
|
+
unless is_root? then
|
387
|
+
splash_exit case: :not_root, :more => "Command specific execution report"
|
388
|
+
end
|
389
|
+
log = get_logger
|
390
|
+
backend = get_backend :execution_trace
|
391
|
+
redis = (backend.class == Splash::Backends::Redis)? true : false
|
392
|
+
if not redis and options[:hostname] then
|
393
|
+
splash_exit case: :specific_config_required, :more => "Redis backend is requiered for Remote execution report request"
|
394
|
+
end
|
395
|
+
splash_exit case: :not_root if not is_root? and not redis
|
396
|
+
list = get_config.commands.keys
|
397
|
+
if options[:hostname] then
|
398
|
+
options[:hostname] = Socket.gethostname if options[:hostname] == 'hostname'
|
399
|
+
list = backend.list("*", options[:hostname]).map(&:to_sym)
|
400
|
+
end
|
401
|
+
if list.include? command.to_sym then
|
402
|
+
log.info "Splash command #{command} previous execution report:\n"
|
403
|
+
req = { :key => command}
|
404
|
+
req[:hostname] = options[:hostname] if options[:hostname]
|
405
|
+
if backend.exist? req then
|
406
|
+
res = backend.get req
|
407
|
+
tp = Template::new(
|
408
|
+
list_token: get_config.execution_template_tokens,
|
409
|
+
template_file: get_config.execution_template_path)
|
410
|
+
prov = YAML::load(res).select{|key,value| key.keys.first == options[:date]}
|
411
|
+
if prov.empty? then
|
412
|
+
log.ko "Command not runned one this date or date misformatted."
|
413
|
+
else
|
414
|
+
tp.map prov.first.values.first
|
415
|
+
log.flat tp.output
|
416
|
+
end
|
417
|
+
else
|
418
|
+
log.ko "Command not already runned."
|
419
|
+
end
|
420
|
+
splash_exit case: :quiet_exit
|
421
|
+
else
|
422
|
+
splash_exit case: :not_found, :more => "Command report never runned remotly" if options[:hostname]
|
423
|
+
end
|
424
|
+
end
|
425
|
+
|
308
426
|
# Thor method : getting the list of avaibles executions reports
|
309
427
|
desc "getreportlist", "list all executions report results "
|
310
428
|
long_desc <<-LONGDESC
|
@@ -320,6 +438,9 @@ module CLISplash
|
|
320
438
|
option :all, :type => :boolean, :negate => false, :aliases => "-A"
|
321
439
|
option :detail, :type => :boolean, :aliases => "-D"
|
322
440
|
def getreportlist
|
441
|
+
unless is_root? then
|
442
|
+
splash_exit case: :not_root, :more => "Command execution report list"
|
443
|
+
end
|
323
444
|
log = get_logger
|
324
445
|
options[:hostname] = Socket.gethostname if options[:hostname] == 'hostname'
|
325
446
|
if options[:hostname] and options[:all] then
|
@@ -355,10 +476,9 @@ module CLISplash
|
|
355
476
|
req = { :key => command }
|
356
477
|
req[:hostname] = host if options[:all]
|
357
478
|
res = YAML::load(backend.get(req))
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
log.arrow "Execution time : #{res[:exec_time]}"
|
479
|
+
res.each do |record|
|
480
|
+
log.arrow "#{record.keys.first} : #{record[record.keys.first][:status]}"
|
481
|
+
end
|
362
482
|
end
|
363
483
|
end
|
364
484
|
splash_exit case: :quiet_exit
|
data/lib/splash/cli/logs.rb
CHANGED
@@ -12,61 +12,73 @@ module CLISplash
|
|
12
12
|
# Thor method : running Splash configured logs monitors analyse
|
13
13
|
desc "analyse", "analyze logs defined in Splash config"
|
14
14
|
def analyse
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
15
|
+
if is_root? then
|
16
|
+
log = get_logger
|
17
|
+
results = LogScanner::new
|
18
|
+
res = results.analyse
|
19
|
+
log.info "SPlash Configured log monitors :"
|
20
|
+
full_status = true
|
21
|
+
results.output.each do |result|
|
22
|
+
if result[:status] == :clean then
|
23
|
+
log.ok "Log : #{result[:log]} with label : #{result[:label]} : no errors"
|
24
|
+
log.item "Detected pattern : #{result[:pattern]}"
|
25
|
+
log.item "Nb lines = #{result[:lines]}"
|
26
|
+
elsif result[:status] == :missing then
|
27
|
+
log.ko "Log : #{result[:log]} with label : #{result[:label]} : missing !"
|
28
|
+
log.item "Detected pattern : #{result[:pattern]}"
|
29
|
+
else
|
30
|
+
log.ko "Log : #{result[:log]} with label : #{result[:label]} : #{result[:count]} errors"
|
31
|
+
log.item "Detected pattern : #{result[:pattern]}"
|
32
|
+
log.item "Nb lines = #{result[:lines]}"
|
33
|
+
end
|
33
34
|
|
34
|
-
|
35
|
-
|
35
|
+
full_status = false unless result[:status] == :clean
|
36
|
+
end
|
36
37
|
|
37
|
-
|
38
|
-
|
38
|
+
if full_status then
|
39
|
+
log.ok "Global status : no error found"
|
40
|
+
else
|
41
|
+
log.error "Global status : some error found"
|
42
|
+
end
|
43
|
+
splash_exit case: :quiet_exit
|
39
44
|
else
|
40
|
-
|
45
|
+
splash_exit case: :not_root, :more => "Log analysis"
|
41
46
|
end
|
42
|
-
splash_exit case: :quiet_exit
|
43
47
|
end
|
44
48
|
|
45
49
|
|
46
50
|
# Thor method : running Splash configured logs monitors analyse and sending to Prometheus Pushgateway
|
47
51
|
desc "monitor", "monitor logs defined in Splash config"
|
48
52
|
def monitor
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
53
|
+
if is_root? then
|
54
|
+
log = get_logger
|
55
|
+
log.level = :fatal if options[:quiet]
|
56
|
+
result = LogScanner::new
|
57
|
+
result.analyse
|
58
|
+
splash_exit result.notify
|
59
|
+
else
|
60
|
+
splash_exit case: :not_root, :more => "Log analysis"
|
61
|
+
end
|
54
62
|
|
55
63
|
end
|
56
64
|
|
57
65
|
# Thor method : display a specific Splash configured log monitor
|
58
66
|
desc "show LOG", "show Splash configured log monitoring for LOG"
|
59
67
|
def show(logrecord)
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
+
if is_root? then
|
69
|
+
log = get_logger
|
70
|
+
log_record_set = get_config.logs.select{|item| item[:log] == logrecord or item[:label] == logrecord.to_sym}
|
71
|
+
unless log_record_set.empty? then
|
72
|
+
record = log_record_set.first
|
73
|
+
log.info "Splash log monitor : #{record[:log]}"
|
74
|
+
log.item "pattern : /#{record[:pattern]}/"
|
75
|
+
log.item "label : #{record[:label]}"
|
76
|
+
splash_exit case: :quiet_exit
|
77
|
+
else
|
78
|
+
splash_exit case: :not_found, :more => "log not configured"
|
79
|
+
end
|
68
80
|
else
|
69
|
-
splash_exit case: :
|
81
|
+
splash_exit case: :not_root, :more => "Log analysis"
|
70
82
|
end
|
71
83
|
end
|
72
84
|
|
@@ -78,17 +90,66 @@ module CLISplash
|
|
78
90
|
LONGDESC
|
79
91
|
option :detail, :type => :boolean, :aliases => "-D"
|
80
92
|
def list
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
93
|
+
if is_root? then
|
94
|
+
log = get_logger
|
95
|
+
log.info "Splash configured log monitoring :"
|
96
|
+
log_record_set = get_config.logs
|
97
|
+
log.ko 'No configured commands found' if log_record_set.empty?
|
98
|
+
log_record_set.each do |record|
|
99
|
+
log.item "log monitor : #{record[:log]} label : #{record[:label]}"
|
100
|
+
if options[:detail] then
|
101
|
+
log.arrow "pattern : /#{record[:pattern]}/"
|
102
|
+
end
|
103
|
+
end
|
104
|
+
splash_exit case: :quiet_exit
|
105
|
+
else
|
106
|
+
splash_exit case: :not_root, :more => "Log analysis"
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
|
111
|
+
# Thor method : show logs monitoring history
|
112
|
+
long_desc <<-LONGDESC
|
113
|
+
show logs monitoring history for LABEL\n
|
114
|
+
LONGDESC
|
115
|
+
option :table, :type => :boolean, :aliases => "-t"
|
116
|
+
desc "history LABEL", "show logs monitoring history"
|
117
|
+
def history(label)
|
118
|
+
if is_root? then
|
119
|
+
log = get_logger
|
120
|
+
log.info "Log : #{label}"
|
121
|
+
config = get_config
|
122
|
+
if options[:table] then
|
123
|
+
table = TTY::Table.new do |t|
|
124
|
+
t << ["Start Date", "File","Status", "Nb errors", "Nb lines"]
|
125
|
+
t << ['','','','','']
|
126
|
+
LogsRecords::new(label).get_all_records.each do |item|
|
127
|
+
record =item.keys.first
|
128
|
+
value=item[record]
|
129
|
+
|
130
|
+
t << [record, value[:file], value[:status].to_s, value[:errors], value[:lines]]
|
131
|
+
end
|
132
|
+
end
|
133
|
+
if check_unicode_term then
|
134
|
+
puts table.render(:unicode)
|
135
|
+
else
|
136
|
+
puts table.render(:ascii)
|
137
|
+
end
|
138
|
+
|
139
|
+
else
|
140
|
+
LogsRecords::new(label).get_all_records.each do |item|
|
141
|
+
record =item.keys.first
|
142
|
+
value=item[record]
|
143
|
+
log.item record
|
144
|
+
log.arrow "Status : #{value[:status].to_s}"
|
145
|
+
log.arrow "nb files : #{value[:errors]}"
|
146
|
+
log.arrow "nb lines : #{value[:lines]}"
|
147
|
+
end
|
89
148
|
end
|
149
|
+
splash_exit case: :quiet_exit
|
150
|
+
else
|
151
|
+
splash_exit case: :not_root, :more => "Log analysis"
|
90
152
|
end
|
91
|
-
splash_exit case: :quiet_exit
|
92
153
|
end
|
93
154
|
|
94
155
|
end
|
data/lib/splash/cli/process.rb
CHANGED
@@ -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
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
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
|
-
|
38
|
-
|
38
|
+
full_status = false unless result[:status] == :running
|
39
|
+
end
|
39
40
|
|
40
|
-
|
41
|
-
|
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
|
-
|
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
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
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
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
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: :
|
85
|
+
splash_exit case: :not_root, :more => "Process analysis"
|
74
86
|
end
|
75
87
|
end
|
76
88
|
|
@@ -82,20 +94,68 @@ module CLISplash
|
|
82
94
|
LONGDESC
|
83
95
|
option :detail, :type => :boolean, :aliases => "-D"
|
84
96
|
def list
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
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
|
+
|
118
|
+
# Thor method : show logs monitoring history
|
119
|
+
long_desc <<-LONGDESC
|
120
|
+
show Process monitoring history for LABEL\n
|
121
|
+
LONGDESC
|
122
|
+
option :table, :type => :boolean, :aliases => "-t"
|
123
|
+
desc "history PROCESS", "show process monitoring history"
|
124
|
+
def history(process)
|
125
|
+
if is_root? then
|
126
|
+
log = get_logger
|
127
|
+
log.info "Process : #{process}"
|
128
|
+
config = get_config
|
129
|
+
if options[:table] then
|
130
|
+
table = TTY::Table.new do |t|
|
131
|
+
t << ["Start Date", "Status", "CPU Percent", "MEM Percent"]
|
132
|
+
t << ['','','','']
|
133
|
+
ProcessRecords::new(process).get_all_records.each do |item|
|
134
|
+
record =item.keys.first
|
135
|
+
value=item[record]
|
136
|
+
t << [record, value[:status].to_s, value[:cpu_percent], value[:mem_percent]]
|
137
|
+
end
|
138
|
+
end
|
139
|
+
if check_unicode_term then
|
140
|
+
puts table.render(:unicode)
|
141
|
+
else
|
142
|
+
puts table.render(:ascii)
|
143
|
+
end
|
144
|
+
|
145
|
+
else
|
146
|
+
ProcessRecords::new(process).get_all_records.each do |item|
|
147
|
+
record =item.keys.first
|
148
|
+
value=item[record]
|
149
|
+
log.item record
|
150
|
+
log.arrow "Status : #{value[:status].to_s}"
|
151
|
+
log.arrow "CPU Percent : #{value[:cpu_percent]}"
|
152
|
+
log.arrow "MEM Percent : #{value[:mem_percent]}"
|
153
|
+
end
|
154
|
+
end
|
155
|
+
splash_exit case: :quiet_exit
|
156
|
+
else
|
157
|
+
splash_exit case: :not_root, :more => "Process analysis"
|
97
158
|
end
|
98
|
-
splash_exit case: :quiet_exit
|
99
159
|
end
|
100
160
|
|
101
161
|
end
|
data/lib/splash/cli/transfers.rb
CHANGED
@@ -44,7 +44,10 @@ module CLISplash
|
|
44
44
|
log = get_logger
|
45
45
|
log.item "Transfer : #{name}"
|
46
46
|
config = get_config
|
47
|
-
data = TxRecords::new(name).get_all_records.select {|
|
47
|
+
data = TxRecords::new(name).get_all_records.select {|item|
|
48
|
+
record =item.keys.first
|
49
|
+
value=item[record]
|
50
|
+
record == options[:date]}.first
|
48
51
|
if data.nil? then
|
49
52
|
log.ko "Result for #{name} on date #{options[:date]} not found"
|
50
53
|
splash_exit case: :not_found, :more => "Result inexistant"
|
@@ -93,7 +96,9 @@ module CLISplash
|
|
93
96
|
table = TTY::Table.new do |t|
|
94
97
|
t << ["Start Date", "End date", "time", "Files count","File count error","Status"]
|
95
98
|
t << ['','','','','','']
|
96
|
-
TxRecords::new(name).get_all_records.each do |
|
99
|
+
TxRecords::new(name).get_all_records.each do |item|
|
100
|
+
record =item.keys.first
|
101
|
+
value=item[record]
|
97
102
|
start_date = record
|
98
103
|
end_date = (value[:end_date].nil?)? '': value[:end_date]
|
99
104
|
time = (value[:time].nil?)? '': value[:time]
|
@@ -111,7 +116,9 @@ module CLISplash
|
|
111
116
|
end
|
112
117
|
|
113
118
|
else
|
114
|
-
TxRecords::new(name).get_all_records.each do |
|
119
|
+
TxRecords::new(name).get_all_records.each do |item|
|
120
|
+
record =item.keys.first
|
121
|
+
value=item[record]
|
115
122
|
failed = (value[:count].nil? or value[:done].nil?)? 'undef': value[:count].to_i - value[:done].count
|
116
123
|
if value[:end_date].nil? then
|
117
124
|
log.item "Event : #{record} STATUS : #{value[:status]}"
|
data/lib/splash/commands.rb
CHANGED
@@ -6,6 +6,78 @@ module Splash
|
|
6
6
|
# Splash Commands module/namespace
|
7
7
|
module Commands
|
8
8
|
|
9
|
+
|
10
|
+
class CmdNotifier
|
11
|
+
|
12
|
+
@@registry = Prometheus::Client::Registry::new
|
13
|
+
@@metric_exitcode = Prometheus::Client::Gauge.new(:exitcode, docstring: 'SPLASH metric batch exitcode')
|
14
|
+
@@metric_time = Prometheus::Client::Gauge.new(:exectime, docstring: 'SPLASH metric batch execution time')
|
15
|
+
@@registry.register(@@metric_exitcode)
|
16
|
+
@@registry.register(@@metric_time)
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
def initialize(options={})
|
21
|
+
@config = get_config
|
22
|
+
@url = @config.prometheus_pushgateway_url
|
23
|
+
@name = "cmd_#{options[:name].to_s}"
|
24
|
+
@exitcode = options[:exitcode]
|
25
|
+
@time = options[:time]
|
26
|
+
end
|
27
|
+
|
28
|
+
# send metrics to Prometheus PushGateway
|
29
|
+
# @return [Bool]
|
30
|
+
def notify
|
31
|
+
unless verify_service url: @url then
|
32
|
+
return { :case => :service_dependence_missing, :more => "Prometheus Notification not send."}
|
33
|
+
end
|
34
|
+
@@metric_exitcode.set(@exitcode)
|
35
|
+
@@metric_time.set(@time)
|
36
|
+
hostname = Socket.gethostname
|
37
|
+
return Prometheus::Client::Push.new(@name, hostname, @url).add(@@registry)
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
class CmdRecords
|
44
|
+
include Splash::Backends
|
45
|
+
include Splash::Constants
|
46
|
+
def initialize(name)
|
47
|
+
@name = name
|
48
|
+
@backend = get_backend :execution_trace
|
49
|
+
end
|
50
|
+
|
51
|
+
def purge(retention)
|
52
|
+
retention = {} if retention.nil?
|
53
|
+
if retention.include? :hours then
|
54
|
+
adjusted_datetime = DateTime.now - retention[:hours].to_f / 24
|
55
|
+
elsif retention.include? :hours then
|
56
|
+
adjusted_datetime = DateTime.now - retention[:days].to_i
|
57
|
+
else
|
58
|
+
adjusted_datetime = DateTime.now - DEFAULT_RETENTION
|
59
|
+
end
|
60
|
+
|
61
|
+
data = get_all_records
|
62
|
+
|
63
|
+
data.delete_if { |item|
|
64
|
+
DateTime.parse(item.keys.first) <= (adjusted_datetime)}
|
65
|
+
@backend.put key: @name, value: data.to_yaml
|
66
|
+
end
|
67
|
+
|
68
|
+
def add_record(record)
|
69
|
+
data = get_all_records
|
70
|
+
data.push({ DateTime.now.to_s => record })
|
71
|
+
@backend.put key: @name, value: data.to_yaml
|
72
|
+
end
|
73
|
+
|
74
|
+
def get_all_records(options={})
|
75
|
+
return (@backend.exist?({key: @name}))? YAML::load(@backend.get({key: @name})) : []
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
|
9
81
|
# command execution wrapper
|
10
82
|
class CommandWrapper
|
11
83
|
include Splash::Templates
|
@@ -16,11 +88,7 @@ module Splash
|
|
16
88
|
include Splash::Transports
|
17
89
|
|
18
90
|
|
19
|
-
|
20
|
-
@@metric_exitcode = Prometheus::Client::Gauge.new(:errorcode, docstring: 'SPLASH metric batch errorcode')
|
21
|
-
@@metric_time = Prometheus::Client::Gauge.new(:exectime, docstring: 'SPLASH metric batch execution time')
|
22
|
-
@@registry.register(@@metric_exitcode)
|
23
|
-
@@registry.register(@@metric_time)
|
91
|
+
|
24
92
|
|
25
93
|
# Constructor
|
26
94
|
# @param [String] name the name of the command
|
@@ -43,14 +111,17 @@ module Splash
|
|
43
111
|
# @param [String] value numeric.to_s
|
44
112
|
# @param [String] time execution time numeric.to_s
|
45
113
|
# @return [Hash] Exiter case :quiet_exit
|
46
|
-
def notify(value,time)
|
114
|
+
def notify(value,time, session)
|
115
|
+
log = get_logger
|
47
116
|
unless verify_service url: @config.prometheus_pushgateway_url then
|
48
117
|
return { :case => :service_dependence_missing, :more => "Prometheus Notification not send."}
|
49
118
|
end
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
119
|
+
cmdmonitor = CmdNotifier::new({name: @name, exitcode: value, time: time})
|
120
|
+
if cmdmonitor.notify then
|
121
|
+
log.ok "Sending metrics to Prometheus Pushgateway",session
|
122
|
+
else
|
123
|
+
log.ko "Failed to send metrics to Prometheus Pushgateway",session
|
124
|
+
end
|
54
125
|
return { :case => :quiet_exit}
|
55
126
|
end
|
56
127
|
|
@@ -110,9 +181,6 @@ module Splash
|
|
110
181
|
stdout, stderr, status = Open3.capture3(@config.commands[@name.to_sym][:command])
|
111
182
|
end
|
112
183
|
time = Time.now - start
|
113
|
-
tp = Template::new(
|
114
|
-
list_token: @config.execution_template_tokens,
|
115
|
-
template_file: @config.execution_template_path)
|
116
184
|
data = Hash::new
|
117
185
|
data[:start_date] = start_date
|
118
186
|
data[:end_date] = DateTime.now.to_s
|
@@ -123,17 +191,15 @@ module Splash
|
|
123
191
|
data[:stdout] = stdout
|
124
192
|
data[:stderr] = stderr
|
125
193
|
data[:exec_time] = time.to_s
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
backend.put key: key, value: data.to_yaml
|
194
|
+
cmdrec = CmdRecords::new @name
|
195
|
+
cmdrec.purge(@config.commands[@name.to_sym][:retention])
|
196
|
+
cmdrec.add_record data
|
130
197
|
exit_code = status.exitstatus
|
131
198
|
end
|
132
199
|
log.ok "Command executed", session
|
133
200
|
log.arrow "exitcode #{exit_code}", session
|
134
201
|
if options[:notify] then
|
135
|
-
acase = notify(exit_code,time.to_i)
|
136
|
-
get_logger.ok "Prometheus Gateway notified.",session
|
202
|
+
acase = notify(exit_code,time.to_i,session)
|
137
203
|
else
|
138
204
|
log.item "Without Prometheus notification", session
|
139
205
|
end
|
data/lib/splash/constants.rb
CHANGED
@@ -7,7 +7,7 @@ module Splash
|
|
7
7
|
module Constants
|
8
8
|
|
9
9
|
# Current splash version
|
10
|
-
VERSION = "0.8.
|
10
|
+
VERSION = "0.8.1"
|
11
11
|
|
12
12
|
# the path to th config file, not overridable by config
|
13
13
|
CONFIG_FILE = "/etc/splash.yml"
|
@@ -87,8 +87,8 @@ module Splash
|
|
87
87
|
# the default sdterr trace file
|
88
88
|
WEBADMIN_STDERR_TRACE="stderr.txt"
|
89
89
|
|
90
|
-
# default
|
91
|
-
|
90
|
+
# default retention for trace
|
91
|
+
DEFAULT_RETENTION=1
|
92
92
|
|
93
93
|
end
|
94
94
|
end
|
data/lib/splash/logs.rb
CHANGED
@@ -6,6 +6,79 @@ module Splash
|
|
6
6
|
# Logs namespace
|
7
7
|
module Logs
|
8
8
|
|
9
|
+
class LogsNotifier
|
10
|
+
|
11
|
+
@@registry = Prometheus::Client::Registry::new
|
12
|
+
@@metric_missing = Prometheus::Client::Gauge.new(:logmissing, docstring: 'SPLASH metric log missing', labels: [:log ])
|
13
|
+
@@metric_count = Prometheus::Client::Gauge.new(:logerrors, docstring: 'SPLASH metric log error', labels: [:log ])
|
14
|
+
@@metric_lines = Prometheus::Client::Gauge.new(:loglines, docstring: 'SPLASH metric log lines numbers', labels: [:log ])
|
15
|
+
@@registry.register(@@metric_count)
|
16
|
+
@@registry.register(@@metric_missing)
|
17
|
+
@@registry.register(@@metric_lines)
|
18
|
+
|
19
|
+
def initialize(options={})
|
20
|
+
@config = get_config
|
21
|
+
@url = @config.prometheus_pushgateway_url
|
22
|
+
@name = options[:name]
|
23
|
+
@missing = options[:missing]
|
24
|
+
@lines = options[:lines]
|
25
|
+
@errors = options[:errors]
|
26
|
+
end
|
27
|
+
|
28
|
+
# send metrics to Prometheus PushGateway
|
29
|
+
# @return [Bool]
|
30
|
+
def notify
|
31
|
+
unless verify_service url: @url then
|
32
|
+
return { :case => :service_dependence_missing, :more => "Prometheus Notification not send."}
|
33
|
+
end
|
34
|
+
@@metric_missing.set(@missing, labels: { log: @name })
|
35
|
+
@@metric_count.set(@errors, labels: { log: @name })
|
36
|
+
@@metric_lines.set(@lines, labels: { log: @name })
|
37
|
+
hostname = Socket.gethostname
|
38
|
+
return Prometheus::Client::Push.new("Splash", hostname, @url).add(@@registry)
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
class LogsRecords
|
44
|
+
include Splash::Backends
|
45
|
+
include Splash::Constants
|
46
|
+
def initialize(name)
|
47
|
+
@name = name
|
48
|
+
@backend = get_backend :logs_trace
|
49
|
+
end
|
50
|
+
|
51
|
+
def purge(retention)
|
52
|
+
retention = {} if retention.nil?
|
53
|
+
if retention.include? :hours then
|
54
|
+
adjusted_datetime = DateTime.now - retention[:hours].to_f / 24
|
55
|
+
elsif retention.include? :hours then
|
56
|
+
adjusted_datetime = DateTime.now - retention[:days].to_i
|
57
|
+
else
|
58
|
+
adjusted_datetime = DateTime.now - DEFAULT_RETENTION
|
59
|
+
end
|
60
|
+
|
61
|
+
data = get_all_records
|
62
|
+
|
63
|
+
data.delete_if { |item|
|
64
|
+
DateTime.parse(item.keys.first) <= (adjusted_datetime)}
|
65
|
+
@backend.put key: @name, value: data.to_yaml
|
66
|
+
end
|
67
|
+
|
68
|
+
def add_record(record)
|
69
|
+
data = get_all_records
|
70
|
+
data.push({ DateTime.now.to_s => record })
|
71
|
+
@backend.put key: @name, value: data.to_yaml
|
72
|
+
end
|
73
|
+
|
74
|
+
def get_all_records(options={})
|
75
|
+
return (@backend.exist?({key: @name}))? YAML::load(@backend.get({key: @name})) : []
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
|
81
|
+
|
9
82
|
# Log scanner and notifier
|
10
83
|
class LogScanner
|
11
84
|
include Splash::Constants
|
@@ -17,13 +90,7 @@ module Splash
|
|
17
90
|
def initialize
|
18
91
|
@logs_target = Marshal.load(Marshal.dump(get_config.logs))
|
19
92
|
@config = get_config
|
20
|
-
|
21
|
-
@metric_count = Prometheus::Client::Gauge.new(:logerrors, docstring: 'SPLASH metric log error', labels: [:log ])
|
22
|
-
@metric_missing = Prometheus::Client::Gauge.new(:logmissing, docstring: 'SPLASH metric log missing', labels: [:log ])
|
23
|
-
@metric_lines = Prometheus::Client::Gauge.new(:loglines, docstring: 'SPLASH metric log lines numbers', labels: [:log ])
|
24
|
-
@registry.register(@metric_count)
|
25
|
-
@registry.register(@metric_missing)
|
26
|
-
@registry.register(@metric_lines)
|
93
|
+
|
27
94
|
end
|
28
95
|
|
29
96
|
|
@@ -62,17 +129,24 @@ module Splash
|
|
62
129
|
session = (options[:session]) ? options[:session] : log.get_session
|
63
130
|
log.info "Sending metrics to Prometheus Pushgateway", session
|
64
131
|
@logs_target.each do |item|
|
65
|
-
|
66
|
-
|
67
|
-
@metric_count.set(item[:count], labels: { log: item[:log] })
|
68
|
-
@metric_missing.set(missing, labels: { log: item[:log] })
|
132
|
+
logsrec = LogsRecords::new item[:label]
|
133
|
+
errors = (item[:count])? item[:count] : 0
|
69
134
|
lines = (item[:lines])? item[:lines] : 0
|
70
|
-
|
135
|
+
missing = (item[:status] = :missing)? 1 : 0
|
136
|
+
file = item[:log]
|
137
|
+
logsrec.purge(item[:retention])
|
138
|
+
logsrec.add_record :status => item[:status],
|
139
|
+
:errors => errors,
|
140
|
+
:lines => lines,
|
141
|
+
:file => file
|
142
|
+
|
143
|
+
logsmonitor = LogsNotifier::new({name: item[:label], missing: missing, file: file, errors: errors, lines: lines})
|
144
|
+
if logsmonitor.notify then
|
145
|
+
log.ok "Sending metrics for log #{file} to Prometheus Pushgateway", session
|
146
|
+
else
|
147
|
+
log.ko "Failed to send metrics for log #{file} to Prometheus Pushgateway", session
|
148
|
+
end
|
71
149
|
end
|
72
|
-
hostname = Socket.gethostname
|
73
|
-
url = @config.prometheus_pushgateway_url
|
74
|
-
Prometheus::Client::Push.new('Splash',hostname, url).add(@registry)
|
75
|
-
log.ok "Sending to Prometheus PushGateway done.", session
|
76
150
|
return {:case => :quiet_exit }
|
77
151
|
end
|
78
152
|
|
data/lib/splash/processes.rb
CHANGED
@@ -6,6 +6,81 @@ module Splash
|
|
6
6
|
# Processes namespace
|
7
7
|
module Processes
|
8
8
|
|
9
|
+
|
10
|
+
class ProcessNotifier
|
11
|
+
|
12
|
+
@@registry = Prometheus::Client::Registry::new
|
13
|
+
@@metric_status = Prometheus::Client::Gauge.new(:process_status, docstring: 'SPLASH metric process status', labels: [:process ])
|
14
|
+
@@metric_cpu_percent = Prometheus::Client::Gauge.new(:process_cpu_percent, docstring: 'SPLASH metric process CPU usage in percent', labels: [:process ])
|
15
|
+
@@metric_mem_percent = Prometheus::Client::Gauge.new(:process_mem_percent, docstring: 'SPLASH metric process MEM usage in percent', labels: [:process ])
|
16
|
+
@@registry.register(@@metric_status)
|
17
|
+
@@registry.register(@@metric_cpu_percent)
|
18
|
+
@@registry.register(@@metric_mem_percent)
|
19
|
+
|
20
|
+
|
21
|
+
def initialize(options={})
|
22
|
+
@config = get_config
|
23
|
+
@url = @config.prometheus_pushgateway_url
|
24
|
+
@name = options[:name]
|
25
|
+
@status = options[:status]
|
26
|
+
@cpu_percent = options[:cpu_percent]
|
27
|
+
@mem_percent = options[:mem_percent]
|
28
|
+
end
|
29
|
+
|
30
|
+
# send metrics to Prometheus PushGateway
|
31
|
+
# @return [Bool]
|
32
|
+
def notify
|
33
|
+
unless verify_service url: @url then
|
34
|
+
return { :case => :service_dependence_missing, :more => "Prometheus Notification not send."}
|
35
|
+
end
|
36
|
+
@@metric_mem_percent.set(@mem_percent, labels: { process: @name })
|
37
|
+
@@metric_cpu_percent.set(@cpu_percent, labels: { process: @name })
|
38
|
+
@@metric_status.set(@status, labels: { process: @name })
|
39
|
+
hostname = Socket.gethostname
|
40
|
+
return Prometheus::Client::Push.new("Splash", hostname, @url).add(@@registry)
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
class ProcessRecords
|
47
|
+
include Splash::Backends
|
48
|
+
include Splash::Constants
|
49
|
+
|
50
|
+
def initialize(name)
|
51
|
+
@name = name
|
52
|
+
@backend = get_backend :process_trace
|
53
|
+
end
|
54
|
+
|
55
|
+
def purge(retention)
|
56
|
+
retention = {} if retention.nil?
|
57
|
+
if retention.include? :hours then
|
58
|
+
adjusted_datetime = DateTime.now - retention[:hours].to_f / 24
|
59
|
+
elsif retention.include? :hours then
|
60
|
+
adjusted_datetime = DateTime.now - retention[:days].to_i
|
61
|
+
else
|
62
|
+
adjusted_datetime = DateTime.now - DEFAULT_RETENTION
|
63
|
+
end
|
64
|
+
|
65
|
+
data = get_all_records
|
66
|
+
|
67
|
+
data.delete_if { |item|
|
68
|
+
DateTime.parse(item.keys.first) <= (adjusted_datetime)}
|
69
|
+
@backend.put key: @name, value: data.to_yaml
|
70
|
+
end
|
71
|
+
|
72
|
+
def add_record(record)
|
73
|
+
data = get_all_records
|
74
|
+
data.push({ DateTime.now.to_s => record })
|
75
|
+
@backend.put key: @name, value: data.to_yaml
|
76
|
+
end
|
77
|
+
|
78
|
+
def get_all_records(options={})
|
79
|
+
return (@backend.exist?({key: @name}))? YAML::load(@backend.get({key: @name})) : []
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
|
9
84
|
# Processes scanner and notifier
|
10
85
|
class ProcessScanner
|
11
86
|
include Splash::Constants
|
@@ -17,14 +92,6 @@ module Splash
|
|
17
92
|
def initialize
|
18
93
|
@processes_target = Marshal.load(Marshal.dump(get_config.processes))
|
19
94
|
@config = get_config
|
20
|
-
@registry = Prometheus::Client::Registry::new
|
21
|
-
@metric_status = Prometheus::Client::Gauge.new(:process_status, docstring: 'SPLASH metric process status', labels: [:process ])
|
22
|
-
@metric_cpu_percent = Prometheus::Client::Gauge.new(:process_cpu_percent, docstring: 'SPLASH metric process CPU usage in percent', labels: [:process ])
|
23
|
-
@metric_mem_percent = Prometheus::Client::Gauge.new(:process_mem_percent, docstring: 'SPLASH metric process MEM usage in percent', labels: [:process ])
|
24
|
-
@registry.register(@metric_status)
|
25
|
-
@registry.register(@metric_cpu_percent)
|
26
|
-
@registry.register(@metric_mem_percent)
|
27
|
-
|
28
95
|
end
|
29
96
|
|
30
97
|
|
@@ -64,17 +131,21 @@ module Splash
|
|
64
131
|
session = (options[:session]) ? options[:session] : log.get_session
|
65
132
|
log.info "Sending metrics to Prometheus Pushgateway", session
|
66
133
|
@processes_target.each do |item|
|
134
|
+
processrec = ProcessRecords::new item[:process]
|
67
135
|
missing = (item[:status] == :missing)? 1 : 0
|
68
|
-
log.item "Sending metrics for #{item[:process]}", session
|
69
136
|
val = (item[:status] == :running )? 1 : 0
|
70
|
-
|
71
|
-
|
72
|
-
|
137
|
+
processrec.purge(item[:retention])
|
138
|
+
processrec.add_record :status => item[:status],
|
139
|
+
:cpu_percent => item[:cpu],
|
140
|
+
:mem_percent => item[:mem] ,
|
141
|
+
:process => item[:process]
|
142
|
+
processmonitor = ProcessNotifier::new({name: item[:process], status: val , cpu_percent: item[:cpu], mem_percent: item[:mem]})
|
143
|
+
if processmonitor.notify then
|
144
|
+
log.ok "Sending metrics for process #{item[:process]} to Prometheus Pushgateway", session
|
145
|
+
else
|
146
|
+
log.ko "Failed to send metrics for process #{item[:process]} to Prometheus Pushgateway", session
|
147
|
+
end
|
73
148
|
end
|
74
|
-
hostname = Socket.gethostname
|
75
|
-
url = @config.prometheus_pushgateway_url
|
76
|
-
Prometheus::Client::Push.new('Splash',hostname, url).add(@registry)
|
77
|
-
log.ok "Sending to Prometheus PushGateway done.", session
|
78
149
|
return {:case => :quiet_exit }
|
79
150
|
end
|
80
151
|
|
data/lib/splash/transfers.rb
CHANGED
@@ -49,40 +49,45 @@ module Splash
|
|
49
49
|
|
50
50
|
class TxRecords
|
51
51
|
include Splash::Backends
|
52
|
+
include Splash::Constants
|
53
|
+
|
52
54
|
def initialize(name)
|
53
55
|
@name = name
|
54
|
-
@backend = get_backend :
|
56
|
+
@backend = get_backend :transfers_trace
|
55
57
|
end
|
56
58
|
|
57
59
|
def purge(retention)
|
60
|
+
retention = {} if retention.nil?
|
58
61
|
if retention.include? :hours then
|
59
62
|
adjusted_datetime = DateTime.now - retention[:hours].to_f / 24
|
60
63
|
elsif retention.include? :hours then
|
61
64
|
adjusted_datetime = DateTime.now - retention[:days].to_i
|
62
65
|
else
|
63
|
-
|
66
|
+
adjusted_datetime = DateTime.now - DEFAULT_RETENTION
|
64
67
|
end
|
65
68
|
|
66
69
|
data = get_all_records
|
67
70
|
|
68
|
-
data.delete_if { |item
|
69
|
-
DateTime.parse(item) <= (adjusted_datetime)
|
71
|
+
data.delete_if { |item|
|
72
|
+
DateTime.parse(item.keys.first) <= (adjusted_datetime)}
|
70
73
|
@backend.put key: @name, value: data.to_yaml
|
71
74
|
end
|
72
75
|
|
73
76
|
def add_record(record)
|
74
77
|
data = get_all_records
|
75
|
-
data
|
78
|
+
data.push({ DateTime.now.to_s => record })
|
76
79
|
@backend.put key: @name, value: data.to_yaml
|
77
80
|
end
|
78
81
|
|
79
|
-
def get_all_records
|
80
|
-
return (@backend.exist?({key: @name}))? YAML::load(@backend.get({key: @name})) :
|
82
|
+
def get_all_records(options={})
|
83
|
+
return (@backend.exist?({key: @name}))? YAML::load(@backend.get({key: @name})) : []
|
81
84
|
end
|
82
85
|
|
83
86
|
def check_prepared
|
84
87
|
return :never_run_prepare unless @backend.exist?({key: @name})
|
85
|
-
return :never_prepare unless YAML::load(@backend.get({key: @name})).select {|item
|
88
|
+
return :never_prepare unless YAML::load(@backend.get({key: @name})).select {|item|
|
89
|
+
record =item.keys.first
|
90
|
+
value=item[record]
|
86
91
|
value[:status] == :prepared
|
87
92
|
}.count > 0
|
88
93
|
return :prepared
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: prometheus-splash
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Romain GEORGES
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-10-
|
11
|
+
date: 2020-10-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -508,7 +508,7 @@ homepage: https://github.com/Ultragreen/prometheus-splash
|
|
508
508
|
licenses:
|
509
509
|
- BSD-2-Clause
|
510
510
|
metadata: {}
|
511
|
-
post_install_message:
|
511
|
+
post_install_message:
|
512
512
|
rdoc_options: []
|
513
513
|
require_paths:
|
514
514
|
- lib
|
@@ -523,8 +523,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
523
523
|
- !ruby/object:Gem::Version
|
524
524
|
version: '0'
|
525
525
|
requirements: []
|
526
|
-
rubygems_version: 3.
|
527
|
-
signing_key:
|
526
|
+
rubygems_version: 3.0.6
|
527
|
+
signing_key:
|
528
528
|
specification_version: 4
|
529
529
|
summary: Supervision with Prometheus of Logs and Asynchronous tasks orchestration
|
530
530
|
for Services or Hosts
|