prometheus-splash 0.4.5 → 0.6.1

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 (99) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +64 -2
  3. data/README.md +58 -60
  4. data/bin/splash +13 -5
  5. data/config/splash.yml +77 -7
  6. data/lib/splash/backends.rb +6 -0
  7. data/lib/splash/backends/file.rb +40 -0
  8. data/lib/splash/backends/redis.rb +47 -4
  9. data/lib/splash/cli.rb +31 -3
  10. data/lib/splash/cli/commands.rb +82 -33
  11. data/lib/splash/cli/config.rb +25 -4
  12. data/lib/splash/cli/daemon.rb +11 -14
  13. data/lib/splash/cli/documentation.rb +5 -2
  14. data/lib/splash/cli/logs.rb +27 -17
  15. data/lib/splash/cli/process.rb +103 -0
  16. data/lib/splash/cli/sequences.rb +112 -0
  17. data/lib/splash/cli/webadmin.rb +46 -0
  18. data/lib/splash/commands.rb +146 -120
  19. data/lib/splash/config.rb +170 -15
  20. data/lib/splash/config/flush.rb +30 -0
  21. data/lib/splash/config/sanitycheck.rb +7 -2
  22. data/lib/splash/config/service.rb +33 -0
  23. data/lib/splash/config/setup.rb +8 -3
  24. data/lib/splash/constants.rb +37 -8
  25. data/lib/splash/daemon.rb +6 -0
  26. data/lib/splash/daemon/controller.rb +136 -0
  27. data/lib/splash/daemon/metrics.rb +103 -0
  28. data/lib/splash/daemon/orchestrator.rb +182 -0
  29. data/lib/splash/daemon/orchestrator/grammar.rb +76 -0
  30. data/lib/splash/daemon/orchestrator/hooks.rb +28 -0
  31. data/lib/splash/dependencies.rb +17 -2
  32. data/lib/splash/exiter.rb +15 -0
  33. data/lib/splash/helpers.rb +91 -50
  34. data/lib/splash/loggers.rb +48 -17
  35. data/lib/splash/loggers/cli.rb +18 -3
  36. data/lib/splash/loggers/daemon.rb +23 -4
  37. data/lib/splash/loggers/dual.rb +35 -2
  38. data/lib/splash/loggers/web.rb +51 -0
  39. data/lib/splash/logs.rb +67 -53
  40. data/lib/splash/processes.rb +83 -0
  41. data/lib/splash/sequences.rb +105 -0
  42. data/lib/splash/templates.rb +10 -0
  43. data/lib/splash/transports.rb +9 -0
  44. data/lib/splash/transports/rabbitmq.rb +33 -4
  45. data/lib/splash/webadmin.rb +122 -0
  46. data/lib/splash/webadmin/api/routes/commands.rb +28 -0
  47. data/lib/splash/webadmin/api/routes/config.rb +10 -0
  48. data/lib/splash/webadmin/api/routes/init.rb +2 -0
  49. data/lib/splash/webadmin/api/routes/logs.rb +59 -0
  50. data/lib/splash/webadmin/api/routes/process.rb +60 -0
  51. data/lib/splash/webadmin/main.rb +26 -0
  52. data/lib/splash/webadmin/portal/controllers/commands.rb +7 -0
  53. data/lib/splash/webadmin/portal/controllers/documentation.rb +6 -0
  54. data/lib/splash/webadmin/portal/controllers/home.rb +12 -0
  55. data/lib/splash/webadmin/portal/controllers/logs.rb +14 -0
  56. data/lib/splash/webadmin/portal/controllers/notfound.rb +5 -0
  57. data/lib/splash/webadmin/portal/controllers/processes.rb +14 -0
  58. data/lib/splash/webadmin/portal/controllers/proxy.rb +28 -0
  59. data/lib/splash/webadmin/portal/controllers/restclient.rb +19 -0
  60. data/lib/splash/webadmin/portal/init.rb +11 -0
  61. data/lib/splash/webadmin/portal/public/css/ultragreen.css +8544 -0
  62. data/lib/splash/webadmin/portal/public/fonts/FontAwesome.otf +0 -0
  63. data/lib/splash/webadmin/portal/public/fonts/fontawesome-webfont.ttf +0 -0
  64. data/lib/splash/webadmin/portal/public/fonts/fontawesome-webfont.woff +0 -0
  65. data/lib/splash/webadmin/portal/public/fonts/fontawesome-webfont.woff2 +0 -0
  66. data/lib/splash/webadmin/portal/public/images/logo_splash.png +0 -0
  67. data/lib/splash/webadmin/portal/public/images/logo_splash_reduce.png +0 -0
  68. data/lib/splash/webadmin/portal/public/images/logo_splash_tiny.png +0 -0
  69. data/lib/splash/webadmin/portal/views/commands.slim +49 -0
  70. data/lib/splash/webadmin/portal/views/documentation.slim +3 -0
  71. data/lib/splash/webadmin/portal/views/home.slim +78 -0
  72. data/lib/splash/webadmin/portal/views/layout.slim +43 -0
  73. data/lib/splash/webadmin/portal/views/logs.slim +32 -0
  74. data/lib/splash/webadmin/portal/views/nav.slim +17 -0
  75. data/lib/splash/webadmin/portal/views/not_found.slim +3 -0
  76. data/lib/splash/webadmin/portal/views/processes.slim +29 -0
  77. data/lib/splash/webadmin/portal/views/proxy.slim +13 -0
  78. data/lib/splash/webadmin/portal/views/restclient.slim +41 -0
  79. data/lib/splash/webadmin/portal/views/restclient_result.slim +29 -0
  80. data/prometheus-splash.gemspec +8 -1
  81. data/spec/helpers_spec.rb +119 -0
  82. data/templates/ansible-splash/Vagrantfile +1 -1
  83. data/templates/ansible-splash/deploy.yml +28 -1
  84. data/templates/ansible-splash/group_vars/DEV.yml +2 -0
  85. data/templates/ansible-splash/roles/mq/handlers/main.yml +1 -1
  86. data/templates/ansible-splash/roles/mq/tasks/main.yml +17 -1
  87. data/templates/ansible-splash/roles/mq/templates/rabbitmq-env.conf.j2 +13 -0
  88. data/templates/ansible-splash/roles/splash/handlers/main.yml +4 -0
  89. data/templates/ansible-splash/roles/splash/tasks/main.yml +25 -1
  90. data/templates/ansible-splash/roles/splash/templates/logrotate.splash.j2 +11 -0
  91. data/templates/ansible-splash/roles/splash/templates/splash.yml.j2 +1 -1
  92. data/templates/splashd.service +1 -1
  93. data/test.sh +42 -0
  94. metadata +159 -11
  95. data/lib/splash/controller.rb +0 -90
  96. data/lib/splash/orchestrator.rb +0 -100
  97. data/lib/splash/orchestrator/grammar.rb +0 -53
  98. data/lib/splash/orchestrator/hooks.rb +0 -16
  99. data/templates/ansible-splash/inventory.prod +0 -26
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+
3
+ # Base Splash module
4
+ module Splash
5
+
6
+ # module for Configuration utilities
7
+ module ConfigUtilities
8
+ include Splash::Constants
9
+
10
+ # clean backend action method
11
+ # @param [Hash] options
12
+ # @option options [Symbol] :name the name of the backend (:redis, :file)
13
+ # @return [Hash] An Exiter case hash (:quiet_exit or :configuration_error)
14
+ def flush_backend(options ={})
15
+ config = get_config
16
+ self.extend Splash::Backends
17
+ self.extend Splash::Loggers
18
+ log = get_logger
19
+ log.info "Splash backend flushing"
20
+ name = (options[:name])? options[:name] : :execution_trace
21
+ backend = get_backend name
22
+ if backend.flush then
23
+ return { :case => :quiet_exit, :more => "Splash backend #{name.to_s} flushed" }
24
+ else
25
+ return { :case => :configuration_error, :more => "Splash backend #{name.to_s} can't be flushed" }
26
+ end
27
+ end
28
+
29
+ end
30
+ end
@@ -1,12 +1,17 @@
1
1
  # coding: utf-8
