prometheus-splash 0.6.0 → 0.8.2

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.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +38 -1
  3. data/README.md +1 -1
  4. data/config/splash.yml +97 -11
  5. data/lib/splash/backends.rb +1 -0
  6. data/lib/splash/cli.rb +4 -1
  7. data/lib/splash/cli/commands.rb +127 -7
  8. data/lib/splash/cli/daemon.rb +41 -1
  9. data/lib/splash/cli/logs.rb +111 -47
  10. data/lib/splash/cli/process.rb +112 -52
  11. data/lib/splash/cli/sequences.rb +114 -0
  12. data/lib/splash/cli/transfers.rb +213 -0
  13. data/lib/splash/cli/webadmin.rb +3 -3
  14. data/lib/splash/commands.rb +89 -22
  15. data/lib/splash/config.rb +149 -62
  16. data/lib/splash/config/sanitycheck.rb +1 -1
  17. data/lib/splash/constants.rb +11 -11
  18. data/lib/splash/daemon/controller.rb +10 -10
  19. data/lib/splash/daemon/metrics.rb +8 -8
  20. data/lib/splash/daemon/orchestrator.rb +96 -35
  21. data/lib/splash/daemon/orchestrator/grammar.rb +16 -1
  22. data/lib/splash/dependencies.rb +8 -0
  23. data/lib/splash/exiter.rb +1 -1
  24. data/lib/splash/helpers.rb +22 -4
  25. data/lib/splash/loggers/cli.rb +2 -10
  26. data/lib/splash/logs.rb +91 -17
  27. data/lib/splash/processes.rb +88 -17
  28. data/lib/splash/sequences.rb +105 -0
  29. data/lib/splash/transfers.rb +229 -0
  30. data/lib/splash/transports/rabbitmq.rb +0 -1
  31. data/lib/splash/webadmin.rb +4 -4
  32. data/lib/splash/webadmin/api/routes/commands.rb +2 -2
  33. data/lib/splash/webadmin/api/routes/config.rb +53 -2
  34. data/lib/splash/webadmin/api/routes/logs.rb +32 -17
  35. data/lib/splash/webadmin/api/routes/process.rb +4 -4
  36. data/lib/splash/webadmin/api/routes/sequences.rb +28 -0
  37. data/lib/splash/webadmin/main.rb +3 -2
  38. data/lib/splash/webadmin/portal/controllers/commands.rb +2 -0
  39. data/lib/splash/webadmin/portal/controllers/documentation.rb +3 -1
  40. data/lib/splash/webadmin/portal/controllers/home.rb +24 -0
  41. data/lib/splash/webadmin/portal/controllers/logs.rb +44 -1
  42. data/lib/splash/webadmin/portal/controllers/processes.rb +2 -0
  43. data/lib/splash/webadmin/portal/controllers/proxy.rb +15 -8
  44. data/lib/splash/webadmin/portal/controllers/restclient.rb +7 -2
  45. data/lib/splash/webadmin/portal/controllers/sequences.rb +9 -0
  46. data/lib/splash/webadmin/portal/init.rb +2 -2
  47. data/lib/splash/webadmin/portal/public/css/ultragreen.css +6 -0
  48. data/lib/splash/webadmin/portal/public/favicon.ico +0 -0
  49. data/lib/splash/webadmin/portal/views/commands.slim +1 -1
  50. data/lib/splash/webadmin/portal/views/documentation.slim +1 -1
  51. data/lib/splash/webadmin/portal/views/home.slim +53 -9
  52. data/lib/splash/webadmin/portal/views/layout.slim +2 -2
  53. data/lib/splash/webadmin/portal/views/logs.slim +68 -21
  54. data/lib/splash/webadmin/portal/views/logs_form.slim +24 -0
  55. data/lib/splash/webadmin/portal/views/nav.slim +1 -1
  56. data/lib/splash/webadmin/portal/views/not_found.slim +1 -1
  57. data/lib/splash/webadmin/portal/views/processes.slim +1 -1
  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 +50 -0
  62. data/prometheus-splash.gemspec +5 -2
  63. metadata +69 -4
