prometheus-splash 0.5.3 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +58 -60
  3. data/bin/splash +3 -0
  4. data/config/splash.yml +15 -2
  5. data/lib/splash/backends.rb +6 -0
  6. data/lib/splash/backends/file.rb +36 -0
  7. data/lib/splash/backends/redis.rb +44 -1
  8. data/lib/splash/cli.rb +7 -3
  9. data/lib/splash/cli/commands.rb +11 -4
  10. data/lib/splash/cli/config.rb +9 -1
  11. data/lib/splash/cli/daemon.rb +8 -1
  12. data/lib/splash/cli/documentation.rb +5 -2
  13. data/lib/splash/cli/logs.rb +14 -6
  14. data/lib/splash/cli/process.rb +9 -0
  15. data/lib/splash/cli/webadmin.rb +46 -0
  16. data/lib/splash/commands.rb +23 -2
  17. data/lib/splash/config.rb +141 -1
  18. data/lib/splash/config/flush.rb +9 -1
  19. data/lib/splash/config/sanitycheck.rb +6 -1
  20. data/lib/splash/config/service.rb +8 -1
  21. data/lib/splash/config/setup.rb +8 -3
  22. data/lib/splash/constants.rb +30 -2
  23. data/lib/splash/daemon.rb +5 -1
  24. data/lib/splash/daemon/controller.rb +21 -1
  25. data/lib/splash/daemon/metrics.rb +22 -7
  26. data/lib/splash/daemon/orchestrator.rb +21 -3
  27. data/lib/splash/daemon/orchestrator/grammar.rb +25 -5
  28. data/lib/splash/daemon/orchestrator/hooks.rb +10 -0
  29. data/lib/splash/dependencies.rb +10 -1
  30. data/lib/splash/exiter.rb +14 -0
  31. data/lib/splash/helpers.rb +69 -45
  32. data/lib/splash/loggers.rb +30 -4
  33. data/lib/splash/loggers/cli.rb +18 -3
  34. data/lib/splash/loggers/daemon.rb +14 -3
  35. data/lib/splash/loggers/dual.rb +14 -1
  36. data/lib/splash/loggers/web.rb +51 -0
  37. data/lib/splash/logs.rb +15 -4
  38. data/lib/splash/processes.rb +17 -5
  39. data/lib/splash/templates.rb +10 -0
  40. data/lib/splash/transports.rb +9 -0
  41. data/lib/splash/transports/rabbitmq.rb +33 -3
  42. data/lib/splash/webadmin.rb +122 -0
  43. data/lib/splash/webadmin/api/routes/commands.rb +28 -0
  44. data/lib/splash/webadmin/api/routes/config.rb +10 -0
  45. data/lib/splash/webadmin/api/routes/init.rb +2 -0
  46. data/lib/splash/webadmin/api/routes/logs.rb +59 -0
  47. data/lib/splash/webadmin/api/routes/process.rb +60 -0
  48. data/lib/splash/webadmin/main.rb +26 -0
  49. data/lib/splash/webadmin/portal/controllers/commands.rb +7 -0
  50. data/lib/splash/webadmin/portal/controllers/documentation.rb +6 -0
  51. data/lib/splash/webadmin/portal/controllers/home.rb +12 -0
  52. data/lib/splash/webadmin/portal/controllers/logs.rb +14 -0
  53. data/lib/splash/webadmin/portal/controllers/notfound.rb +5 -0
  54. data/lib/splash/webadmin/portal/controllers/processes.rb +14 -0
  55. data/lib/splash/webadmin/portal/controllers/proxy.rb +30 -0
  56. data/lib/splash/webadmin/portal/controllers/restclient.rb +19 -0
  57. data/lib/splash/webadmin/portal/init.rb +11 -0
  58. data/lib/splash/webadmin/portal/public/css/ultragreen.css +8544 -0
  59. data/lib/splash/webadmin/portal/public/fonts/FontAwesome.otf +0 -0
  60. data/lib/splash/webadmin/portal/public/fonts/fontawesome-webfont.ttf +0 -0
  61. data/lib/splash/webadmin/portal/public/fonts/fontawesome-webfont.woff +0 -0
  62. data/lib/splash/webadmin/portal/public/fonts/fontawesome-webfont.woff2 +0 -0
  63. data/lib/splash/webadmin/portal/public/images/logo_splash.png +0 -0
  64. data/lib/splash/webadmin/portal/public/images/logo_splash_reduce.png +0 -0
  65. data/lib/splash/webadmin/portal/public/images/logo_splash_tiny.png +0 -0
  66. data/lib/splash/webadmin/portal/views/commands.slim +49 -0
  67. data/lib/splash/webadmin/portal/views/documentation.slim +3 -0
  68. data/lib/splash/webadmin/portal/views/home.slim +78 -0
  69. data/lib/splash/webadmin/portal/views/layout.slim +43 -0
  70. data/lib/splash/webadmin/portal/views/logs.slim +32 -0
  71. data/lib/splash/webadmin/portal/views/nav.slim +17 -0
  72. data/lib/splash/webadmin/portal/views/not_found.slim +3 -0
  73. data/lib/splash/webadmin/portal/views/processes.slim +29 -0
  74. data/lib/splash/webadmin/portal/views/proxy.slim +13 -0
  75. data/lib/splash/webadmin/portal/views/restclient.slim +41 -0
  76. data/lib/splash/webadmin/portal/views/restclient_result.slim +29 -0
  77. data/prometheus-splash.gemspec +6 -0
  78. data/spec/helpers_spec.rb +119 -0
  79. metadata +128 -5
