prometheus-splash 0.5.0 → 0.5.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +31 -0
- data/config/splash.yml +2 -0
- data/lib/splash/backends/file.rb +4 -0
- data/lib/splash/backends/redis.rb +3 -3
- data/lib/splash/cli.rb +3 -1
- data/lib/splash/cli/commands.rb +14 -13
- data/lib/splash/cli/config.rb +7 -1
- data/lib/splash/cli/daemon.rb +2 -2
- data/lib/splash/cli/logs.rb +4 -3
- data/lib/splash/commands.rb +122 -120
- data/lib/splash/config.rb +5 -0
- data/lib/splash/config/flush.rb +22 -0
- data/lib/splash/constants.rb +4 -1
- data/lib/splash/daemon.rb +2 -0
- data/lib/splash/{controller.rb → daemon/controller.rb} +4 -4
- data/lib/splash/daemon/metrics.rb +78 -0
- data/lib/splash/{orchestrator.rb → daemon/orchestrator.rb} +35 -18
- data/lib/splash/daemon/orchestrator/grammar.rb +56 -0
- data/lib/splash/daemon/orchestrator/hooks.rb +18 -0
- data/lib/splash/dependencies.rb +2 -2
- data/lib/splash/helpers.rb +0 -2
- data/lib/splash/loggers.rb +11 -10
- data/lib/splash/loggers/dual.rb +21 -1
- data/lib/splash/logs.rb +56 -54
- data/templates/ansible-splash/roles/splash/handlers/main.yml +4 -0
- data/templates/ansible-splash/roles/splash/tasks/main.yml +24 -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
- metadata +10 -5
- data/lib/splash/orchestrator/grammar.rb +0 -54
- data/lib/splash/orchestrator/hooks.rb +0 -16
data/lib/splash/config.rb
CHANGED
@@ -21,6 +21,7 @@ module Splash
|
|
21
21
|
self[:prometheus_pushgateway_port] = (config_from_file[:prometheus][:pushgateway][:port])? config_from_file[:prometheus][:pushgateway][:port] : PROMETHEUS_PUSHGATEWAY_PORT
|
22
22
|
self[:daemon_process_name] = (config_from_file[:daemon][:process_name])? config_from_file[:daemon][:process_name] : DAEMON_PROCESS_NAME
|
23
23
|
self[:daemon_logmon_scheduling] = (config_from_file[:daemon][:logmon_scheduling])? config_from_file[:daemon][:logmon_scheduling] : DAEMON_LOGMON_SCHEDULING
|
24
|
+
self[:daemon_metrics_scheduling] = (config_from_file[:daemon][:metrics_scheduling])? config_from_file[:daemon][:metrics_scheduling] : DAEMON_METRICS_SCHEDULING
|
24
25
|
self[:execution_template_tokens] = EXECUTION_TEMPLATE_TOKENS_LIST
|
25
26
|
self[:execution_template_path] = (config_from_file[:templates][:execution][:path])? config_from_file[:templates][:execution][:path] : EXECUTION_TEMPLATE
|
26
27
|
self[:pid_path] = (config_from_file[:daemon][:paths][:pid_path])? config_from_file[:daemon][:paths][:pid_path] : DAEMON_PID_PATH
|
@@ -56,6 +57,10 @@ module Splash
|
|
56
57
|
return self[:daemon_logmon_scheduling]
|
57
58
|
end
|
58
59
|
|
60
|
+
def daemon_metrics_scheduling
|
61
|
+
return self[:daemon_metrics_scheduling]
|
62
|
+
end
|
63
|
+
|
59
64
|
def execution_template_path
|
60
65
|
return self[:execution_template_path]
|
61
66
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Splash
|
2
|
+
module ConfigUtilities
|
3
|
+
include Splash::Constants
|
4
|
+
|
5
|
+
|
6
|
+
def flush_backend(options ={})
|
7
|
+
config = get_config
|
8
|
+
self.extend Splash::Backends
|
9
|
+
self.extend Splash::Loggers
|
10
|
+
log = get_logger
|
11
|
+
log.info "Splash backend flushing"
|
12
|
+
name = (options[:name])? options[:name] : :execution_trace
|
13
|
+
backend = get_backend name
|
14
|
+
if backend.flush then
|
15
|
+
return { :case => :quiet_exit, :more => "Splash backend #{name.to_s} flushed" }
|
16
|
+
else
|
17
|
+
return { :case => :configuration_error, :more => "Splash backend #{name.to_s} can't be flushed" }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
data/lib/splash/constants.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
module Splash
|
3
3
|
module Constants
|
4
|
-
VERSION = "0.5.
|
4
|
+
VERSION = "0.5.2"
|
5
5
|
|
6
6
|
# the path to th config file, not overridable by config
|
7
7
|
CONFIG_FILE = "/etc/splash.yml"
|
@@ -11,6 +11,9 @@ module Splash
|
|
11
11
|
|
12
12
|
# default scheduling criteria for log monitoring
|
13
13
|
DAEMON_LOGMON_SCHEDULING={ :every => '20s'}
|
14
|
+
# default scheduling criteria for log metrics notifications
|
15
|
+
DAEMON_METRICS_SCHEDULING={ :every => '20s'}
|
16
|
+
|
14
17
|
# the display name of daemon in proc info (ps/top)
|
15
18
|
DAEMON_PROCESS_NAME="Splash : daemon."
|
16
19
|
# the default pid file path
|
@@ -1,13 +1,13 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
module Splash
|
3
|
-
module
|
4
|
-
module
|
3
|
+
module Daemon
|
4
|
+
module Controller
|
5
5
|
include Splash::Constants
|
6
6
|
include Splash::Helpers
|
7
7
|
include Splash::Config
|
8
|
-
include Splash::Orchestrator
|
9
8
|
include Splash::Exiter
|
10
9
|
include Splash::Loggers
|
10
|
+
include Splash::Daemon::Orchestrator
|
11
11
|
|
12
12
|
def startdaemon(options = {})
|
13
13
|
config = get_config
|
@@ -43,7 +43,7 @@ module Splash
|
|
43
43
|
:foreground => options[:foreground]
|
44
44
|
}
|
45
45
|
|
46
|
-
["int","term","hup"].each do |type| daemon_config["sig#{type}_handler".to_sym] = Proc::new { ObjectSpace.each_object(Splash::Orchestrator::Scheduler).first.shutdown } end
|
46
|
+
["int","term","hup"].each do |type| daemon_config["sig#{type}_handler".to_sym] = Proc::new { ObjectSpace.each_object(Splash::Daemon::Orchestrator::Scheduler).first.shutdown } end
|
47
47
|
res = daemonize daemon_config do
|
48
48
|
Scheduler::new options
|
49
49
|
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
module Splash
|
2
|
+
module Daemon
|
3
|
+
module Metrics
|
4
|
+
include Splash::Constants
|
5
|
+
include Splash::Helpers
|
6
|
+
include Splash::Config
|
7
|
+
include Splash::Loggers
|
8
|
+
|
9
|
+
@@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
|
+
class Manager
|
19
|
+
|
20
|
+
attr_reader :execution_count
|
21
|
+
attr_reader :monitoring_count
|
22
|
+
|
23
|
+
def initialize
|
24
|
+
@config = get_config
|
25
|
+
@starttime = Time.now
|
26
|
+
@execution_count = 0
|
27
|
+
@monitoring_count = 0
|
28
|
+
|
29
|
+
@registry = Prometheus::Client::Registry::new
|
30
|
+
@metric_uptime = Prometheus::Client::Gauge.new(:splash_uptime, docstring: 'SPLASH self metric uptime')
|
31
|
+
@metric_execution = Prometheus::Client::Gauge.new(:splash_execution, docstring: 'SPLASH self metric total commands execution count')
|
32
|
+
@metric_monitoring = Prometheus::Client::Gauge.new(:splash_monitoring, docstring: 'SPLASH self metric total logs monitoring count')
|
33
|
+
@registry.register(@metric_uptime)
|
34
|
+
@registry.register(@metric_execution)
|
35
|
+
@registry.register(@metric_monitoring)
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
def uptime
|
40
|
+
return Time.now - @starttime
|
41
|
+
end
|
42
|
+
|
43
|
+
def inc_execution
|
44
|
+
@execution_count += 1
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
def inc_monitoring
|
49
|
+
@monitoring_count += 1
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
def notify
|
54
|
+
log = get_logger
|
55
|
+
session = get_session
|
56
|
+
unless verify_service host: @config.prometheus_pushgateway_host ,port: @config.prometheus_pushgateway_port then
|
57
|
+
return { :case => :service_dependence_missing, :more => "Prometheus Notification not send." }
|
58
|
+
end
|
59
|
+
|
60
|
+
log.debug "Sending Splash self metrics to PushGateway." , session
|
61
|
+
@metric_uptime.set uptime
|
62
|
+
@metric_execution.set execution_count
|
63
|
+
@metric_monitoring.set monitoring_count
|
64
|
+
hostname = Socket.gethostname
|
65
|
+
url = "http://#{@config.prometheus_pushgateway_host}:#{@config.prometheus_pushgateway_port}"
|
66
|
+
Prometheus::Client::Push.new('Splash',hostname, url).add(@registry)
|
67
|
+
log.debug "Sending to Prometheus PushGateway done.", session
|
68
|
+
return {:case => :quiet_exit }
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -1,21 +1,25 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
Dir[File.dirname(__FILE__) + '/orchestrator/*.rb'].each {|file| require file }
|
3
3
|
|
4
|
-
|
5
|
-
|
6
4
|
module Splash
|
7
|
-
module
|
5
|
+
module Daemon
|
6
|
+
module Orchestrator
|
8
7
|
|
9
|
-
|
8
|
+
class Scheduler
|
10
9
|
include Splash::Constants
|
11
10
|
include Splash::Helpers
|
12
11
|
include Splash::Config
|
13
12
|
include Splash::Transports
|
14
|
-
include Splash::Orchestrator::Grammar
|
13
|
+
include Splash::Daemon::Orchestrator::Grammar
|
15
14
|
include Splash::Loggers
|
15
|
+
include Splash::Logs
|
16
|
+
include Splash::Commands
|
17
|
+
|
16
18
|
|
17
19
|
def initialize(options = {})
|
18
20
|
@log = get_logger
|
21
|
+
self.extend Splash::Daemon::Metrics
|
22
|
+
@metric_manager = get_metrics_manager
|
19
23
|
$stdout.sync = true
|
20
24
|
$stderr.sync = true
|
21
25
|
@server = Rufus::Scheduler::new
|
@@ -32,6 +36,7 @@ module Splash
|
|
32
36
|
@server.send sched,value do
|
33
37
|
begin
|
34
38
|
session = get_session
|
39
|
+
@metric_manager.inc_monitoring
|
35
40
|
@log.trigger "Logs monitoring for Scheduling : #{sched.to_s} #{value.to_s}", session
|
36
41
|
@result.analyse
|
37
42
|
@result.notify :session => session
|
@@ -39,6 +44,18 @@ module Splash
|
|
39
44
|
@log.error "PushGateway seems to be done, please start it.", session
|
40
45
|
end
|
41
46
|
end
|
47
|
+
|
48
|
+
sched,value = @config.daemon_metrics_scheduling.flatten
|
49
|
+
|
50
|
+
@log.item "Initializing Splash metrics notifications."
|
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
|
58
|
+
|
42
59
|
hostname = Socket.gethostname
|
43
60
|
transport = get_default_subscriber queue: "splash.#{hostname}.input"
|
44
61
|
if transport.class == Hash and transport.include? :case then
|
@@ -69,32 +86,32 @@ module Splash
|
|
69
86
|
|
70
87
|
private
|
71
88
|
def init_commands_scheduling
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
end
|
89
|
+
config = get_config.commands
|
90
|
+
commands = config.select{|key,value| value.include? :schedule}.keys
|
91
|
+
commands.each do |command|
|
92
|
+
sched,value = config[command][:schedule].flatten
|
93
|
+
@log.arrow "Scheduling command #{command.to_s}"
|
94
|
+
@server.send sched,value do
|
95
|
+
session = get_session
|
96
|
+
@log.trigger "Executing Scheduled command #{command.to_s} for Scheduling : #{sched.to_s} #{value.to_s}", session
|
97
|
+
execute command: command.to_s, session: session
|
82
98
|
end
|
99
|
+
end
|
83
100
|
|
84
101
|
end
|
85
102
|
|
86
103
|
def execute(options)
|
87
|
-
command =
|
104
|
+
command = CommandWrapper::new(options[:command])
|
88
105
|
if options[:ack] then
|
89
106
|
command.ack
|
90
107
|
else
|
108
|
+
@metric_manager.inc_execution
|
91
109
|
return command.call_and_notify trace: true, notify: true, callback: true, session: options[:session]
|
92
110
|
end
|
93
111
|
end
|
94
112
|
|
95
113
|
end
|
96
114
|
|
97
|
-
|
98
115
|
end
|
99
|
-
|
100
116
|
end
|
117
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
module Splash
|
3
|
+
module Daemon
|
4
|
+
module Orchestrator
|
5
|
+
module Grammar
|
6
|
+
|
7
|
+
include Splash::Config
|
8
|
+
include Splash::Loggers
|
9
|
+
|
10
|
+
|
11
|
+
VERBS=[:ping,:list_commands,:execute_command,:ack_command, :shutdown]
|
12
|
+
|
13
|
+
|
14
|
+
def shutdown
|
15
|
+
terminate
|
16
|
+
end
|
17
|
+
|
18
|
+
def ping(content)
|
19
|
+
return "Pong : #{content[:payload][:hostname]} !"
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
def list_commands(content)
|
24
|
+
return get_config.commands
|
25
|
+
end
|
26
|
+
|
27
|
+
def ack_command(content)
|
28
|
+
return execute command: content[:payload][:name], ack: true
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
def execute_command(content)
|
33
|
+
payload = content[:payload]
|
34
|
+
unless get_config.commands.include? payload[:name].to_sym
|
35
|
+
@log.item "Command not found", content[:session]
|
36
|
+
return { :case => :not_found }
|
37
|
+
end
|
38
|
+
if payload.include? :schedule then
|
39
|
+
sched,value = payload[:schedule].flatten
|
40
|
+
@log.schedule "remote call command #{payload[:name]}, scheduling : #{sched.to_s} #{value}", content[:session]
|
41
|
+
@server.send sched,value do
|
42
|
+
@log.trigger "Executing Scheduled command #{payload[:name]} for Scheduling : #{sched.to_s} #{value}", content[:session]
|
43
|
+
execute command: payload[:name], session: content[:session]
|
44
|
+
end
|
45
|
+
return { :case => :quiet_exit }
|
46
|
+
else
|
47
|
+
@log.info "Execute direct command", content[:session]
|
48
|
+
res = execute command: payload[:name], session: content[:session]
|
49
|
+
return res
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
data/lib/splash/dependencies.rb
CHANGED
data/lib/splash/helpers.rb
CHANGED
data/lib/splash/loggers.rb
CHANGED
@@ -10,12 +10,12 @@ module Splash
|
|
10
10
|
def get_logger(options = {})
|
11
11
|
logger = (get_config.loggers[:list].include? options[:logger])? options[:logger].to_s : get_config.loggers[:default].to_s
|
12
12
|
aclass = "Splash::Loggers::#{logger.capitalize}"
|
13
|
-
|
13
|
+
begin
|
14
14
|
return @@logger = Kernel.const_get(aclass)::new if options[:force]
|
15
15
|
return @@logger ||= Kernel.const_get(aclass)::new
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
rescue
|
17
|
+
splash_exit case: :configuration_error, more: "Logger specified inexistant : #{logger}"
|
18
|
+
end
|
19
19
|
end
|
20
20
|
|
21
21
|
def get_session
|
@@ -24,19 +24,20 @@ module Splash
|
|
24
24
|
|
25
25
|
|
26
26
|
def change_logger(options = {})
|
27
|
+
level = get_logger.level
|
27
28
|
options[:force] = true
|
28
|
-
get_logger(options)
|
29
|
+
get_logger(options).level = level
|
29
30
|
end
|
30
31
|
|
31
|
-
|
32
|
+
LEVELS = [:debug, :warn, :info, :result, :fatal, :unknown]
|
33
|
+
ALIAS = {:flat => :info, :item => :info, :ok => :info, :ko => :info, :trigger => :info,
|
34
|
+
:schedule => :info, :arrow => :info, :send => :info,
|
35
|
+
:receive => :info, :error => :result, :success => :result }
|
32
36
|
|
33
37
|
class LoggerTemplate
|
34
38
|
include Splash::Config
|
35
39
|
|
36
|
-
|
37
|
-
ALIAS = {:flat => :info, :item => :info, :ok => :info, :ko => :info, :trigger => :info,
|
38
|
-
:schedule => :info, :arrow => :info, :send => :info,
|
39
|
-
:receive => :info, :error => :result, :success => :result }
|
40
|
+
|
40
41
|
LEVELS.each do |method|
|
41
42
|
define_method(method) do |message,session = ''|
|
42
43
|
self.log({ :level => method, :message => message, :session => session})
|
data/lib/splash/loggers/dual.rb
CHANGED
@@ -1,10 +1,22 @@
|
|
1
1
|
module Splash
|
2
2
|
module Loggers
|
3
3
|
|
4
|
-
class Dual
|
4
|
+
class Dual #< Splash::Loggers::LoggerTemplate
|
5
|
+
|
6
|
+
|
5
7
|
include Splash::Config
|
6
8
|
|
7
9
|
|
10
|
+
LEVELS.each do |method|
|
11
|
+
define_method(method) do |message,session = ''|
|
12
|
+
self.log({ :level => method, :message => message, :session => session})
|
13
|
+
end
|
14
|
+
end
|
15
|
+
ALIAS.keys.each do |method|
|
16
|
+
define_method(method) do |message,session = ''|
|
17
|
+
self.log({ :level => method, :message => message, :session => session})
|
18
|
+
end
|
19
|
+
end
|
8
20
|
|
9
21
|
def initialize
|
10
22
|
super
|
@@ -16,7 +28,15 @@ module Splash
|
|
16
28
|
@log1.log options
|
17
29
|
@log2.log options
|
18
30
|
end
|
31
|
+
def level
|
32
|
+
@level
|
33
|
+
end
|
19
34
|
|
35
|
+
def level=(level)
|
36
|
+
@level = level
|
37
|
+
@log1.level=level
|
38
|
+
@log2.level=level
|
39
|
+
end
|
20
40
|
end
|
21
41
|
end
|
22
42
|
end
|