@@ -50,7 +50,7 @@ module Splash
50
50
  end
51
51
 
52
52
  target = "Prometheus PushGateway Service running"
53
- if verify_service host: config.prometheus_pushgateway_host ,port: config.prometheus_pushgateway_port then
53
+ if verify_service url: config.prometheus_pushgateway_url then
54
54
  log.ok target
55
55
  else
56
56
  log.ko target
@@ -7,12 +7,13 @@ module Splash
7
7
  module Constants
8
8
 
9
9
  # Current splash version
10
- VERSION = "0.6.0"
11
-
10
+ VERSION = "0.8.2"
12
11
  # the path to th config file, not overridable by config
13
12
  CONFIG_FILE = "/etc/splash.yml"
14
13
  # the default execution trace_path if backend file
15
14
  TRACE_PATH="/var/run/splash"
15
+ # the default pid file path
16
+ PID_PATH="/var/run"
16
17
 
17
18
 
18
19
  # default scheduling criteria for log monitoring
@@ -24,8 +25,6 @@ module Splash
24
25
 
25
26
  # the display name of daemon in proc info (ps/top)
26
27
  DAEMON_PROCESS_NAME="Splash : daemon."
27
- # the default pid file path
28
- DAEMON_PID_PATH="/var/run"
29
28
  # the default pid file name
30
29
  DAEMON_PID_FILE="splash.pid"
31
30
  # the default sdtout trace file
@@ -42,15 +41,14 @@ module Splash
42
41
  # type of licence
43
42
  LICENSE="BSD-2-Clause"
44
43
 
45
- # the default prometheus pushgateway host
46
- PROMETHEUS_PUSHGATEWAY_HOST = "localhost"
47
- # the default prometheus pushgateway port
48
- PROMETHEUS_PUSHGATEWAY_PORT = "9091"
49
- # the default prometheus pushgateway port
50
- PROMETHEUS_PUSHGATEWAY_PATH = ''
44
+ # the default prometheus pushgateway URL
45
+ PROMETHEUS_PUSHGATEWAY_URL = 'http://localhost:9091/'
46
+
47
+ # the default prometheus Alertmanager URL
48
+ PROMETHEUS_ALERTMANAGER_URL = 'http://localhost:9092/'
51
49
 
52
50
  # the default prometheus URL
53
- PROMETHEUS_URL = "http://localhost:9090"
51
+ PROMETHEUS_URL = "http://localhost:9090/"
54
52
 
55
53
  # the default path fo execution report template
56
54
  EXECUTION_TEMPLATE="/etc/splash_execution_report.tpl"
@@ -88,6 +86,8 @@ module Splash
88
86
  # the default sdterr trace file
89
87
  WEBADMIN_STDERR_TRACE="stderr.txt"
90
88
 
89
+ # default retention for trace
90
+ DEFAULT_RETENTION=1
91
91
 
92
92
  end
93
93
  end
@@ -26,7 +26,7 @@ module Splash
26
26
  config = get_config
27
27
  log = get_logger
28
28
  log.level = :fatal if options[:quiet]
29
- unless verify_service host: config.prometheus_pushgateway_host ,port: config.prometheus_pushgateway_port then
29
+ unless verify_service url: config.prometheus_pushgateway_url then
30
30
  return {:case => :service_dependence_missing, :more => 'Prometheus Gateway'}
31
31
  end
32
32
  realpid = get_processes pattern: get_config.daemon_process_name
@@ -35,7 +35,7 @@ module Splash
35
35
  return {:case => :already_exist, :more => "Splash Process already launched on foreground "}
36
36
  end
37
37
 
38
- unless File::exist? config.full_pid_path then
38
+ unless File::exist? config.daemon_full_pid_path then
39
39
  unless realpid.empty? then
40
40
  return {:case => :already_exist, :more => "Splash Process already launched "}
41
41
  end
