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.
@@ -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
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
2
  module Splash
3
3
  module Constants
4
- VERSION = "0.5.0"
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
@@ -0,0 +1,2 @@
1
+ # coding: utf-8
2
+ Dir[File.dirname(__FILE__) + '/daemon/*.rb'].each {|file| require file }
@@ -1,13 +1,13 @@
1
1
  # coding: utf-8
2
2
  module Splash
3
- module LogsMonitor
4
- module DaemonController
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 Orchestrator
5
+ module Daemon
6
+ module Orchestrator
8
7
 
9
- class Scheduler
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
- config = get_config.commands
73
- commands = config.select{|key,value| value.include? :schedule}.keys
74
- commands.each do |command|
75
- sched,value = config[command][:schedule].flatten
76
- @log.arrow "Scheduling command #{command.to_s}"
77
- @server.send sched,value do
78
- session = get_session
79
- @log.trigger "Executing Scheduled command #{command.to_s} for Scheduling : #{sched.to_s} #{value.to_s}", session
80
- execute command: command.to_s, session: session
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 = Splash::CommandWrapper::new(options[: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
@@ -0,0 +1,18 @@
1
+ # coding: utf-8
2
+ module Splash
3
+ module Daemon
4
+ module Orchestrator
5
+
6
+ module SchedulerHooks
7
+ def on_pre_trigger(job, trigger_time)
8
+
9
+ end
10
+
11
+ def on_post_trigger(job, trigger_time)
12
+
13
+ end
14
+
15
+ end
16
+ end
17
+ end
18
+ end
@@ -48,8 +48,8 @@ module Splash
48
48
 
49
49
  require 'splash/commands'
50
50
  require 'splash/logs'
51
- require 'splash/orchestrator'
52
- require 'splash/controller'
51
+ require 'splash/daemon'
52
+
53
53
 
54
54
  end
55
55
  end
@@ -159,9 +159,7 @@ module Splash
159
159
  if options[:foreground]
160
160
  change_logger logger: :dual
161
161
  Process.setproctitle options[:description] if options[:description]
162
- p $0
163
162
  return yield
164
- p 'titi'
165
163
  end
166
164
  fork do
167
165
  change_logger logger: :daemon
@@ -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
- # begin
13
+ begin
14
14
  return @@logger = Kernel.const_get(aclass)::new if options[:force]
15
15
  return @@logger ||= Kernel.const_get(aclass)::new
16
- # rescue
17
- # splash_exit case: :configuration_error, more: "Logger specified inexistant : #{logger}"
18
- # end
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
- LEVELS = [:debug, :warn, :info, :result, :fatal, :unknown]
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})
@@ -1,10 +1,22 @@
1
1
  module Splash
2
2
  module Loggers
3
3
 
4
- class Dual < Splash::Loggers::LoggerTemplate
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