2
+
3
+ # Base Splash module
2
4
  module Splash
5
+
6
+ # moudle for Configuration utilities
3
7
  module ConfigUtilities
4
8
  include Splash::Constants
5
9
 
6
10
 
7
11
 
8
12
  # Sanitycheck action method for testing installation of Splash
9
- # @return [Integer] an errorcode value
13
+ # @param [Hash] options
14
+ # @return [Hash] An Exiter case hash (:splash_sanitycheck_success or :splash_sanitycheck_error)
10
15
  def checkconfig(options ={})
11
16
  self.extend Splash::Loggers
12
17
  log = get_logger
@@ -45,7 +50,7 @@ module Splash
45
50
  end
46
51
 
47
52
  target = "Prometheus PushGateway Service running"
48
- if verify_service host: config.prometheus_pushgateway_host ,port: config.prometheus_pushgateway_port then
53
+ if verify_service url: config.prometheus_pushgateway_url then
49
54
  log.ok target
50
55
  else
51
56
  log.ko target
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+
3
+ # Base Splash module
4
+ module Splash
5
+
6
+ # moudle for Configuration utilities
7
+ module ConfigUtilities
8
+ include Splash::Constants
9
+ include Splash::Helpers
10
+
11
+
12
+ # clean backend configured
13
+ # @param [Hash] options
14
+ # @option options [Symbol] :name the name of the backend (:redis, :file)
15
+ # @return [Hash] An Exiter case hash (:quiet_exit or :configuration_error)
16
+ def addservice(options = {})
17
+ local_service_file = search_file_in_gem "prometheus-splash", "templates/splashd.service"
18
+ config = get_config
19
+ self.extend Splash::Loggers
20
+ log = get_logger
21
+ log.info "Splashd Systemd Service installation"
22
+ service_file = "splashd.service"
23
+ systemd_path = "/etc/systemd/system"
24
+ return { :case => :options_incompatibility, :more => "Systemd not avaible on this System" } if verify_folder({ :name => systemd_path}) == [:inexistant]
25
+ log.item "Installing service file : #{service_file} in #{systemd_path}"
26
+ if install_file source: local_service_file, target: "#{systemd_path}/#{service_file}", mode: "755", owner: config.user_root, group: config.group_root then
27
+ return { :case => :quiet_exit, :more => "Splashd Systemd service installed" }
28
+ else
29
+ return { :case => :error_exit, :more => "Splashd Systemd service could not be installed" }
30
+ end
31
+ end
32
+ end
33
+ end
@@ -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
- # @return [Integer] an errorcode value
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
@@ -1,20 +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
- VERSION = "0.4.5"
8
+
9
+ # Current splash version
10
+ VERSION = "0.6.1"
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'}
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'}
26
+
14
27
  # the display name of daemon in proc info (ps/top)