@@ -50,9 +50,9 @@ module Splash
50
50
  end
51
51
  end
52
52
  daemon_config = {:description => config.daemon_process_name,
53
- :pid_file => config.full_pid_path,
54
- :stdout_trace => config.full_stdout_trace_path,
55
- :stderr_trace => config.full_stderr_trace_path,
53
+ :pid_file => config.daemon_full_pid_path,
54
+ :stdout_trace => config.daemon_full_stdout_trace_path,
55
+ :stderr_trace => config.daemon_full_stderr_trace_path,
56
56
  :foreground => options[:foreground]
57
57
  }
58
58
 
@@ -62,7 +62,7 @@ module Splash
62
62
  end
63
63
  sleep 1
64
64
  if res == 0 then
65
- pid = `cat #{config.full_pid_path}`.to_i
65
+ pid = `cat #{config.daemon_full_pid_path}`.to_i
66
66
  log.ok "Splash Daemon Started, with PID : #{pid}"
67
67
  return {:case => :quiet_exit, :more => "Splash Daemon successfully loaded."}
68
68
  else
@@ -82,15 +82,15 @@ module Splash
82
82
  config = get_config
83
83
  log = get_logger
84
84
  log.level = :fatal if options[:quiet]
85
- if File.exist?(config.full_pid_path) then
85
+ if File.exist?(config.daemon_full_pid_path) then
86
86
  begin
87
- pid = `cat #{config.full_pid_path}`.to_i
87
+ pid = `cat #{config.daemon_full_pid_path}`.to_i
88
88
  Process.kill("TERM", pid)
89
89
  acase = {:case => :quiet_exit, :more => 'Splash stopped succesfully'}
90
90
  rescue Errno::ESRCH
91
91
  acase = {:case => :not_found, :more => "Process of PID : #{pid} not found"}
92
92
  end
93
- FileUtils::rm config.full_pid_path if File::exist? config.full_pid_path
93
+ FileUtils::rm config.daemon_full_pid_path if File::exist? config.daemon_full_pid_path
94
94
  else
95
95
  acase = {:case => :not_found, :more => "Splash is not running"}
96
96
  end
@@ -104,7 +104,7 @@ module Splash
104
104
  log = get_logger
105
105
  config = get_config
106
106
  pid = realpid = ''
107
- pid = `cat #{config.full_pid_path}`.to_s if File.exist?(config.full_pid_path)
107
+ pid = `cat #{config.daemon_full_pid_path}`.to_s if File.exist?(config.daemon_full_pid_path)
108
108
  listpid = get_processes({ :pattern => get_config.daemon_process_name})
109
109
  pid.chomp!
110
110
  if listpid.empty? then
@@ -17,8 +17,8 @@ module Splash
17
17
 
18
18
  # metrics manager factory
19
19
  # @return [Splash::Daemon::Metrics::Manager]
20
- def get_metrics_manager
21
- return @@manager ||= Manager::new
20
+ def get_metrics_manager(session)
21
+ return @@manager ||= Manager::new(:session => session)
22
22
  end
23
23
 
24
24
  # Metrics Manager (collect and sending to Prometheus)
@@ -32,7 +32,8 @@ module Splash
32
32
  attr_reader :monitoring_processes_count
33
33
 
34
34
  # Constructor prepare prometheus-client, defined metrics and init attributes
35
- def initialize
35
+ def initialize(options ={})
36
+ @session = options[:session]
36
37
  @config = get_config
37
38
  @starttime = Time.now
38
39
  @execution_count = 0
@@ -75,21 +76,20 @@ module Splash
75
76
  # @return [Hash] Exiter case ( :service_dependence_missing , :quiet_exit)
76
77
  def notify
77
78
  log = get_logger
78
- session = get_session
79
- unless verify_service host: @config.prometheus_pushgateway_host ,port: @config.prometheus_pushgateway_port then
79
+ unless verify_service url: @config.prometheus_pushgateway_url then
80
80
  return { :case => :service_dependence_missing, :more => "Prometheus Notification not send." }