@@ -1,8 +1,16 @@
1
+ # coding: utf-8
2
+
3
+ # Base Splash module
1
4
  module Splash
5
+
6
+ # module for Configuration utilities
2
7
  module ConfigUtilities
3
8
  include Splash::Constants
4
9
 
5
-
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)
6
14
  def flush_backend(options ={})
7
15
  config = get_config
8
16
  self.extend Splash::Backends
@@ -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
@@ -1,11 +1,18 @@
1
1
  # coding: utf-8
2
2
 
3
-
3
+ # Base Splash module
4
4
  module Splash
5
+
6
+ # moudle for Configuration utilities
5
7
  module ConfigUtilities
6
8
  include Splash::Constants
7
9
  include Splash::Helpers
8
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)
9
16
  def addservice(options = {})
10
17
  local_service_file = search_file_in_gem "prometheus-splash", "templates/splashd.service"
11
18
  config = get_config
@@ -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,7 +1,13 @@
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.5.3"
8
+
9
+ # Current splash version
10
+ VERSION = "0.6.0"
5
11
 
6
12
  # the path to th config file, not overridable by config
7
13
  CONFIG_FILE = "/etc/splash.yml"
@@ -40,6 +46,11 @@ module Splash
40
46
  PROMETHEUS_PUSHGATEWAY_HOST = "localhost"
41
47
  # the default prometheus pushgateway port
42
48
  PROMETHEUS_PUSHGATEWAY_PORT = "9091"
49
+ # the default prometheus pushgateway port
50
+ PROMETHEUS_PUSHGATEWAY_PATH = ''
51
+
52
+ # the default prometheus URL
53
+ PROMETHEUS_URL = "http://localhost:9090"
43
54
 
44
55
  # the default path fo execution report template
45
56
  EXECUTION_TEMPLATE="/etc/splash_execution_report.tpl"
@@ -55,11 +66,28 @@ module Splash
55
66
  :active => :rabbitmq,
56
67
  :rabbitmq => { :port => 5672, :host => "localhost", :vhost => '/'} }
57
68
 
58
- LOGGERS_STRUCT = { :list => [:cli,:daemon, :dual],
69
+ # loggers default settings
70
+ LOGGERS_STRUCT = { :list => [:cli,:daemon, :dual, :web],
59
71
  :default => :cli,
60
72
  :level => :info,
61
73
  :daemon => {:file => '/var/log/splash.log'},
74
+ :web => {:file => '/var/log/splash_web.log'},
62
75
  :cli => {:color => true, :emoji => true } }
63
76
 
77
+ WEBADMIN_IP = "127.0.0.1"
78
+ WEBADMIN_PORT = "9234"
79
+ WEBADMIN_PROXY = false
80
+ # the display name of daemon in proc info (ps/top)
81
+ WEBADMIN_PROCESS_NAME="Splash : WebAdmin."
82
+ # the default pid file path
83
+ WEBADMIN_PID_PATH="/var/run"
84
+ # the default pid file name
85
+ WEBADMIN_PID_FILE="splash.pid"
86
+ # the default sdtout trace file
87
+ WEBADMIN_STDOUT_TRACE="stdout.txt"
88
+ # the default sdterr trace file
89
+ WEBADMIN_STDERR_TRACE="stderr.txt"
90
+
91
+
64
92
  end
65
93
  end
@@ -1,2 +1,6 @@
1
1
  # coding: utf-8
2
- Dir[File.dirname(__FILE__) + '/daemon/*.rb'].each {|file| require file }
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,6 +16,12 @@ 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
@@ -43,7 +56,7 @@ module Splash
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.shutdown } end
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
@@ -61,6 +74,10 @@ 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
@@ -80,6 +97,9 @@ module Splash
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
@@ -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,20 +14,24 @@ 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]
17
+
18
+ # metrics manager factory
19
+ # @return [Splash::Daemon::Metrics::Manager]
13
20
  def get_metrics_manager
