prometheus-splash 0.5.2 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +38 -0
- data/README.md +58 -60
- data/bin/splash +3 -0
- data/config/splash.yml +106 -10
- data/lib/splash/backends.rb +7 -0
- data/lib/splash/backends/file.rb +36 -0
- data/lib/splash/backends/redis.rb +44 -1
- data/lib/splash/cli.rb +16 -4
- data/lib/splash/cli/commands.rb +12 -5
- data/lib/splash/cli/config.rb +9 -1
- data/lib/splash/cli/daemon.rb +49 -2
- data/lib/splash/cli/documentation.rb +5 -2
- data/lib/splash/cli/logs.rb +21 -13
- data/lib/splash/cli/process.rb +103 -0
- data/lib/splash/cli/sequences.rb +114 -0
- data/lib/splash/cli/transfers.rb +206 -0
- data/lib/splash/cli/webadmin.rb +46 -0
- data/lib/splash/commands.rb +26 -4
- data/lib/splash/config.rb +184 -23
- data/lib/splash/config/flush.rb +9 -1
- data/lib/splash/config/sanitycheck.rb +7 -2
- data/lib/splash/config/service.rb +8 -1
- data/lib/splash/config/setup.rb +8 -3
- data/lib/splash/constants.rb +41 -10
- data/lib/splash/daemon.rb +5 -1
- data/lib/splash/daemon/controller.rb +31 -11
- data/lib/splash/daemon/metrics.rb +47 -22
- data/lib/splash/daemon/orchestrator.rb +141 -36
- data/lib/splash/daemon/orchestrator/grammar.rb +40 -5
- data/lib/splash/daemon/orchestrator/hooks.rb +10 -0
- data/lib/splash/dependencies.rb +19 -0
- data/lib/splash/exiter.rb +14 -0
- data/lib/splash/helpers.rb +93 -46
- data/lib/splash/loggers.rb +30 -4
- data/lib/splash/loggers/cli.rb +18 -11
- data/lib/splash/loggers/daemon.rb +14 -3
- data/lib/splash/loggers/dual.rb +14 -1
- data/lib/splash/loggers/web.rb +51 -0
- data/lib/splash/logs.rb +16 -5
- data/lib/splash/processes.rb +83 -0
- data/lib/splash/sequences.rb +105 -0
- data/lib/splash/templates.rb +10 -0
- data/lib/splash/transfers.rb +224 -0
- data/lib/splash/transports.rb +9 -0
- data/lib/splash/transports/rabbitmq.rb +33 -4
- data/lib/splash/webadmin.rb +122 -0
- data/lib/splash/webadmin/api/routes/commands.rb +28 -0
- data/lib/splash/webadmin/api/routes/config.rb +10 -0
- data/lib/splash/webadmin/api/routes/init.rb +2 -0
- data/lib/splash/webadmin/api/routes/logs.rb +59 -0
- data/lib/splash/webadmin/api/routes/process.rb +60 -0
- data/lib/splash/webadmin/api/routes/sequences.rb +28 -0
- data/lib/splash/webadmin/main.rb +27 -0
- data/lib/splash/webadmin/portal/controllers/commands.rb +7 -0
- data/lib/splash/webadmin/portal/controllers/documentation.rb +6 -0
- data/lib/splash/webadmin/portal/controllers/home.rb +31 -0
- data/lib/splash/webadmin/portal/controllers/logs.rb +14 -0
- data/lib/splash/webadmin/portal/controllers/notfound.rb +5 -0
- data/lib/splash/webadmin/portal/controllers/processes.rb +14 -0
- data/lib/splash/webadmin/portal/controllers/proxy.rb +36 -0
- data/lib/splash/webadmin/portal/controllers/restclient.rb +19 -0
- data/lib/splash/webadmin/portal/controllers/sequences.rb +7 -0
- data/lib/splash/webadmin/portal/init.rb +11 -0
- data/lib/splash/webadmin/portal/public/css/ultragreen.css +8544 -0
- data/lib/splash/webadmin/portal/public/fonts/FontAwesome.otf +0 -0
- data/lib/splash/webadmin/portal/public/fonts/fontawesome-webfont.ttf +0 -0
- data/lib/splash/webadmin/portal/public/fonts/fontawesome-webfont.woff +0 -0
- data/lib/splash/webadmin/portal/public/fonts/fontawesome-webfont.woff2 +0 -0
- data/lib/splash/webadmin/portal/public/images/logo_splash.png +0 -0
- data/lib/splash/webadmin/portal/public/images/logo_splash_reduce.png +0 -0
- data/lib/splash/webadmin/portal/public/images/logo_splash_tiny.png +0 -0
- data/lib/splash/webadmin/portal/views/commands.slim +49 -0
- data/lib/splash/webadmin/portal/views/documentation.slim +3 -0
- data/lib/splash/webadmin/portal/views/home.slim +123 -0
- data/lib/splash/webadmin/portal/views/layout.slim +43 -0
- data/lib/splash/webadmin/portal/views/logs.slim +32 -0
- data/lib/splash/webadmin/portal/views/nav.slim +17 -0
- data/lib/splash/webadmin/portal/views/not_found.slim +3 -0
- data/lib/splash/webadmin/portal/views/processes.slim +29 -0
- data/lib/splash/webadmin/portal/views/proxy.slim +16 -0
- data/lib/splash/webadmin/portal/views/restclient.slim +41 -0
- data/lib/splash/webadmin/portal/views/restclient_result.slim +29 -0
- data/lib/splash/webadmin/portal/views/sequences.slim +50 -0
- data/prometheus-splash.gemspec +12 -3
- data/spec/helpers_spec.rb +119 -0
- metadata +196 -8
data/lib/splash/config/setup.rb
CHANGED
@@ -1,13 +1,18 @@
|
|
1
|
-
|
2
1
|
# coding: utf-8
|
3
2
|
|
4
|
-
|
3
|
+
# Base Splash module
|
5
4
|
module Splash
|
5
|
+
|
6
|
+
# moudle for Configuration utilities
|
6
7
|
module ConfigUtilities
|
7
8
|
include Splash::Constants
|
8
9
|
include Splash::Helpers
|
10
|
+
|
11
|
+
|
9
12
|
# Setup action method for installing Splash
|
10
|
-
# @
|
13
|
+
# @param [Hash] options
|
14
|
+
# @option options [Symbol] :preserve flag to preserve config file during setup
|
15
|
+
# @return [Hash] An Exiter case hash (:splash_setup_success or :splash_setup_error)
|
11
16
|
def setupsplash(options = {})
|
12
17
|
conf_in_path = search_file_in_gem "prometheus-splash", "config/splash.yml"
|
13
18
|
full_res = 0
|
data/lib/splash/constants.rb
CHANGED
@@ -1,23 +1,31 @@
|
|
1
1
|
# coding: utf-8
|
2
|
+
|
3
|
+
# base Splash module / namespace
|
2
4
|
module Splash
|
5
|
+
|
6
|
+
# Constants namespace
|
3
7
|
module Constants
|
4
|
-
|
8
|
+
|
9
|
+
# Current splash version
|
10
|
+
VERSION = "0.8.0"
|
5
11
|
|
6
12
|
# the path to th config file, not overridable by config
|
7
13
|
CONFIG_FILE = "/etc/splash.yml"
|
8
14
|
# the default execution trace_path if backend file
|
9
15
|
TRACE_PATH="/var/run/splash"
|
16
|
+
# the default pid file path
|
17
|
+
PID_PATH="/var/run"
|
10
18
|
|
11
19
|
|
12
20
|
# default scheduling criteria for log monitoring
|
13
21
|
DAEMON_LOGMON_SCHEDULING={ :every => '20s'}
|
14
|
-
# default scheduling criteria for
|
15
|
-
DAEMON_METRICS_SCHEDULING={ :every => '
|
22
|
+
# default scheduling criteria for metrics notifications
|
23
|
+
DAEMON_METRICS_SCHEDULING={ :every => '15s'}
|
24
|
+
# default scheduling criteria for process monitoring
|
25
|
+
DAEMON_PROCMON_SCHEDULING={ :every => '20s'}
|
16
26
|
|
17
27
|
# the display name of daemon in proc info (ps/top)
|
18
28
|
DAEMON_PROCESS_NAME="Splash : daemon."
|
19
|
-
# the default pid file path
|
20
|
-
DAEMON_PID_PATH="/var/run"
|
21
29
|
# the default pid file name
|
22
30
|
DAEMON_PID_FILE="splash.pid"
|
23
31
|
# the default sdtout trace file
|
@@ -34,10 +42,14 @@ module Splash
|
|
34
42
|
# type of licence
|
35
43
|
LICENSE="BSD-2-Clause"
|
36
44
|
|
37
|
-
# the default prometheus pushgateway
|
38
|
-
|
39
|
-
|
40
|
-
|
45
|
+
# the default prometheus pushgateway URL
|
46
|
+
PROMETHEUS_PUSHGATEWAY_URL = 'http://localhost:9091/'
|
47
|
+
|
48
|
+
# the default prometheus Alertmanager URL
|
49
|
+
PROMETHEUS_ALERTMANAGER_URL = 'http://localhost:9092/'
|
50
|
+
|
51
|
+
# the default prometheus URL
|
52
|
+
PROMETHEUS_URL = "http://localhost:9090/"
|
41
53
|
|
42
54
|
# the default path fo execution report template
|
43
55
|
EXECUTION_TEMPLATE="/etc/splash_execution_report.tpl"
|
@@ -53,11 +65,30 @@ module Splash
|
|
53
65
|
:active => :rabbitmq,
|
54
66
|
:rabbitmq => { :port => 5672, :host => "localhost", :vhost => '/'} }
|
55
67
|
|
56
|
-
|
68
|
+
# loggers default settings
|
69
|
+
LOGGERS_STRUCT = { :list => [:cli,:daemon, :dual, :web],
|
57
70
|
:default => :cli,
|
58
71
|
:level => :info,
|
59
72
|
:daemon => {:file => '/var/log/splash.log'},
|
73
|
+
:web => {:file => '/var/log/splash_web.log'},
|
60
74
|
:cli => {:color => true, :emoji => true } }
|
61
75
|
|
76
|
+
WEBADMIN_IP = "127.0.0.1"
|
77
|
+
WEBADMIN_PORT = "9234"
|
78
|
+
WEBADMIN_PROXY = false
|
79
|
+
# the display name of daemon in proc info (ps/top)
|
80
|
+
WEBADMIN_PROCESS_NAME="Splash : WebAdmin."
|
81
|
+
# the default pid file path
|
82
|
+
WEBADMIN_PID_PATH="/var/run"
|
83
|
+
# the default pid file name
|
84
|
+
WEBADMIN_PID_FILE="splash.pid"
|
85
|
+
# the default sdtout trace file
|
86
|
+
WEBADMIN_STDOUT_TRACE="stdout.txt"
|
87
|
+
# the default sdterr trace file
|
88
|
+
WEBADMIN_STDERR_TRACE="stderr.txt"
|
89
|
+
|
90
|
+
# default transfer retention for trace
|
91
|
+
TRANSFER_DEFAULT_RETENTION=1
|
92
|
+
|
62
93
|
end
|
63
94
|
end
|
data/lib/splash/daemon.rb
CHANGED
@@ -1,2 +1,6 @@
|
|
1
1
|
# coding: utf-8
|
2
|
-
|
2
|
+
require File.dirname(__FILE__) + '/daemon/orchestrator.rb'
|
3
|
+
require File.dirname(__FILE__) + '/daemon/metrics.rb'
|
4
|
+
require File.dirname(__FILE__) + '/daemon/controller.rb'
|
5
|
+
|
6
|
+
# Dir[File.dirname(__FILE__) + '/daemon/*.rb'].each {|file| require file }
|
@@ -1,6 +1,13 @@
|
|
1
1
|
# coding: utf-8
|
2
|
+
require 'splash/daemon/orchestrator'
|
3
|
+
|
4
|
+
# base Splash module
|
2
5
|
module Splash
|
6
|
+
|
7
|
+
# global daemon module
|
3
8
|
module Daemon
|
9
|
+
|
10
|
+
# Daemon Controller Module
|
4
11
|
module Controller
|
5
12
|
include Splash::Constants
|
6
13
|
include Splash::Helpers
|
@@ -9,11 +16,17 @@ module Splash
|
|
9
16
|
include Splash::Loggers
|
10
17
|
include Splash::Daemon::Orchestrator
|
11
18
|
|
19
|
+
# Start the Splash Daemon
|
20
|
+
# @param [Hash] options
|
21
|
+
# @option options [Symbol] :quiet activate quiet mode for log (limit to :fatal)
|
22
|
+
# @option options [Symbol] :foreground run daemon in foreground
|
23
|
+
# @option options [Symbol] :purge clean input queue for daemon on configured transport
|
24
|
+
# @return [Hash] Exiter Case (:quiet_exit, :already_exist, :unknown_error or other)
|
12
25
|
def startdaemon(options = {})
|
13
26
|
config = get_config
|
14
27
|
log = get_logger
|
15
28
|
log.level = :fatal if options[:quiet]
|
16
|
-
unless verify_service
|
29
|
+
unless verify_service url: config.prometheus_pushgateway_url then
|
17
30
|
return {:case => :service_dependence_missing, :more => 'Prometheus Gateway'}
|
18
31
|
end
|
19
32
|
realpid = get_processes pattern: get_config.daemon_process_name
|
@@ -22,7 +35,7 @@ module Splash
|
|
22
35
|
return {:case => :already_exist, :more => "Splash Process already launched on foreground "}
|
23
36
|
end
|
24
37
|
|
25
|
-
unless File::exist? config.
|
38
|
+
unless File::exist? config.daemon_full_pid_path then
|
26
39
|
unless realpid.empty? then
|
27
40
|
return {:case => :already_exist, :more => "Splash Process already launched "}
|
28
41
|
end
|
@@ -37,19 +50,19 @@ module Splash
|
|
37
50
|
end
|
38
51
|
end
|
39
52
|
daemon_config = {:description => config.daemon_process_name,
|
40
|
-
:pid_file => config.
|
41
|
-
:stdout_trace => config.
|
42
|
-
:stderr_trace => config.
|
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,
|
43
56
|
:foreground => options[:foreground]
|
44
57
|
}
|
45
58
|
|
46
|
-
["int","term","hup"].each do |type| daemon_config["sig#{type}_handler".to_sym] = Proc::new { ObjectSpace.each_object(Splash::Daemon::Orchestrator::Scheduler).first.
|
59
|
+
["int","term","hup"].each do |type| daemon_config["sig#{type}_handler".to_sym] = Proc::new { ObjectSpace.each_object(Splash::Daemon::Orchestrator::Scheduler).first.terminate } end
|
47
60
|
res = daemonize daemon_config do
|
48
61
|
Scheduler::new options
|
49
62
|
end
|
50
63
|
sleep 1
|
51
64
|
if res == 0 then
|
52
|
-
pid = `cat #{config.
|
65
|
+
pid = `cat #{config.daemon_full_pid_path}`.to_i
|
53
66
|
log.ok "Splash Daemon Started, with PID : #{pid}"
|
54
67
|
return {:case => :quiet_exit, :more => "Splash Daemon successfully loaded."}
|
55
68
|
else
|
@@ -61,30 +74,37 @@ module Splash
|
|
61
74
|
end
|
62
75
|
end
|
63
76
|
|
77
|
+
# Stop the Splash Daemon
|
78
|
+
# @param [Hash] options
|
79
|
+
# @option options [Symbol] :quiet activate quiet mode for log (limit to :fatal)
|
80
|
+
# @return [Hash] Exiter Case (:quiet_exit, :not_found, other)
|
64
81
|
def stopdaemon(options = {})
|
65
82
|
config = get_config
|
66
83
|
log = get_logger
|
67
84
|
log.level = :fatal if options[:quiet]
|
68
|
-
if File.exist?(config.
|
85
|
+
if File.exist?(config.daemon_full_pid_path) then
|
69
86
|
begin
|
70
|
-
pid = `cat #{config.
|
87
|
+
pid = `cat #{config.daemon_full_pid_path}`.to_i
|
71
88
|
Process.kill("TERM", pid)
|
72
89
|
acase = {:case => :quiet_exit, :more => 'Splash stopped succesfully'}
|
73
90
|
rescue Errno::ESRCH
|
74
91
|
acase = {:case => :not_found, :more => "Process of PID : #{pid} not found"}
|
75
92
|
end
|
76
|
-
FileUtils::rm config.
|
93
|
+
FileUtils::rm config.daemon_full_pid_path if File::exist? config.daemon_full_pid_path
|
77
94
|
else
|
78
95
|
acase = {:case => :not_found, :more => "Splash is not running"}
|
79
96
|
end
|
80
97
|
return acase
|
81
98
|
end
|
82
99
|
|
100
|
+
# Status of the Splash Daemon, display status
|
101
|
+
# @param [Hash] options ignored
|
102
|
+
# @return [Hash] Exiter Case (:status_ko, :status_ok)
|
83
103
|
def statusdaemon(options = {})
|
84
104
|
log = get_logger
|
85
105
|
config = get_config
|
86
106
|
pid = realpid = ''
|
87
|
-
pid = `cat #{config.
|
107
|
+
pid = `cat #{config.daemon_full_pid_path}`.to_s if File.exist?(config.daemon_full_pid_path)
|
88
108
|
listpid = get_processes({ :pattern => get_config.daemon_process_name})
|
89
109
|
pid.chomp!
|
90
110
|
if listpid.empty? then
|
@@ -1,5 +1,12 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
# base Splash module
|
1
4
|
module Splash
|
5
|
+
|
6
|
+
# global daemon module
|
2
7
|
module Daemon
|
8
|
+
|
9
|
+
# Metrics management modulefor Splash daemon
|
3
10
|
module Metrics
|
4
11
|
include Splash::Constants
|
5
12
|
include Splash::Helpers
|
@@ -7,64 +14,82 @@ module Splash
|
|
7
14
|
include Splash::Loggers
|
8
15
|
|
9
16
|
@@manager=nil
|
10
|
-
# factory of Configuration Class instance
|
11
|
-
# @param [String] config_file the path of the YAML Config file
|
12
|
-
# @return [SPlash::Config::Configuration]
|
13
|
-
def get_metrics_manager
|
14
|
-
return @@manager ||= Manager::new
|
15
|
-
end
|
16
17
|
|
18
|
+
# metrics manager factory
|
19
|
+
# @return [Splash::Daemon::Metrics::Manager]
|
20
|
+
def get_metrics_manager(session)
|
21
|
+
return @@manager ||= Manager::new(:session => session)
|
22
|
+
end
|
17
23
|
|
24
|
+
# Metrics Manager (collect and sending to Prometheus)
|
18
25
|
class Manager
|
19
26
|
|
27
|
+
# metric : commands executions count during Splash daemon uptime
|
20
28
|
attr_reader :execution_count
|
21
|
-
|
22
|
-
|
23
|
-
|
29
|
+
# metric : logs monitoring count during Splash daemon uptime
|
30
|
+
attr_reader :monitoring_logs_count
|
31
|
+
# metric : processes monitoring count during Splash daemon uptime
|
32
|
+
attr_reader :monitoring_processes_count
|
33
|
+
|
34
|
+
# Constructor prepare prometheus-client, defined metrics and init attributes
|
35
|
+
def initialize(options ={})
|
36
|
+
@session = options[:session]
|
24
37
|
@config = get_config
|
25
38
|
@starttime = Time.now
|
26
39
|
@execution_count = 0
|
27
|
-
@
|
40
|
+
@monitoring_logs_count = 0
|
41
|
+
@monitoring_processes_count = 0
|
42
|
+
|
28
43
|
|
29
44
|
@registry = Prometheus::Client::Registry::new
|
30
45
|
@metric_uptime = Prometheus::Client::Gauge.new(:splash_uptime, docstring: 'SPLASH self metric uptime')
|
31
46
|
@metric_execution = Prometheus::Client::Gauge.new(:splash_execution, docstring: 'SPLASH self metric total commands execution count')
|
32
|
-
@
|
47
|
+
@metric_logs_monitoring = Prometheus::Client::Gauge.new(:splash_logs_monitoring, docstring: 'SPLASH self metric total logs monitoring count')
|
48
|
+
@metric_processes_monitoring = Prometheus::Client::Gauge.new(:splash_processes_monitoring, docstring: 'SPLASH self metric total processes monitoring count')
|
33
49
|
@registry.register(@metric_uptime)
|
34
50
|
@registry.register(@metric_execution)
|
35
|
-
@registry.register(@
|
51
|
+
@registry.register(@metric_logs_monitoring)
|
52
|
+
@registry.register(@metric_processes_monitoring)
|
36
53
|
end
|
37
54
|
|
38
|
-
|
55
|
+
# virtual accessor uptime
|
39
56
|
def uptime
|
40
57
|
return Time.now - @starttime
|
41
58
|
end
|
42
59
|
|
60
|
+
# increment metric : execution_count
|
43
61
|
def inc_execution
|
44
62
|
@execution_count += 1
|
45
63
|
end
|
46
64
|
|
47
|
-
|
48
|
-
def
|
49
|
-
@
|
65
|
+
# increment metric : monitoring_logs_count
|
66
|
+
def inc_logs_monitoring
|
67
|
+
@monitoring_logs_count += 1
|
50
68
|
end
|
51
69
|
|
70
|
+
# increment metric : monitoring_processes_count
|
71
|
+
def inc_processes_monitoring
|
72
|
+
@monitoring_processes_count += 1
|
73
|
+
end
|
52
74
|
|
75
|
+
# Send metrics to Prometheus PushGateway
|
76
|
+
# @return [Hash] Exiter case ( :service_dependence_missing , :quiet_exit)
|
53
77
|
def notify
|
54
78
|
log = get_logger
|
55
|
-
|
56
|
-
unless verify_service host: @config.prometheus_pushgateway_host ,port: @config.prometheus_pushgateway_port then
|
79
|
+
unless verify_service url: @config.prometheus_pushgateway_url then
|
57
80
|
return { :case => :service_dependence_missing, :more => "Prometheus Notification not send." }
|
58
81
|
end
|
59
82
|
|
60
|
-
log.
|
83
|
+
log.ok "Sending Splash self metrics to PushGateway." , @session
|
61
84
|
@metric_uptime.set uptime
|
62
85
|
@metric_execution.set execution_count
|
63
|
-
@
|
86
|
+
@metric_logs_monitoring.set monitoring_logs_count
|
87
|
+
@metric_processes_monitoring.set monitoring_processes_count
|
88
|
+
|
64
89
|
hostname = Socket.gethostname
|
65
|
-
url =
|
90
|
+
url = @config.prometheus_pushgateway_url
|
66
91
|
Prometheus::Client::Push.new('Splash',hostname, url).add(@registry)
|
67
|
-
log.debug "Sending to Prometheus PushGateway done.", session
|
92
|
+
log.debug "Sending to Prometheus PushGateway done.", @session
|
68
93
|
return {:case => :quiet_exit }
|
69
94
|
end
|
70
95
|
|
@@ -1,10 +1,16 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
Dir[File.dirname(__FILE__) + '/orchestrator/*.rb'].each {|file| require file }
|
3
3
|
|
4
|
+
# base Splash module
|
4
5
|
module Splash
|
6
|
+
|
7
|
+
# global daemon module
|
5
8
|
module Daemon
|
9
|
+
|
10
|
+
# orchestrator specific module
|
6
11
|
module Orchestrator
|
7
12
|
|
13
|
+
# Splash Scheduler object
|
8
14
|
class Scheduler
|
9
15
|
include Splash::Constants
|
10
16
|
include Splash::Helpers
|
@@ -13,49 +19,59 @@ module Splash
|
|
13
19
|
include Splash::Daemon::Orchestrator::Grammar
|
14
20
|
include Splash::Loggers
|
15
21
|
include Splash::Logs
|
22
|
+
include Splash::Processes
|
16
23
|
include Splash::Commands
|
24
|
+
include Splash::Sequences
|
17
25
|
|
18
|
-
|
26
|
+
# Constructor prepare the Scheduler
|
27
|
+
# commands Schedules
|
28
|
+
# logs monitorings
|
29
|
+
# process monitorings
|
30
|
+
# @param [Hash] options
|
31
|
+
# @option options [Symbol] :scheduling activate commands scheduling
|
19
32
|
def initialize(options = {})
|
20
33
|
@log = get_logger
|
21
34
|
self.extend Splash::Daemon::Metrics
|
22
|
-
@
|
35
|
+
@session = get_session
|
36
|
+
@metric_manager = get_metrics_manager(@session)
|
23
37
|
$stdout.sync = true
|
24
38
|
$stderr.sync = true
|
25
39
|
@server = Rufus::Scheduler::new
|
26
40
|
@server.extend SchedulerHooks
|
27
41
|
@config = get_config
|
28
|
-
@
|
42
|
+
@scheduling = options[:scheduling]
|
43
|
+
|
29
44
|
@log.info "Splash Orchestrator starting :"
|
30
|
-
if
|
31
|
-
@log.item "Initializing commands Scheduling."
|
45
|
+
if @scheduling then
|
46
|
+
@log.item "Initializing Sequences & commands Scheduling."
|
32
47
|
init_commands_scheduling
|
33
|
-
|
34
|
-
sched,value = @config.daemon_logmon_scheduling.flatten
|
35
|
-
@log.item "Initializing logs monitorings & notifications."
|
36
|
-
@server.send sched,value do
|
37
|
-
begin
|
38
|
-
session = get_session
|
39
|
-
@metric_manager.inc_monitoring
|
40
|
-
@log.trigger "Logs monitoring for Scheduling : #{sched.to_s} #{value.to_s}", session
|
41
|
-
@result.analyse
|
42
|
-
@result.notify :session => session
|
43
|
-
rescue Errno::ECONNREFUSED
|
44
|
-
@log.error "PushGateway seems to be done, please start it.", session
|
45
|
-
end
|
48
|
+
init_sequences_scheduling
|
46
49
|
end
|
47
50
|
|
48
|
-
|
51
|
+
init_logs_monitoring_scheduling
|
52
|
+
init_process_monitoring_scheduling
|
53
|
+
init_metrics_scheduling
|
54
|
+
init_daemon_subscriber
|
49
55
|
|
50
|
-
|
51
|
-
@server.send sched,value do
|
52
|
-
begin
|
53
|
-
@metric_manager.notify
|
54
|
-
rescue Errno::ECONNREFUSED
|
55
|
-
@log.error "PushGateway seems to be done, please start it."
|
56
|
-
end
|
57
|
-
end
|
56
|
+
end
|
58
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
|
59
75
|
hostname = Socket.gethostname
|
60
76
|
transport = get_default_subscriber queue: "splash.#{hostname}.input"
|
61
77
|
if transport.class == Hash and transport.include? :case then
|
@@ -77,14 +93,67 @@ module Splash
|
|
77
93
|
end
|
78
94
|
end
|
79
95
|
|
80
|
-
|
81
|
-
|
82
|
-
@
|
83
|
-
|
84
|
-
|
96
|
+
#prepare logs monitoring sheduling
|
97
|
+
def init_logs_monitoring_scheduling
|
98
|
+
if @config.logs.empty? then
|
99
|
+
@log.item "No logs to monitor"
|
100
|
+
else
|
101
|
+
sched,value = @config.daemon_procmon_scheduling.flatten
|
102
|
+
@log.item "Initializing logs monitorings & notifications."
|
103
|
+
@log_result = LogScanner::new
|
104
|
+
@server.send sched,value do
|
105
|
+
begin
|
106
|
+
session = get_session
|
107
|
+
@metric_manager.inc_logs_monitoring
|
108
|
+
@log.trigger "Logs monitoring for Scheduling : #{sched.to_s} #{value.to_s}", session
|
109
|
+
@log_result.analyse
|
110
|
+
@log_result.notify :session => session
|
111
|
+
rescue Errno::ECONNREFUSED
|
112
|
+
@log.error "PushGateway seems to be done, please start it.", session
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
85
116
|
end
|
86
117
|
|
87
|
-
|
118
|
+
#prepare process monitoring sheduling
|
119
|
+
def init_process_monitoring_scheduling
|
120
|
+
if @config.processes.empty? then
|
121
|
+
@log.item "No processes to monitor"
|
122
|
+
else
|
123
|
+
sched,value = @config.daemon_logmon_scheduling.flatten
|
124
|
+
@log.item "Initializing processes monitorings & notifications."
|
125
|
+
@process_result = ProcessScanner::new
|
126
|
+
@server.send sched,value do
|
127
|
+
begin
|
128
|
+
session = get_session
|
129
|
+
@metric_manager.inc_processes_monitoring
|
130
|
+
@log.trigger "Processes monitoring for Scheduling : #{sched.to_s} #{value.to_s}", session
|
131
|
+
@process_result.analyse
|
132
|
+
@process_result.notify :session => session
|
133
|
+
rescue Errno::ECONNREFUSED
|
134
|
+
@log.error "PushGateway seems to be done, please start it.", session
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
|
141
|
+
#prepare metrics sheduling
|
142
|
+
def init_metrics_scheduling
|
143
|
+
sched,value = @config.daemon_metrics_scheduling.flatten
|
144
|
+
@log.item "Initializing Splash metrics notifications."
|
145
|
+
@server.send sched,value do
|
146
|
+
begin
|
147
|
+
@log.trigger "Splash Metrics monitoring for Scheduling : #{sched.to_s} #{value.to_s}", @session
|
148
|
+
@metric_manager.notify
|
149
|
+
rescue Errno::ECONNREFUSED
|
150
|
+
@log.error "PushGateway seems to be done, please start it."
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
|
156
|
+
# prepare commands Scheduling
|
88
157
|
def init_commands_scheduling
|
89
158
|
config = get_config.commands
|
90
159
|
commands = config.select{|key,value| value.include? :schedule}.keys
|
@@ -97,21 +166,57 @@ module Splash
|
|
97
166
|
execute command: command.to_s, session: session
|
98
167
|
end
|
99
168
|
end
|
169
|
+
end
|
100
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
|
101
185
|
end
|
102
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
|
+
|
206
|
+
# execute_command verb : execute command specified in payload
|
207
|
+
# @param [Hash] options
|
208
|
+
# @option options [Symbol] :command the name of the command
|
209
|
+
# @option options [Symbol] :ack ack flag to inhibit execution and send ack to Prometheus (0)
|
210
|
+
# @return [Hash] Exiter case
|
103
211
|
def execute(options)
|
104
212
|
command = CommandWrapper::new(options[:command])
|
105
213
|
if options[:ack] then
|
106
|
-
command.ack
|
107
214
|
else
|
108
215
|
@metric_manager.inc_execution
|
109
216
|
return command.call_and_notify trace: true, notify: true, callback: true, session: options[:session]
|
110
217
|
end
|
111
218
|
end
|
112
|
-
|
113
219
|
end
|
114
|
-
|
115
220
|
end
|
116
221
|
end
|
117
222
|
end
|