81
81
  end
82
82
 
83
- log.debug "Sending Splash self metrics to PushGateway." , session
83
+ log.ok "Sending Splash self metrics to PushGateway." , @session
84
84
  @metric_uptime.set uptime
85
85
  @metric_execution.set execution_count
86
86
  @metric_logs_monitoring.set monitoring_logs_count
87
87
  @metric_processes_monitoring.set monitoring_processes_count
88
88
 
89
89
  hostname = Socket.gethostname
90
- url = "http://#{@config.prometheus_pushgateway_host}:#{@config.prometheus_pushgateway_port}/#{@config.prometheus_pushgateway_path}"
90
+ url = @config.prometheus_pushgateway_url
91
91
  Prometheus::Client::Push.new('Splash',hostname, url).add(@registry)
92
- log.debug "Sending to Prometheus PushGateway done.", session
92
+ log.debug "Sending to Prometheus PushGateway done.", @session
93
93
  return {:case => :quiet_exit }
94
94
  end
95
95
 
@@ -21,6 +21,7 @@ module Splash
21
21
  include Splash::Logs
22
22
  include Splash::Processes
23
23
  include Splash::Commands
24
+ include Splash::Sequences
24
25
 
25
26
  # Constructor prepare the Scheduler
26
27
  # commands Schedules
@@ -31,19 +32,69 @@ module Splash
31
32
  def initialize(options = {})
32
33
  @log = get_logger
33
34
  self.extend Splash::Daemon::Metrics
34
- @metric_manager = get_metrics_manager
35
+ @session = get_session
36
+ @metric_manager = get_metrics_manager(@session)
35
37
  $stdout.sync = true
36
38
  $stderr.sync = true
37
39
  @server = Rufus::Scheduler::new
38
40
  @server.extend SchedulerHooks
39
41
  @config = get_config
42
+ @scheduling = options[:scheduling]
40
43
 
41
44
  @log.info "Splash Orchestrator starting :"
42
- if options[:scheduling] then
43
- @log.item "Initializing commands Scheduling."
45
+ if @scheduling then
46
+ @log.item "Initializing Sequences & commands Scheduling."
44
47
  init_commands_scheduling
48
+ init_sequences_scheduling
45
49
  end
46
50
 
51
+ init_logs_monitoring_scheduling
52
+ init_process_monitoring_scheduling
53
+ init_metrics_scheduling
54
+ init_daemon_subscriber
55
+
56
+ end
57
+
58
+
59
+
60
+
61
+
62
+ # Stop the Splash daemon gracefully
63
+ # @return [hash] Exiter Case :quiet_exit
64
+ def terminate
65
+ @log.info "Splash daemon shutdown"
66
+ @server.shutdown
67
+ change_logger logger: :cli
68
+ splash_exit case: :quiet_exit
69
+ end
70
+
71
+ private
72
+
73
+ #prepare main daemon subscriber
74
+ def init_daemon_subscriber
75
+ hostname = Socket.gethostname
76
+ transport = get_default_subscriber queue: "splash.#{hostname}.input"
77
+ if transport.class == Hash and transport.include? :case then
78
+ splash_exit transport
79
+ end
80
+ transport.subscribe(:block => true) do |delivery_info, properties, body|
81
+ content = YAML::load(body)
82
+ session = get_session
83
+ content[:session] = session
84
+ if VERBS.include? content[:verb]
85
+ @log.receive "Valid remote order, verb : #{content[:verb].to_s}", session
86
+ res = self.send content[:verb], content
87
+ get_default_client.publish queue: content[:return_to], message: res.to_yaml
88
+ @log.send "Result to #{content[:return_to]}.", session
89
+ else
90
+ @log.receive "INVALID remote order, verb : #{content[:verb].to_s}", session
91
+ get_default_client.publish queue: content[:return_to], message: "Unkown verb #{content[:verb]}".to_yaml
92
+ end
93
+ end
94
+ end
95
+
96
+ #prepare logs monitoring sheduling
97
+ def init_logs_monitoring_scheduling
47
98
  if @config.logs.empty? then
