prometheus-splash 0.6.1 → 0.8.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +43 -1
- data/README.md +1 -1
- data/config/splash.yml +45 -5
- data/lib/splash/backends.rb +1 -0
- data/lib/splash/cli.rb +2 -1
- data/lib/splash/cli/commands.rb +125 -5
- data/lib/splash/cli/daemon.rb +41 -1
- data/lib/splash/cli/logs.rb +111 -47
- data/lib/splash/cli/process.rb +112 -52
- data/lib/splash/cli/sequences.rb +2 -0
- data/lib/splash/cli/transfers.rb +213 -0
- data/lib/splash/cli/webadmin.rb +3 -3
- data/lib/splash/commands.rb +85 -19
- data/lib/splash/config.rb +142 -52
- data/lib/splash/constants.rb +7 -3
- data/lib/splash/daemon/metrics.rb +6 -6
- data/lib/splash/daemon/orchestrator.rb +76 -36
- data/lib/splash/daemon/orchestrator/grammar.rb +16 -1
- data/lib/splash/dependencies.rb +6 -1
- data/lib/splash/exiter.rb +1 -1
- data/lib/splash/helpers.rb +12 -3
- data/lib/splash/loggers/cli.rb +2 -10
- data/lib/splash/logs.rb +90 -16
- data/lib/splash/processes.rb +87 -16
- data/lib/splash/transfers.rb +229 -0
- data/lib/splash/webadmin.rb +3 -3
- data/lib/splash/webadmin/api/routes/commands.rb +2 -2
- data/lib/splash/webadmin/api/routes/config.rb +53 -2
- data/lib/splash/webadmin/api/routes/logs.rb +32 -17
- data/lib/splash/webadmin/api/routes/process.rb +4 -4
- data/lib/splash/webadmin/api/routes/sequences.rb +28 -0
- data/lib/splash/webadmin/main.rb +1 -0
- data/lib/splash/webadmin/portal/controllers/commands.rb +2 -0
- data/lib/splash/webadmin/portal/controllers/documentation.rb +3 -1
- data/lib/splash/webadmin/portal/controllers/home.rb +24 -0
- data/lib/splash/webadmin/portal/controllers/logs.rb +44 -1
- data/lib/splash/webadmin/portal/controllers/processes.rb +2 -0
- data/lib/splash/webadmin/portal/controllers/proxy.rb +13 -4
- data/lib/splash/webadmin/portal/controllers/restclient.rb +7 -2
- data/lib/splash/webadmin/portal/controllers/sequences.rb +9 -0
- data/lib/splash/webadmin/portal/init.rb +2 -2
- data/lib/splash/webadmin/portal/public/css/ultragreen.css +6 -0
- data/lib/splash/webadmin/portal/public/favicon.ico +0 -0
- data/lib/splash/webadmin/portal/views/commands.slim +1 -1
- data/lib/splash/webadmin/portal/views/documentation.slim +1 -1
- data/lib/splash/webadmin/portal/views/home.slim +53 -9
- data/lib/splash/webadmin/portal/views/layout.slim +2 -2
- data/lib/splash/webadmin/portal/views/logs.slim +68 -21
- data/lib/splash/webadmin/portal/views/logs_form.slim +24 -0
- data/lib/splash/webadmin/portal/views/nav.slim +1 -1
- data/lib/splash/webadmin/portal/views/not_found.slim +1 -1
- data/lib/splash/webadmin/portal/views/processes.slim +1 -1
- data/lib/splash/webadmin/portal/views/proxy.slim +5 -2
- data/lib/splash/webadmin/portal/views/restclient.slim +7 -4
- data/lib/splash/webadmin/portal/views/restclient_result.slim +24 -20
- data/lib/splash/webadmin/portal/views/sequences.slim +50 -0
- data/prometheus-splash.gemspec +7 -4
- data/ultragreen_roodi_coding_convention.yml +4 -4
- metadata +75 -12
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/sequences.rb
CHANGED
@@ -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
|
data/lib/splash/cli/webadmin.rb
CHANGED
@@ -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 :
|
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 :
|
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 :
|
40
|
+
acase = run_as_root :startweb
|
41
41
|
splash_exit acase
|
42
42
|
end
|
43
43
|
|
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
|