14
21
  return @@manager ||= Manager::new
15
22
  end
16
23
 
17
-
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
29
+ # metric : logs monitoring count during Splash daemon uptime
21
30
  attr_reader :monitoring_logs_count
31
+ # metric : processes monitoring count during Splash daemon uptime
22
32
  attr_reader :monitoring_processes_count
23
33
 
34
+ # Constructor prepare prometheus-client, defined metrics and init attributes
24
35
  def initialize
25
36
  @config = get_config
26
37
  @starttime = Time.now
@@ -40,24 +51,28 @@ module Splash
40
51
  @registry.register(@metric_processes_monitoring)
41
52
  end
42
53
 
43
-
54
+ # virtual accessor uptime
44
55
  def uptime
45
56
  return Time.now - @starttime
46
57
  end
47
58
 
59
+ # increment metric : execution_count
48
60
  def inc_execution
49
61
  @execution_count += 1
50
62
  end
51
63
 
52
-
64
+ # increment metric : monitoring_logs_count
53
65
  def inc_logs_monitoring
54
66
  @monitoring_logs_count += 1
55
67
  end
56
68
 
69
+ # increment metric : monitoring_processes_count
57
70
  def inc_processes_monitoring
58
71
  @monitoring_processes_count += 1
59
72
  end
60
73
 
74
+ # Send metrics to Prometheus PushGateway
75
+ # @return [Hash] Exiter case ( :service_dependence_missing , :quiet_exit)
61
76
  def notify
62
77
  log = get_logger
63
78
  session = get_session
@@ -72,7 +87,7 @@ module Splash
72
87
  @metric_processes_monitoring.set monitoring_processes_count
73
88
 
74
89
  hostname = Socket.gethostname
75
- url = "http://#{@config.prometheus_pushgateway_host}:#{@config.prometheus_pushgateway_port}"
90
+ url = "http://#{@config.prometheus_pushgateway_host}:#{@config.prometheus_pushgateway_port}/#{@config.prometheus_pushgateway_path}"
76
91
  Prometheus::Client::Push.new('Splash',hostname, url).add(@registry)
77
92
  log.debug "Sending to Prometheus PushGateway done.", session
78
93
  return {:case => :quiet_exit }
@@ -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
@@ -16,7 +22,12 @@ module Splash
16
22
  include Splash::Processes
17
23
  include Splash::Commands
18
24
 
19
-
25
+ # Constructor prepare the Scheduler
26
+ # commands Schedules
27
+ # logs monitorings
28
+ # process monitorings
29
+ # @param [Hash] options
30
+ # @option options [Symbol] :scheduling activate commands scheduling
20
31
  def initialize(options = {})
21
32
  @log = get_logger
22
33
  self.extend Splash::Daemon::Metrics
@@ -103,6 +114,8 @@ module Splash
103
114
  end
104
115
  end
105
116
 
117
+ # Stop the Splash daemon gracefully
118
+ # @return [hash] Exiter Case :quiet_exit
106
119
  def terminate
107
120
  @log.info "Splash daemon shutdown"
108
121
  @server.shutdown
@@ -111,6 +124,7 @@ module Splash
111
124
  end
112
125
 
113
126
  private
127
+ # prepare commands Scheduling
114
128
  def init_commands_scheduling
115
129
  config = get_config.commands
116
130
  commands = config.select{|key,value| value.include? :schedule}.keys
@@ -126,10 +140,14 @@ module Splash
126
140
 
127
141
  end
128
142
 
143
+ # execute_command verb : execute command specified in payload
144
+ # @param [Hash] options
145
+ # @option options [Symbol] :command the name of the command
146
+ # @option options [Symbol] :ack ack flag to inhibit execution and send ack to Prometheus (0)
147
+ # @return [Hash] Exiter case
129
148
  def execute(options)