48
99
  @log.item "No logs to monitor"
49
100
  else
@@ -62,7 +113,10 @@ module Splash
62
113
  end
63
114
  end
64
115
  end
116
+ end
65
117
 
118
+ #prepare process monitoring sheduling
119
+ def init_process_monitoring_scheduling
66
120
  if @config.processes.empty? then
67
121
  @log.item "No processes to monitor"
68
122
  else
@@ -81,49 +135,24 @@ module Splash
81
135
  end
82
136
  end
83
137
  end
138
+ end
84
139
 
85
140
 
141
+ #prepare metrics sheduling
142
+ def init_metrics_scheduling
86
143
  sched,value = @config.daemon_metrics_scheduling.flatten
87
144
  @log.item "Initializing Splash metrics notifications."
88
145
  @server.send sched,value do
89
146
  begin
147
+ @log.trigger "Splash Metrics monitoring for Scheduling : #{sched.to_s} #{value.to_s}", @session
90
148
  @metric_manager.notify
91
149
  rescue Errno::ECONNREFUSED
92
150
  @log.error "PushGateway seems to be done, please start it."
93
151
  end
94
152
  end
95
-
96
- hostname = Socket.gethostname
97
- transport = get_default_subscriber queue: "splash.#{hostname}.input"
98
- if transport.class == Hash and transport.include? :case then
99
- splash_exit transport
100
- end
101
- transport.subscribe(:block => true) do |delivery_info, properties, body|
102
- content = YAML::load(body)
103
- session = get_session
104
- content[:session] = session
105
- if VERBS.include? content[:verb]
106
- @log.receive "Valid remote order, verb : #{content[:verb].to_s}", session
107
- res = self.send content[:verb], content
108
- get_default_client.publish queue: content[:return_to], message: res.to_yaml
109
- @log.send "Result to #{content[:return_to]}.", session
110
- else
111
- @log.receive "INVALID remote order, verb : #{content[:verb].to_s}", session
112
- get_default_client.publish queue: content[:return_to], message: "Unkown verb #{content[:verb]}".to_yaml
113
- end
114
- end
115
153
  end
116
154
 
117
- # Stop the Splash daemon gracefully
118
- # @return [hash] Exiter Case :quiet_exit
119
- def terminate
120
- @log.info "Splash daemon shutdown"
121
- @server.shutdown
122
- change_logger logger: :cli
123
- splash_exit case: :quiet_exit
124
- end
125
155
 
126
- private
127
156
  # prepare commands Scheduling
128
157
  def init_commands_scheduling
129
158
  config = get_config.commands
@@ -137,9 +166,43 @@ module Splash
137
166
  execute command: command.to_s, session: session
138
167
  end
139
168
  end
169
+ end
140
170
 
171
+
172
+ # prepare sequences Scheduling
173
+ def init_sequences_scheduling
174
+ config = get_config.sequences
175
+ sequences = config.select{|key,value| value.include? :schedule}.keys
176
+ sequences.each do |sequence|
177
+ sched,value = config[sequence][:schedule].flatten
178
+ @log.arrow "Scheduling sequence #{sequence.to_s}"
179
+ @server.send sched,value do
180
+ session = get_session
181
+ @log.trigger "Executing Scheduled sequence #{sequence.to_s} for Scheduling : #{sched.to_s} #{value.to_s}", session
182
+ run_seq name: sequence.to_s, session: session
183
+ end
184
+ end
141
185
  end
142
186
 
187
+ # reset the orchestrator
188
+ # @return [Hash] Exiter case
189
+ def reset_orchestrator
190
+ @server.shutdown
191
+ @server = Rufus::Scheduler::new
192
+ @server.extend SchedulerHooks
193
+ @config = rehash_config
194
+ @log.info "Splash Orchestrator re-hashing :"
195
+ if @scheduling then
196
+ @log.item "Re-Initializing Sequences & commands Scheduling."
197
+ init_commands_scheduling
198
+ init_sequences_scheduling
199
+ end
200
+ init_logs_monitoring_scheduling
201
+ init_process_monitoring_scheduling
202
+ init_metrics_scheduling
203
+ end
204
+
205
+
143
206
  # execute_command verb : execute command specified in payload
