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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +64 -2
- data/README.md +58 -60
- data/bin/splash +13 -5
- data/config/splash.yml +77 -7
- data/lib/splash/backends.rb +6 -0
- data/lib/splash/backends/file.rb +40 -0
- data/lib/splash/backends/redis.rb +47 -4
- data/lib/splash/cli.rb +31 -3
- data/lib/splash/cli/commands.rb +82 -33
- data/lib/splash/cli/config.rb +25 -4
- data/lib/splash/cli/daemon.rb +11 -14
- data/lib/splash/cli/documentation.rb +5 -2
- data/lib/splash/cli/logs.rb +27 -17
- data/lib/splash/cli/process.rb +103 -0
- data/lib/splash/cli/sequences.rb +112 -0
- data/lib/splash/cli/webadmin.rb +46 -0
- data/lib/splash/commands.rb +146 -120
- data/lib/splash/config.rb +170 -15
- data/lib/splash/config/flush.rb +30 -0
- data/lib/splash/config/sanitycheck.rb +7 -2
- data/lib/splash/config/service.rb +33 -0
- data/lib/splash/config/setup.rb +8 -3
- data/lib/splash/constants.rb +37 -8
- data/lib/splash/daemon.rb +6 -0
- data/lib/splash/daemon/controller.rb +136 -0
- data/lib/splash/daemon/metrics.rb +103 -0
- data/lib/splash/daemon/orchestrator.rb +182 -0
- data/lib/splash/daemon/orchestrator/grammar.rb +76 -0
- data/lib/splash/daemon/orchestrator/hooks.rb +28 -0
- data/lib/splash/dependencies.rb +17 -2
- data/lib/splash/exiter.rb +15 -0
- data/lib/splash/helpers.rb +91 -50
- data/lib/splash/loggers.rb +48 -17
- data/lib/splash/loggers/cli.rb +18 -3
- data/lib/splash/loggers/daemon.rb +23 -4
- data/lib/splash/loggers/dual.rb +35 -2
- data/lib/splash/loggers/web.rb +51 -0
- data/lib/splash/logs.rb +67 -53
- data/lib/splash/processes.rb +83 -0
- data/lib/splash/sequences.rb +105 -0
- data/lib/splash/templates.rb +10 -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/main.rb +26 -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 +12 -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 +28 -0
- data/lib/splash/webadmin/portal/controllers/restclient.rb +19 -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 +78 -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 +13 -0
- data/lib/splash/webadmin/portal/views/restclient.slim +41 -0
- data/lib/splash/webadmin/portal/views/restclient_result.slim +29 -0
- data/prometheus-splash.gemspec +8 -1
- data/spec/helpers_spec.rb +119 -0
- data/templates/ansible-splash/Vagrantfile +1 -1
- data/templates/ansible-splash/deploy.yml +28 -1
- data/templates/ansible-splash/group_vars/DEV.yml +2 -0
- data/templates/ansible-splash/roles/mq/handlers/main.yml +1 -1
- data/templates/ansible-splash/roles/mq/tasks/main.yml +17 -1
- data/templates/ansible-splash/roles/mq/templates/rabbitmq-env.conf.j2 +13 -0
- data/templates/ansible-splash/roles/splash/handlers/main.yml +4 -0
- data/templates/ansible-splash/roles/splash/tasks/main.yml +25 -1
- data/templates/ansible-splash/roles/splash/templates/logrotate.splash.j2 +11 -0
- data/templates/ansible-splash/roles/splash/templates/splash.yml.j2 +1 -1
- data/templates/splashd.service +1 -1
- data/test.sh +42 -0
- metadata +159 -11
- data/lib/splash/controller.rb +0 -90
- data/lib/splash/orchestrator.rb +0 -100
- data/lib/splash/orchestrator/grammar.rb +0 -53
- data/lib/splash/orchestrator/hooks.rb +0 -16
- data/templates/ansible-splash/inventory.prod +0 -26
data/lib/splash/loggers/cli.rb
CHANGED
@@ -1,11 +1,17 @@
|
|
1
1
|
# coding: utf-8
|
2
|
+
|
3
|
+
# base Splash module
|
2
4
|
module Splash
|
5
|
+
|
6
|
+
# Splash Loggers module
|
3
7
|
module Loggers
|
4
8
|
|
9
|
+
# Cli specific logger
|
5
10
|
class Cli < Splash::Loggers::LoggerTemplate
|
6
11
|
|
7
12
|
include Splash::Config
|
8
13
|
|
14
|
+
# mapping of UTf-8 emoji for log levels or alias
|
9
15
|
EMOJI = { :unknown => "\u{1F4A5}",
|
10
16
|
:fatal => "\u{26D4}",
|
11
17
|
:error => "\u{1F6AB}",
|
@@ -22,6 +28,7 @@ module Splash
|
|
22
28
|
:success => "\u{1F4AA}",
|
23
29
|
:debug => "\u{1F41B}"}
|
24
30
|
|
31
|
+
# mapping of colors for log levels or alias
|
25
32
|
COLORS = { :unknown => :red,
|
26
33
|
:fatal => :red,
|
27
34
|
:error => :red,
|
@@ -39,7 +46,11 @@ module Splash
|
|
39
46
|
:debug => :magenta}
|
40
47
|
|
41
48
|
|
42
|
-
|
49
|
+
# log wrapper
|
50
|
+
# @param [Hash] options
|
51
|
+
# @option options [Symbol] :level defined in Splash::Loggers::LEVEL or Splash::Loggers::ALIAS
|
52
|
+
# @option options [String] :message
|
53
|
+
# display formatted string to STDOUT
|
43
54
|
def log(options)
|
44
55
|
level = (ALIAS.keys.include? options[:level])? ALIAS[options[:level]] : options[:level]
|
45
56
|
if @active_levels.include? level then
|
@@ -59,14 +70,20 @@ module Splash
|
|
59
70
|
end
|
60
71
|
end
|
61
72
|
|
73
|
+
# setter in configuration for emoji display
|
74
|
+
# @param [Boolean] status
|
62
75
|
def emoji=(status)
|
63
76
|
get_config.loggers[:cli][:emoji] = status
|
64
77
|
end
|
65
78
|
|
79
|
+
# setter in configuration for color display
|
80
|
+
# @param [Boolean] status
|
66
81
|
def color=(status)
|
67
82
|
get_config.loggers[:cli][:color] = status
|
68
83
|
end
|
69
84
|
|
85
|
+
# check if unicode must be used with term ENV
|
86
|
+
# @return [Boolean]
|
70
87
|
def check_unicode_term
|
71
88
|
return false unless ENV.include? "TERM"
|
72
89
|
if ENV.values_at("LC_ALL","LC_CTYPE","LANG").compact.first.include?("UTF-8") and ENV.values_at('TERM').first.include? "xterm" then
|
@@ -78,7 +95,5 @@ module Splash
|
|
78
95
|
|
79
96
|
end
|
80
97
|
|
81
|
-
class BadLevel < Exception; end
|
82
|
-
|
83
98
|
end
|
84
99
|
end
|
@@ -1,12 +1,17 @@
|
|
1
1
|
# coding: utf-8
|
2
|
+
|
3
|
+
# base Splash module
|
2
4
|
module Splash
|
3
|
-
module Loggers
|
4
5
|
|
6
|
+
# Splash Loggers module
|
7
|
+
module Loggers
|
5
8
|
|
9
|
+
# Daemon specific logger
|
6
10
|
class Daemon < Splash::Loggers::LoggerTemplate
|
7
11
|
|
8
12
|
|
9
|
-
|
13
|
+
# contructor, open log file
|
14
|
+
# @return [Splash::Loggers::Daemon]
|
10
15
|
def initialize
|
11
16
|
self.level = get_config.loggers[:level]
|
12
17
|
@log_file = get_config.loggers[:daemon][:file]
|
@@ -14,18 +19,32 @@ module Splash
|
|
14
19
|
@stream.sync = true
|
15
20
|
end
|
16
21
|
|
17
|
-
|
22
|
+
# log wrapper
|
23
|
+
# @param [Hash] options
|
24
|
+
# @option options [Symbol] :level defined in Splash::Loggers::LEVEL or Splash::Loggers::ALIAS
|
25
|
+
# @option options [String] :message
|
26
|
+
# @option options [String] :session a session number
|
27
|
+
# write formatted string to log file
|
18
28
|
def log(options)
|
29
|
+
pid = Process.pid.to_s
|
30
|
+
date = DateTime.now.to_s
|
19
31
|
level = (ALIAS.keys.include? options[:level])? ALIAS[options[:level]] : options[:level]
|
20
32
|
if @active_levels.include? level then
|
21
|
-
|
33
|
+
unless options[:session].empty? then
|
34
|
+
@stream.puts "[#{date}] (#{pid}) (#{options[:session]}) #{alt(options[:level])} : #{options[:message]}"
|
35
|
+
else
|
36
|
+
@stream.puts "[#{date}] (#{pid}) #{alt(options[:level])} : #{options[:message]}"
|
37
|
+
end
|
22
38
|
end
|
23
39
|
end
|
24
40
|
|
41
|
+
# close log file descriptor
|
25
42
|
def close
|
26
43
|
@stream.close
|
27
44
|
end
|
28
45
|
|
46
|
+
|
47
|
+
|
29
48
|
end
|
30
49
|
|
31
50
|
end
|
data/lib/splash/loggers/dual.rb
CHANGED
@@ -1,11 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
# base Splash module
|
1
4
|
module Splash
|
5
|
+
|
6
|
+
# Splash Loggers module
|
2
7
|
module Loggers
|
3
8
|
|
4
|
-
|
5
|
-
|
9
|
+
# Dual multiplexer specific logger
|
10
|
+
# log against CLi and Daemon
|
11
|
+
class Dual #< Splash::Loggers::LoggerTemplate
|
6
12
|
|
7
13
|
|
14
|
+
include Splash::Config
|
15
|
+
|
16
|
+
# build levels and alias forwarders
|
17
|
+
LEVELS.each do |method|
|
18
|
+
define_method(method) do |message,session = ''|
|
19
|
+
self.log({ :level => method, :message => message, :session => session})
|
20
|
+
end
|
21
|
+
end
|
22
|
+
ALIAS.keys.each do |method|
|
23
|
+
define_method(method) do |message,session = ''|
|
24
|
+
self.log({ :level => method, :message => message, :session => session})
|
25
|
+
end
|
26
|
+
end
|
8
27
|
|
28
|
+
# Constructor build two attributes for each loggers : Cli, Daemon
|
9
29
|
def initialize
|
10
30
|
super
|
11
31
|
@log1 = Splash::Loggers::Cli::new
|
@@ -17,6 +37,19 @@ module Splash
|
|
17
37
|
@log2.log options
|
18
38
|
end
|
19
39
|
|
40
|
+
# getter for root level
|
41
|
+
# @return [Symbol] a level
|
42
|
+
def level
|
43
|
+
@level
|
44
|
+
end
|
45
|
+
|
46
|
+
# setter for global level, both Cli and Daemon
|
47
|
+
# @param [Symbol] level a level in Splash::Loggers::LEVELS or Splash::Loggers::ALIAS
|
48
|
+
def level=(level)
|
49
|
+
@level = level
|
50
|
+
@log1.level=level
|
51
|
+
@log2.level=level
|
52
|
+
end
|
20
53
|
end
|
21
54
|
end
|
22
55
|
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
# base Splash module
|
4
|
+
module Splash
|
5
|
+
|
6
|
+
# Splash Loggers module
|
7
|
+
module Loggers
|
8
|
+
|
9
|
+
# Web specific logger
|
10
|
+
class Web < Splash::Loggers::LoggerTemplate
|
11
|
+
|
12
|
+
|
13
|
+
# contructor, open log file
|
14
|
+
# @return [Splash::Loggers::Web]
|
15
|
+
def initialize
|
16
|
+
self.level = get_config.loggers[:level]
|
17
|
+
@log_file = get_config.loggers[:web][:file]
|
18
|
+
@stream = File::open(@log_file, 'a')
|
19
|
+
@stream.sync = true
|
20
|
+
end
|
21
|
+
|
22
|
+
# log wrapper
|
23
|
+
# @param [Hash] options
|
24
|
+
# @option options [Symbol] :level defined in Splash::Loggers::LEVEL or Splash::Loggers::ALIAS
|
25
|
+
# @option options [String] :message
|
26
|
+
# @option options [String] :session a session number
|
27
|
+
# write formatted string to log file
|
28
|
+
def log(options)
|
29
|
+
pid = Process.pid.to_s
|
30
|
+
date = DateTime.now.to_s
|
31
|
+
level = (ALIAS.keys.include? options[:level])? ALIAS[options[:level]] : options[:level]
|
32
|
+
if @active_levels.include? level then
|
33
|
+
unless options[:session].empty? then
|
34
|
+
@stream.puts "[#{date}] (#{pid}) (#{options[:session]}) #{alt(options[:level])} : #{options[:message]}"
|
35
|
+
else
|
36
|
+
@stream.puts "[#{date}] (#{pid}) #{alt(options[:level])} : #{options[:message]}"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# close log file descriptor
|
42
|
+
def close
|
43
|
+
@stream.close
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
data/lib/splash/logs.rb
CHANGED
@@ -1,67 +1,81 @@
|
|
1
1
|
# coding: utf-8
|
2
|
+
|
3
|
+
# base Splash module
|
2
4
|
module Splash
|
3
|
-
class LogScanner
|
4
|
-
include Splash::Constants
|
5
|
-
include Splash::Config
|
6
5
|
|
6
|
+
# Logs namespace
|
7
|
+
module Logs
|
7
8
|
|
8
|
-
#
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
@config = get_config
|
13
|
-
@registry = Prometheus::Client.registry
|
14
|
-
@metric_count = Prometheus::Client::Gauge.new(:logerrors, docstring: 'SPLASH metric log error', labels: [:log ])
|
15
|
-
@metric_missing = Prometheus::Client::Gauge.new(:logmissing, docstring: 'SPLASH metric log missing', labels: [:log ])
|
16
|
-
@metric_lines = Prometheus::Client::Gauge.new(:loglines, docstring: 'SPLASH metric log lines numbers', labels: [:log ])
|
17
|
-
@registry.register(@metric_count)
|
18
|
-
@registry.register(@metric_missing)
|
19
|
-
@registry.register(@metric_lines)
|
20
|
-
end
|
9
|
+
# Log scanner and notifier
|
10
|
+
class LogScanner
|
11
|
+
include Splash::Constants
|
12
|
+
include Splash::Config
|
21
13
|
|
22
14
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
15
|
+
# LogScanner Constructor : initialize prometheus metrics
|
16
|
+
# return [Splash::Logs::LogScanner]
|
17
|
+
def initialize
|
18
|
+
@logs_target = Marshal.load(Marshal.dump(get_config.logs))
|
19
|
+
@config = get_config
|
20
|
+
@registry = Prometheus::Client::Registry::new
|
21
|
+
@metric_count = Prometheus::Client::Gauge.new(:logerrors, docstring: 'SPLASH metric log error', labels: [:log ])
|
22
|
+
@metric_missing = Prometheus::Client::Gauge.new(:logmissing, docstring: 'SPLASH metric log missing', labels: [:log ])
|
23
|
+
@metric_lines = Prometheus::Client::Gauge.new(:loglines, docstring: 'SPLASH metric log lines numbers', labels: [:log ])
|
24
|
+
@registry.register(@metric_count)
|
25
|
+
@registry.register(@metric_missing)
|
26
|
+
@registry.register(@metric_lines)
|
35
27
|
end
|
36
|
-
return {:case => :quiet_exit }
|
37
|
-
end
|
38
28
|
|
39
|
-
# pseudo-accessor on @logs_target
|
40
|
-
def output
|
41
|
-
return @logs_target
|
42
|
-
end
|
43
29
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
30
|
+
# start log analyse for log target in config
|
31
|
+
# @return [Hash] Exiter case :quiet_exit
|
32
|
+
def analyse
|
33
|
+
@logs_target.each do |record|
|
34
|
+
record[:count]=0 if record[:count].nil?
|
35
|
+
record[:status] = :clean if record[:status].nil?
|
36
|
+
if File.exist?(record[:log]) then
|
37
|
+
record[:count] = File.readlines(record[:log]).grep(/#{record[:pattern]}/).size
|
38
|
+
record[:status] = :matched if record[:count] > 0
|
39
|
+
record[:lines] = `wc -l "#{record[:log]}"`.strip.split(/\s+/)[0].to_i unless record[:status] == :missing
|
40
|
+
else
|
41
|
+
record[:status] = :missing
|
42
|
+
end
|
43
|
+
end
|
44
|
+
return {:case => :quiet_exit }
|
49
45
|
end
|
50
|
-
|
51
|
-
@logs_target
|
52
|
-
|
53
|
-
|
54
|
-
@
|
55
|
-
|
56
|
-
|
57
|
-
|
46
|
+
|
47
|
+
# pseudo-accessor on @logs_target
|
48
|
+
# @return [Hash] the logs structure
|
49
|
+
def output
|
50
|
+
return @logs_target
|
51
|
+
end
|
52
|
+
|
53
|
+
# start notification on prometheus for metric logerrors, logmissing; loglines
|
54
|
+
# @param [Hash] options
|
55
|
+
# @option options [String] :session a session number for log daemon
|
56
|
+
# @return [Hash] Exiter case :quiet_exit
|
57
|
+
def notify(options = {})
|
58
|
+
log = get_logger
|
59
|
+
unless verify_service url: @config.prometheus_pushgateway_url then
|
60
|
+
return { :case => :service_dependence_missing, :more => "Prometheus Notification not send." }
|
61
|
+
end
|
62
|
+
session = (options[:session]) ? options[:session] : log.get_session
|
63
|
+
log.info "Sending metrics to Prometheus Pushgateway", session
|
64
|
+
@logs_target.each do |item|
|
65
|
+
missing = (item[:status] == :missing)? 1 : 0
|
66
|
+
log.item "Sending metrics for #{item[:log]}", session
|
67
|
+
@metric_count.set(item[:count], labels: { log: item[:log] })
|
68
|
+
@metric_missing.set(missing, labels: { log: item[:log] })
|
69
|
+
lines = (item[:lines])? item[:lines] : 0
|
70
|
+
@metric_lines.set(lines, labels: { log: item[:log] })
|
71
|
+
end
|
72
|
+
hostname = Socket.gethostname
|
73
|
+
url = @config.prometheus_pushgateway_url
|
74
|
+
Prometheus::Client::Push.new('Splash',hostname, url).add(@registry)
|
75
|
+
log.ok "Sending to Prometheus PushGateway done.", session
|
76
|
+
return {:case => :quiet_exit }
|
58
77
|
end
|
59
|
-
hostname = Socket.gethostname
|
60
|
-
url = "http://#{@config.prometheus_pushgateway_host}:#{@config.prometheus_pushgateway_port}"
|
61
|
-
Prometheus::Client::Push.new('Splash',hostname, url).add(@registry)
|
62
|
-
log.ok "Sending to Prometheus PushGateway done."
|
63
|
-
return {:case => :quiet_exit }
|
64
|
-
end
|
65
78
|
|
79
|
+
end
|
66
80
|
end
|
67
81
|
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
# base Splash Module
|
4
|
+
module Splash
|
5
|
+
|
6
|
+
# Processes namespace
|
7
|
+
module Processes
|
8
|
+
|
9
|
+
# Processes scanner and notifier
|
10
|
+
class ProcessScanner
|
11
|
+
include Splash::Constants
|
12
|
+
include Splash::Config
|
13
|
+
|
14
|
+
|
15
|
+
# ProcessScanner Constructor : initialize prometheus metrics
|
16
|
+
# @return [Splash::Processes::ProcessScanner]
|
17
|
+
def initialize
|
18
|
+
@processes_target = Marshal.load(Marshal.dump(get_config.processes))
|
19
|
+
@config = get_config
|
20
|
+
@registry = Prometheus::Client::Registry::new
|
21
|
+
@metric_status = Prometheus::Client::Gauge.new(:process_status, docstring: 'SPLASH metric process status', labels: [:process ])
|
22
|
+
@metric_cpu_percent = Prometheus::Client::Gauge.new(:process_cpu_percent, docstring: 'SPLASH metric process CPU usage in percent', labels: [:process ])
|
23
|
+
@metric_mem_percent = Prometheus::Client::Gauge.new(:process_mem_percent, docstring: 'SPLASH metric process MEM usage in percent', labels: [:process ])
|
24
|
+
@registry.register(@metric_status)
|
25
|
+
@registry.register(@metric_cpu_percent)
|
26
|
+
@registry.register(@metric_mem_percent)
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
# start process analyse for process target in config
|
32
|
+
# @return [Hash] Exiter case :quiet_exit
|
33
|
+
def analyse
|
34
|
+
@processes_target.each do |record|
|
35
|
+
list = get_processes patterns: record[:patterns], full: true
|
36
|
+
if list.empty?
|
37
|
+
record[:status] = :inexistant
|
38
|
+
record[:cpu] = 0
|
39
|
+
record[:mem] = 0
|
40
|
+
else
|
41
|
+
record[:status] = :running
|
42
|
+
record[:cpu] = list[0]['%CPU']
|
43
|
+
record[:mem] = list[0]['%MEM']
|
44
|
+
end
|
45
|
+
end
|
46
|
+
return {:case => :quiet_exit }
|
47
|
+
end
|
48
|
+
|
49
|
+
# pseudo-accessor on @processes_target
|
50
|
+
# @return [Hash] the processes structure
|
51
|
+
def output
|
52
|
+
return @processes_target
|
53
|
+
end
|
54
|
+
|
55
|
+
# start notification on prometheus for metrics
|
56
|
+
# @param [Hash] options
|
57
|
+
# @option options [String] :session a session number for log daemon
|
58
|
+
# @return [Hash] Exiter case :quiet_exit
|
59
|
+
def notify(options = {})
|
60
|
+
log = get_logger
|
61
|
+
unless verify_service url: @config.prometheus_pushgateway_url then
|
62
|
+
return { :case => :service_dependence_missing, :more => "Prometheus Notification not send." }
|
63
|
+
end
|
64
|
+
session = (options[:session]) ? options[:session] : log.get_session
|
65
|
+
log.info "Sending metrics to Prometheus Pushgateway", session
|
66
|
+
@processes_target.each do |item|
|
67
|
+
missing = (item[:status] == :missing)? 1 : 0
|
68
|
+
log.item "Sending metrics for #{item[:process]}", session
|
69
|
+
val = (item[:status] == :running )? 1 : 0
|
70
|
+
@metric_status.set(val, labels: { process: item[:process] })
|
71
|
+
@metric_cpu_percent.set(item[:cpu], labels: { process: item[:process] })
|
72
|
+
@metric_mem_percent.set(item[:mem], labels: { process: item[:process] })
|
73
|
+
end
|
74
|
+
hostname = Socket.gethostname
|
75
|
+
url = @config.prometheus_pushgateway_url
|
76
|
+
Prometheus::Client::Push.new('Splash',hostname, url).add(@registry)
|
77
|
+
log.ok "Sending to Prometheus PushGateway done.", session
|
78
|
+
return {:case => :quiet_exit }
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
# base Splash module
|
4
|
+
module Splash
|
5
|
+
|
6
|
+
# Splash Commands module/namespace
|
7
|
+
module Sequences
|
8
|
+
|
9
|
+
include Splash::Commands
|
10
|
+
include Splash::Config
|
11
|
+
include Splash::Loggers
|
12
|
+
include Splash::Exiter
|
13
|
+
include Splash::Transports
|
14
|
+
|
15
|
+
def run_seq(params = {})
|
16
|
+
list = get_config.sequences
|
17
|
+
name = params[:name].to_sym
|
18
|
+
acase = {}
|
19
|
+
seq_res = []
|
20
|
+
log = get_logger
|
21
|
+
log.info "beginnning Sequence execution : #{name}"
|
22
|
+
session = (params[:session])? params[:session] : get_session
|
23
|
+
if list.include? name then
|
24
|
+
seq_options = (list[name][:options].nil?)? {} : list[name][:options]
|
25
|
+
list[name][:definition].each do |step|
|
26
|
+
log.info "STEP : #{step[:step]}",session
|
27
|
+
if step[:on_host].nil? then
|
28
|
+
command = CommandWrapper::new(step[:command].to_s)
|
29
|
+
step[:callback] = true if step[:callback].nil?
|
30
|
+
step[:trace] = true if step[:trace].nil?
|
31
|
+
step[:notify] = true if step[:notify].nil?
|
32
|
+
step[:session] = session
|
33
|
+
acase = command.call_and_notify step
|
34
|
+
else
|
35
|
+
log.info "Remote execution of #{step[:command]} on #{step[:on_host]}", session
|
36
|
+
begin
|
37
|
+
transport = get_default_client
|
38
|
+
if transport.class == Hash and transport.include? :case then
|
39
|
+
return transport
|
40
|
+
else
|
41
|
+
acase = transport.execute({ :verb => :execute_command,
|
42
|
+
payload: {:name => step[:command].to_s},
|
43
|
+
:return_to => "splash.#{Socket.gethostname}.return",
|
44
|
+
:queue => "splash.#{step[:on_host]}.input" })
|
45
|
+
log.receive "return with exitcode #{acase[:exit_code]}", session
|
46
|
+
end
|
47
|
+
rescue Interrupt
|
48
|
+
acase = { case: :interrupt, more: "Remote command exection", exit_code: 33}
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
seq_res.push acase[:exit_code]
|
53
|
+
continue = (seq_options[:continue].nil?)? true : seq_options[:continue]
|
54
|
+
if acase[:exit_code] > 0 and continue == false then
|
55
|
+
acase[:more] = "Break execution on error, continue = false"
|
56
|
+
break
|
57
|
+
end
|
58
|
+
end
|
59
|
+
else
|
60
|
+
return { :case => :not_found, :more => "Sequence #{name} not configured" }
|
61
|
+
end
|
62
|
+
|
63
|
+
if seq_res.select {|res| res > 0}.count == seq_res.count then
|
64
|
+
acase = { case: :status_ko, more: "all execution failed" }
|
65
|
+
elsif seq_res.select {|res| res > 0}.count > 0 then
|
66
|
+
acase = { case: :status_ko, more: "some execution failed" }
|
67
|
+
else
|
68
|
+
acase = { case: :status_ok, more: "all execution successed" }
|
69
|
+
end
|
70
|
+
acase[:more] << " with remote call interrupt" if seq_res.include?(33)
|
71
|
+
return acase
|
72
|
+
end
|
73
|
+
|
74
|
+
|
75
|
+
def list_seq(options = {})
|
76
|
+
list = get_config.sequences
|
77
|
+
unless list.empty?
|
78
|
+
acase = { :case => :quiet_exit , :more => "List configured sequences"}
|
79
|
+
acase[:data] = list
|
80
|
+
return acase
|
81
|
+
else
|
82
|
+
return { :case => :not_found, :more => 'No sequences configured' }
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def show_seq(options = {})
|
87
|
+
list = get_config.sequences
|
88
|
+
name = options[:name].to_sym
|
89
|
+
if list.include? name then
|
90
|
+
acase = { :case => :quiet_exit, :more => "Show specific sequence : #{name}"}
|
91
|
+
acase[:data] = list[name]
|
92
|
+
else
|
93
|
+
return { :case => :not_found, :more => "Sequence #{name} not configured" }
|
94
|
+
end
|
95
|
+
return acase
|
96
|
+
end
|
97
|
+
|
98
|
+
def schedule_seq(options = {})
|
99
|
+
acase = { :case => :quiet_exit, :more => "schedule" }
|
100
|
+
return acase
|
101
|
+
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
105
|
+
end
|