15
28
  DAEMON_PROCESS_NAME="Splash : daemon."
16
- # the default pid file path
17
- DAEMON_PID_PATH="/var/run"
18
29
  # the default pid file name
19
30
  DAEMON_PID_FILE="splash.pid"
20
31
  # the default sdtout trace file
@@ -31,10 +42,11 @@ module Splash
31
42
  # type of licence
32
43
  LICENSE="BSD-2-Clause"
33
44
 
34
- # the default prometheus pushgateway host
35
- PROMETHEUS_PUSHGATEWAY_HOST = "localhost"
36
- # the default prometheus pushgateway port
37
- PROMETHEUS_PUSHGATEWAY_PORT = "9091"
45
+ # the default prometheus pushgateway URL
46
+ PROMETHEUS_PUSHGATEWAY_URL = 'http://localhost:9090/'
47
+
48
+ # the default prometheus URL
49
+ PROMETHEUS_URL = "http://localhost:9090/"
38
50
 
39
51
  # the default path fo execution report template
40
52
  EXECUTION_TEMPLATE="/etc/splash_execution_report.tpl"
@@ -50,11 +62,28 @@ module Splash
50
62
  :active => :rabbitmq,
51
63
  :rabbitmq => { :port => 5672, :host => "localhost", :vhost => '/'} }
52
64
 