144
207
  # @param [Hash] options
145
208
  # @option options [Symbol] :command the name of the command
@@ -147,15 +210,13 @@ module Splash
147
210
  # @return [Hash] Exiter case
148
211
  def execute(options)
149
212
  command = CommandWrapper::new(options[:command])
150
- if options[:ack] then
213
+ if options[:ack] then
151
214
  else
152
215
  @metric_manager.inc_execution
153
216
  return command.call_and_notify trace: true, notify: true, callback: true, session: options[:session]
154
217
  end
155
218
  end
156
-
157
219
  end
158
-
159
220
  end
160
221
  end
161
222
  end
@@ -16,7 +16,7 @@ module Splash
16
16
  include Splash::Loggers
17
17
 
18
18
  # list of known verbs for Splash orchestrator
19
- VERBS=[:ping,:list_commands,:execute_command,:ack_command, :shutdown]
19
+ VERBS=[:ping,:list_commands,:execute_command,:ack_command, :shutdown, :get_jobs, :reset]
20
20
 
21
21
  # shutdown verb : stop the Splash daemon gracefully
22
22
  # @param [Hash] content message content Hash Structure, ignored
@@ -46,6 +46,21 @@ module Splash
46
46
  return execute command: content[:payload][:name], ack: true
47
47
  end
48
48
 
49
+
50
+ # get_jobs verb : return list of scheduled jobs for internal scheduler
51
+ # @param [Hash] content message content Hash Structure, ignored
52
+ # @return [String] YAML dataset
53
+ def get_jobs(content)
54
+ return @server.jobs.to_yaml
55
+ end
56
+
57
+ # reset verb : reset the internal scheduler
58
+ # @param [Hash] content message content Hash Structure, ignored
59
+ # @return [String] "Scheduler reset" static
60
+ def reset(content)
61
+ return "Scheduler reset" if reset_orchestrator
62
+ end
63
+
49
64
  # execute_command verb : execute command specified in payload
50
65
  # @param [Hash] content message content Hash Structure, include mandatory payload[:name]
51
66
  # @return [Hash] Exiter case
@@ -13,11 +13,16 @@ module Splash
13
13
  require 'etc'
14
14
  require 'forwardable'
15
15
  require 'json'
16
+ require 'uri'
17
+
18
+
16
19
 
17
20
 
18
21
 
19
22
  # Rubygems
20
23
  begin
24
+ require 'net/ssh'
25
+ require 'net/scp'
21
26
  require 'prometheus/client'
22
27
  require 'prometheus/client/push'
23
28
  require 'thor'
@@ -34,6 +39,7 @@ module Splash
34
39
  require 'rest-client'
35
40
  require 'kramdown'
36
41
  require 'rack/reverse_proxy'
42
+ require 'tty-table'
37
43
 
38
44
 
39
45
  rescue Gem::GemNotFoundException
@@ -55,8 +61,10 @@ module Splash
55
61
 
56
62
 
57
63
  require 'splash/commands'
64
+ require 'splash/sequences'
58
65
  require 'splash/logs'
59
66
  require 'splash/processes'
67
+ require 'splash/transfers'
60
68
 
61
69
  require 'splash/daemon'
62
70
  require 'splash/webadmin'
@@ -60,7 +60,7 @@ module Splash
60
60
 
61
61
  def splash_return(options = {})
62
62
 
63
- data = EXIT_MAP[options[:case]]
63
+ data = EXIT_MAP[options[:case]].clone
64
64
  data[:status] = (data[:code]>0)? :failure : :success
65
65
  data[:more] = options[:more] if options[:more]
66
66
  return data