130
149
  command = CommandWrapper::new(options[:command])
131
- if options[:ack] then
132
- command.ack
150
+ if options[:ack] then
133
151
  else
134
152
  @metric_manager.inc_execution
135
153
  return command.call_and_notify trace: true, notify: true, callback: true, session: options[:session]
@@ -1,34 +1,54 @@
1
1
  # coding: utf-8
2
+
3
+ # base Splash module
2
4
  module Splash
5
+
6
+ # global daemon module
3
7
  module Daemon
8
+
9
+ # orchestrator specific module
4
10
  module Orchestrator
11
+
12
+ # Orchestrator grammar method defiition module
5
13
  module Grammar
6
14
 
7
15
  include Splash::Config
8
16
  include Splash::Loggers
9
17
 
10
-
18
+ # list of known verbs for Splash orchestrator
11
19
  VERBS=[:ping,:list_commands,:execute_command,:ack_command, :shutdown]
12
20
 
13
-
14
- def shutdown
21
+ # shutdown verb : stop the Splash daemon gracefully
22
+ # @param [Hash] content message content Hash Structure, ignored
23
+ # @return [Hash] Exiter Case :quiet_exit
24
+ def shutdown(content)
15
25
  terminate
16
26
  end
17
27
 
28
+ # ping verb : return pong to hostname precise in payload
29
+ # @param [Hash] content message content Hash Structure, include mandatory payload[:hostname]
30
+ # @return [String] the pong
18
31
  def ping(content)
19
32
  return "Pong : #{content[:payload][:hostname]} !"
20
33
  end
21
34
 
22
-
35
+ # list_commands verb : return the list of specified commands in local Splash
36
+ # @param [Hash] content message content Hash Structure, ignored
37
+ # @return [Hash] structure of commands
23
38
  def list_commands(content)
24
39
  return get_config.commands
25
40
  end
26
41
 
42
+ # ack_command verb : send ack to Prometheus, for command specified in payload
43
+ # @param [Hash] content message content Hash Structure, include mandatory payload[:name]
44
+ # @return [Hash] Exiter case
27
45
  def ack_command(content)
28
46
  return execute command: content[:payload][:name], ack: true
29
47
  end
30
48
 
31
-
49
+ # execute_command verb : execute command specified in payload
50
+ # @param [Hash] content message content Hash Structure, include mandatory payload[:name]
51
+ # @return [Hash] Exiter case
32
52
  def execute_command(content)
33
53
  payload = content[:payload]
34
54
  unless get_config.commands.include? payload[:name].to_sym
@@ -1,13 +1,23 @@
1
1
  # coding: utf-8
2
+
3
+ # base Splash module
2
4
  module Splash
5
+
6
+ # global daemon module
3
7
  module Daemon
8
+
9
+ # orchestrator specific module
4
10
  module Orchestrator
5
11
 
12
+ # Rufus Scheduler Hooks
6
13
  module SchedulerHooks
14
+
15
+ # not yet implemented
7
16
  def on_pre_trigger(job, trigger_time)
8
17
 
9
18
  end
10
19
 
20
+ # not yet implemented
11
21
  def on_post_trigger(job, trigger_time)
12
22
 
13
23
  end
@@ -12,6 +12,7 @@ module Splash
12
12
  require 'fileutils'
13
13
  require 'etc'
14
14
  require 'forwardable'
15
+ require 'json'
15
16
 
16
17
 
17
18
 
@@ -27,6 +28,13 @@ module Splash
27
28
  require 'colorize'
28
29
  require "redis"
29
30
  require 'ps-ruby'
31
+ require 'sinatra/base'
32
+ require 'thin'
33
+ require 'slim'
34
+ require 'rest-client'
35
+ require 'kramdown'
36
+ require 'rack/reverse_proxy'
37
+
30
38
 
31
39
  rescue Gem::GemNotFoundException
32
40
  $stderr.puts "Loadind error, it's like you try to run Splash, with a lake of dependencies."
@@ -49,8 +57,9 @@ module Splash
49
57
  require 'splash/commands'
50
58
  require 'splash/logs'
51
59
  require 'splash/processes'
52
-
60
+
53
61
  require 'splash/daemon'
62
+ require 'splash/webadmin'
54
63
 
55
64
 
56
65
  end