53
- LOGGERS_STRUCT = { :list => [:cli,:daemon, :dual],
65
+ # loggers default settings
66
+ LOGGERS_STRUCT = { :list => [:cli,:daemon, :dual, :web],
54
67
  :default => :cli,
55
68
  :level => :info,
56
69
  :daemon => {:file => '/var/log/splash.log'},
70
+ :web => {:file => '/var/log/splash_web.log'},
57
71
  :cli => {:color => true, :emoji => true } }
58
72
 
73
+ WEBADMIN_IP = "127.0.0.1"
74
+ WEBADMIN_PORT = "9234"
75
+ WEBADMIN_PROXY = false
76
+ # the display name of daemon in proc info (ps/top)
77
+ WEBADMIN_PROCESS_NAME="Splash : WebAdmin."
78
+ # the default pid file path
79
+ WEBADMIN_PID_PATH="/var/run"
80
+ # the default pid file name
81
+ WEBADMIN_PID_FILE="splash.pid"
82
+ # the default sdtout trace file
83
+ WEBADMIN_STDOUT_TRACE="stdout.txt"
84
+ # the default sdterr trace file
85
+ WEBADMIN_STDERR_TRACE="stderr.txt"
86
+
87
+
59
88
  end
60
89
  end
@@ -0,0 +1,6 @@
1
+ # coding: utf-8
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 }
@@ -0,0 +1,136 @@
1
+ # coding: utf-8
2
+ require 'splash/daemon/orchestrator'
3
+
4
+ # base Splash module
5
+ module Splash
6
+
7
+ # global daemon module
8
+ module Daemon
9
+
10
+ # Daemon Controller Module
11
+ module Controller
12
+ include Splash::Constants
13
+ include Splash::Helpers
14
+ include Splash::Config
15
+ include Splash::Exiter
16
+ include Splash::Loggers
17
+ include Splash::Daemon::Orchestrator
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)
25
+ def startdaemon(options = {})
26
+ config = get_config
27
+ log = get_logger
28
+ log.level = :fatal if options[:quiet]
29
+ unless verify_service url: config.prometheus_pushgateway_url then
30
+ return {:case => :service_dependence_missing, :more => 'Prometheus Gateway'}
31
+ end
32
+ realpid = get_processes pattern: get_config.daemon_process_name
33
+ foreground = get_processes patterns: [ "splash", "foreground" ]
34
+ unless foreground.empty? or options[:foreground] then
35
+ return {:case => :already_exist, :more => "Splash Process already launched on foreground "}
36
+ end
37
+
38
+ unless File::exist? config.daemon_full_pid_path then
39
+ unless realpid.empty? then
40
+ return {:case => :already_exist, :more => "Splash Process already launched "}
41
+ end
42
+ if options[:purge] then
43
+ transport = get_default_client
44
+ if transport.class == Hash and transport.include? :case then
45
+ splash_exit transport
46
+ else
47
+ queue = "splash.#{Socket.gethostname}.input"
48
+ transport.purge queue: queue
49
+ log.info "Queue : #{queue} purged"
50
+ end
51
+ end
52
+ daemon_config = {:description => config.daemon_process_name,
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
+ :foreground => options[:foreground]
57
+ }
58
+
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
60
+ res = daemonize daemon_config do
61
+ Scheduler::new options
62
+ end
63
+ sleep 1
64
+ if res == 0 then
65
+ pid = `cat #{config.daemon_full_pid_path}`.to_i
66
+ log.ok "Splash Daemon Started, with PID : #{pid}"
67
+ return {:case => :quiet_exit, :more => "Splash Daemon successfully loaded."}
68
+ else
69
+ return {:case => :unknown_error, :more => "Splash Daemon loading error, see logs for more details."}
70
+ end
71
+
72
+ else
73
+ return {:case => :already_exist, :more => "Pid File, please verify if Splash daemon is running."}
74
+ end
75
+ end
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)
81
+ def stopdaemon(options = {})
82
+ config = get_config
83
+ log = get_logger
84
+ log.level = :fatal if options[:quiet]
85
+ if File.exist?(config.daemon_full_pid_path) then
86
+ begin
87
+ pid = `cat #{config.daemon_full_pid_path}`.to_i
88
+ Process.kill("TERM", pid)
89
+ acase = {:case => :quiet_exit, :more => 'Splash stopped succesfully'}
90
+ rescue Errno::ESRCH
91
+ acase = {:case => :not_found, :more => "Process of PID : #{pid} not found"}
92
+ end
93
+ FileUtils::rm config.daemon_full_pid_path if File::exist? config.daemon_full_pid_path
94
+ else
95
+ acase = {:case => :not_found, :more => "Splash is not running"}
96
+ end
97
+ return acase
98
+ end
99
+
100
+ # Status of the Splash Daemon, display status
101
+ # @param [Hash] options ignored
102
+ # @return [Hash] Exiter Case (:status_ko, :status_ok)
103
+ def statusdaemon(options = {})
104
+ log = get_logger
105
+ config = get_config
106
+ pid = realpid = ''
107
+ pid = `cat #{config.daemon_full_pid_path}`.to_s if File.exist?(config.daemon_full_pid_path)
108
+ listpid = get_processes({ :pattern => get_config.daemon_process_name})
109
+ pid.chomp!
110
+ if listpid.empty? then
111
+ realpid = ''
112
+ else
113
+ realpid = listpid.first
114
+ end
115
+ unless realpid.empty? then
116
+ log.item "Splash Process is running with PID #{realpid} "
117
+ else
118
+ log.item 'Splash Process not found '
119
+ end
120
+ unless pid.empty? then
121
+ log.item "and PID file exist with PID #{pid}"
122
+ else
123
+ log.item "and PID file don't exist"
124
+ end
125
+ if pid == realpid then
126
+ return {:case => :status_ok }
127
+ elsif pid.empty? then
128
+ return {:case => :status_ko, :more => "PID File error, you have to kill process manualy, with : '(sudo )kill -TERM #{realpid}'"}
129
+ elsif realpid.empty? then
130
+ return {:case => :status_ko, :more => "Process Splash Dameon missing, run 'splash daemon stop' to reload properly"}
131
+ end
132
+ end
133
+
134
+ end
135
+ end
136
+ end
@@ -0,0 +1,103 @@
1
+ # coding: utf-8
2
+
3
+ # base Splash module
4
+ module Splash
5
+
6
+ # global daemon module
7
+ module Daemon
8
+
9
+ # Metrics management modulefor Splash daemon
10
+ module Metrics
11
+ include Splash::Constants
12
+ include Splash::Helpers
13
+ include Splash::Config
14
+ include Splash::Loggers
15
+
16
+ @@manager=nil
17
+
18
+ # metrics manager factory
19
+ # @return [Splash::Daemon::Metrics::Manager]
20
+ def get_metrics_manager
21
+ return @@manager ||= Manager::new
22
+ end
23
+
24
+ # Metrics Manager (collect and sending to Prometheus)
25
+ class Manager
26
+
27
+ # metric : commands executions count during Splash daemon uptime
28
+ attr_reader :execution_count
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
36
+ @config = get_config
37
+ @starttime = Time.now
38
+ @execution_count = 0
39
+ @monitoring_logs_count = 0
40
+ @monitoring_processes_count = 0
41
+
42
+
43
+ @registry = Prometheus::Client::Registry::new
44
+ @metric_uptime = Prometheus::Client::Gauge.new(:splash_uptime, docstring: 'SPLASH self metric uptime')
45
+ @metric_execution = Prometheus::Client::Gauge.new(:splash_execution, docstring: 'SPLASH self metric total commands execution count')
46
+ @metric_logs_monitoring = Prometheus::Client::Gauge.new(:splash_logs_monitoring, docstring: 'SPLASH self metric total logs monitoring count')
47
+ @metric_processes_monitoring = Prometheus::Client::Gauge.new(:splash_processes_monitoring, docstring: 'SPLASH self metric total processes monitoring count')
48
+ @registry.register(@metric_uptime)
49
+ @registry.register(@metric_execution)
50
+ @registry.register(@metric_logs_monitoring)
51
+ @registry.register(@metric_processes_monitoring)
52
+ end
53
+
54
+ # virtual accessor uptime
55
+ def uptime
56
+ return Time.now - @starttime
57
+ end
58
+
59
+ # increment metric : execution_count
60
+ def inc_execution
61
+ @execution_count += 1
62
+ end
63
+
64
+ # increment metric : monitoring_logs_count
65
+ def inc_logs_monitoring
66
+ @monitoring_logs_count += 1
67
+ end
68
+
69
+ # increment metric : monitoring_processes_count
70
+ def inc_processes_monitoring
71
+ @monitoring_processes_count += 1
72
+ end
73
+
74
+ # Send metrics to Prometheus PushGateway
75
+ # @return [Hash] Exiter case ( :service_dependence_missing , :quiet_exit)
76
+ def notify
77
+ log = get_logger
78
+ session = get_session
79
+ unless verify_service url: @config.prometheus_pushgateway_url then
80
+ return { :case => :service_dependence_missing, :more => "Prometheus Notification not send." }
81
+ end
82
+
83
+ log.debug "Sending Splash self metrics to PushGateway." , session
84
+ @metric_uptime.set uptime
85
+ @metric_execution.set execution_count
86
+ @metric_logs_monitoring.set monitoring_logs_count
87
+ @metric_processes_monitoring.set monitoring_processes_count
88
+
89
+ hostname = Socket.gethostname
90
+ url = @config.prometheus_pushgateway_url
91
+ Prometheus::Client::Push.new('Splash',hostname, url).add(@registry)
92
+ log.debug "Sending to Prometheus PushGateway done.", session
93
+ return {:case => :quiet_exit }
94
+ end
95
+
96
+
97
+
98
+ end
99
+
100
+
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,182 @@
1
+ # coding: utf-8
2
+ Dir[File.dirname(__FILE__) + '/orchestrator/*.rb'].each {|file| require file }
3
+
4
+ # base Splash module
5
+ module Splash
6
+
7
+ # global daemon module
8
+ module Daemon
9
+
10
+ # orchestrator specific module
11
+ module Orchestrator
12
+
13
+ # Splash Scheduler object
14
+ class Scheduler
15
+ include Splash::Constants
16
+ include Splash::Helpers
17
+ include Splash::Config
18
+ include Splash::Transports
19
+ include Splash::Daemon::Orchestrator::Grammar
20
+ include Splash::Loggers
21
+ include Splash::Logs
22
+ include Splash::Processes
23
+ include Splash::Commands
24
+ include Splash::Sequences
25
+
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
32
+ def initialize(options = {})
33
+ @log = get_logger
34
+ self.extend Splash::Daemon::Metrics
35
+ @metric_manager = get_metrics_manager
36
+ $stdout.sync = true
37
+ $stderr.sync = true
38
+ @server = Rufus::Scheduler::new
39
+ @server.extend SchedulerHooks
40
+ @config = get_config
41
+
42
+ @log.info "Splash Orchestrator starting :"
43
+ if options[:scheduling] then
44
+ @log.item "Initializing commands Scheduling."
45
+ init_commands_scheduling
46
+ init_sequences_scheduling
47
+ end
48
+
49
+ if @config.logs.empty? then
50
+ @log.item "No logs to monitor"
51
+ else
52
+ sched,value = @config.daemon_procmon_scheduling.flatten
53
+ @log.item "Initializing logs monitorings & notifications."
54
+ @log_result = LogScanner::new
55
+ @server.send sched,value do
56
+ begin
57
+ session = get_session
58
+ @metric_manager.inc_logs_monitoring
59
+ @log.trigger "Logs monitoring for Scheduling : #{sched.to_s} #{value.to_s}", session
60
+ @log_result.analyse
61
+ @log_result.notify :session => session
62
+ rescue Errno::ECONNREFUSED
63
+ @log.error "PushGateway seems to be done, please start it.", session
64
+ end
65
+ end
66
+ end
67
+
68
+ if @config.processes.empty? then
69
+ @log.item "No processes to monitor"
70
+ else
71
+ sched,value = @config.daemon_logmon_scheduling.flatten
72
+ @log.item "Initializing processes monitorings & notifications."
73
+ @process_result = ProcessScanner::new
74
+ @server.send sched,value do
75
+ begin
76
+ session = get_session
77
+ @metric_manager.inc_processes_monitoring
78
+ @log.trigger "Processes monitoring for Scheduling : #{sched.to_s} #{value.to_s}", session
79
+ @process_result.analyse
80
+ @process_result.notify :session => session
81
+ rescue Errno::ECONNREFUSED
82
+ @log.error "PushGateway seems to be done, please start it.", session
83
+ end
84
+ end
85
+ end
86
+
87
+
88
+ sched,value = @config.daemon_metrics_scheduling.flatten
89
+ @log.item "Initializing Splash metrics notifications."
90
+ @server.send sched,value do
91
+ begin
92
+ @metric_manager.notify
93
+ rescue Errno::ECONNREFUSED
94
+ @log.error "PushGateway seems to be done, please start it."
95
+ end
96
+ end
97
+
98
+ hostname = Socket.gethostname
99
+ transport = get_default_subscriber queue: "splash.#{hostname}.input"
100
+ if transport.class == Hash and transport.include? :case then
101
+ splash_exit transport
102
+ end
103
+ transport.subscribe(:block => true) do |delivery_info, properties, body|
104
+ content = YAML::load(body)
105
+ session = get_session
106
+ content[:session] = session
107
+ if VERBS.include? content[:verb]
108
+ @log.receive "Valid remote order, verb : #{content[:verb].to_s}", session
109
+ res = self.send content[:verb], content
110
+ get_default_client.publish queue: content[:return_to], message: res.to_yaml
111
+ @log.send "Result to #{content[:return_to]}.", session
112
+ else
113
+ @log.receive "INVALID remote order, verb : #{content[:verb].to_s}", session
114
+ get_default_client.publish queue: content[:return_to], message: "Unkown verb #{content[:verb]}".to_yaml
115
+ end
116
+ end
117
+ end
118
+
119
+ # Stop the Splash daemon gracefully
120
+ # @return [hash] Exiter Case :quiet_exit
121
+ def terminate
122
+ @log.info "Splash daemon shutdown"
123
+ @server.shutdown
124
+ change_logger logger: :cli
125
+ splash_exit case: :quiet_exit
126
+ end
127
+
128
+ private
129
+ # prepare commands Scheduling
130
+ def init_commands_scheduling
131
+ config = get_config.commands
132
+ commands = config.select{|key,value| value.include? :schedule}.keys
133
+ commands.each do |command|
134
+ sched,value = config[command][:schedule].flatten
135
+ @log.arrow "Scheduling command #{command.to_s}"
136
+ @server.send sched,value do
137
+ session = get_session
138
+ @log.trigger "Executing Scheduled command #{command.to_s} for Scheduling : #{sched.to_s} #{value.to_s}", session
139
+ execute command: command.to_s, session: session
140
+ end
141
+ end
142
+
143
+ end
144
+
145
+
146
+ # prepare sequences Scheduling
147
+ def init_sequences_scheduling
148
+ config = get_config.sequences
149
+ sequences = config.select{|key,value| value.include? :schedule}.keys
150
+ sequences.each do |sequence|
151
+ sched,value = config[sequence][:schedule].flatten
152
+ @log.arrow "Scheduling sequence #{sequence.to_s}"
153
+ @server.send sched,value do
154
+ session = get_session
155
+ @log.trigger "Executing Scheduled sequence #{sequence.to_s} for Scheduling : #{sched.to_s} #{value.to_s}", session
156
+ run_seq name: sequence.to_s, session: session
157
+ end
158
+ end
159
+
160
+ end
161
+
162
+
163
+
164
+ # execute_command verb : execute command specified in payload
165
+ # @param [Hash] options
166
+ # @option options [Symbol] :command the name of the command
167
+ # @option options [Symbol] :ack ack flag to inhibit execution and send ack to Prometheus (0)
168
+ # @return [Hash] Exiter case
169
+ def execute(options)
170
+ command = CommandWrapper::new(options[:command])
171
+ if options[:ack] then
172
+ else
173
+ @metric_manager.inc_execution
174
+ return command.call_and_notify trace: true, notify: true, callback: true, session: options[:session]
175
+ end
176
+ end
177
+
178
+ end
179
+
180
+ end
181
+ end
182
+ end