prometheus-splash 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +31 -1
- data/bin/splash +6 -364
- data/lib/splash/backends.rb +1 -0
- data/lib/splash/backends/file.rb +1 -0
- data/lib/splash/backends/redis.rb +1 -3
- data/lib/splash/cli.rb +20 -0
- data/lib/splash/cli/commands.rb +164 -0
- data/lib/splash/cli/config.rb +37 -0
- data/lib/splash/cli/daemon.rb +52 -0
- data/lib/splash/cli/documentation.rb +24 -0
- data/lib/splash/cli/logs.rb +72 -0
- data/lib/splash/commands.rb +10 -15
- data/lib/splash/config.rb +7 -9
- data/lib/splash/constants.rb +2 -1
- data/lib/splash/controller.rb +12 -24
- data/lib/splash/dependencies.rb +51 -0
- data/lib/splash/exiter.rb +52 -0
- data/lib/splash/helpers.rb +2 -8
- data/lib/splash/logs.rb +4 -5
- data/lib/splash/orchestrator.rb +4 -5
- data/lib/splash/templates.rb +1 -0
- data/lib/splash/transports.rb +1 -0
- data/lib/splash/transports/rabbitmq.rb +1 -4
- data/prometheus-splash.gemspec +3 -1
- metadata +38 -2
data/lib/splash/config.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
# coding: utf-8
|
2
2
|
module Splash
|
3
3
|
module Config
|
4
4
|
include Splash::Helpers
|
@@ -175,11 +175,10 @@ module Splash
|
|
175
175
|
end
|
176
176
|
|
177
177
|
if full_res > 0 then
|
178
|
-
$stderr.puts "
|
179
|
-
return
|
178
|
+
$stderr.puts " => #{full_res} errors occured"
|
179
|
+
return { :case => :splash_setup_error}
|
180
180
|
else
|
181
|
-
|
182
|
-
return 0
|
181
|
+
return { :case => :splash_setup_success }
|
183
182
|
end
|
184
183
|
|
185
184
|
end
|
@@ -230,11 +229,10 @@ module Splash
|
|
230
229
|
end
|
231
230
|
|
232
231
|
if full_res > 0 then
|
233
|
-
$stderr.puts "
|
234
|
-
return
|
232
|
+
$stderr.puts " => #{full_res} errors occured"
|
233
|
+
return { :case => :splash_sanitycheck_error }
|
235
234
|
else
|
236
|
-
|
237
|
-
return 0
|
235
|
+
return { :case => :splash_sanitycheck_success}
|
238
236
|
end
|
239
237
|
end
|
240
238
|
|
data/lib/splash/constants.rb
CHANGED
data/lib/splash/controller.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
# coding: utf-8
|
2
2
|
module Splash
|
3
3
|
module LogsMonitor
|
4
4
|
module DaemonController
|
@@ -10,9 +10,7 @@ module Splash
|
|
10
10
|
def startdaemon(options = {})
|
11
11
|
config = get_config
|
12
12
|
unless verify_service host: config.prometheus_pushgateway_host ,port: config.prometheus_pushgateway_port then
|
13
|
-
|
14
|
-
$stderr.puts " please start before running Splash daemon."
|
15
|
-
exit 11
|
13
|
+
return {:case => :service_dependence_missing, :more => 'Prometheus Gateway'}
|
16
14
|
end
|
17
15
|
|
18
16
|
unless File::exist? config.full_pid_path then
|
@@ -25,36 +23,31 @@ module Splash
|
|
25
23
|
if res == 0 then
|
26
24
|
pid = `cat #{config.full_pid_path}`.to_i
|
27
25
|
puts "Splash Daemon Started, with PID : #{pid}"
|
26
|
+
return {:case => :quiet_exit}
|
28
27
|
else
|
29
|
-
|
28
|
+
return {:case => :unknown_error, :more => "Splash Daemon loading error"}
|
30
29
|
end
|
31
|
-
return res
|
32
30
|
|
33
31
|
else
|
34
|
-
|
35
|
-
return 14
|
32
|
+
return {:case => :already_exist, :more => "Pid File, please verify if Splash daemon is running."}
|
36
33
|
end
|
37
34
|
end
|
38
35
|
|
39
36
|
def stopdaemon(options = {})
|
40
37
|
config = get_config
|
41
|
-
errorcode = 0
|
42
38
|
if File.exist?(config.full_pid_path) then
|
43
|
-
|
44
39
|
begin
|
45
40
|
pid = `cat #{config.full_pid_path}`.to_i
|
46
41
|
Process.kill("TERM", pid)
|
47
|
-
|
42
|
+
acase = {:case => :quiet_exit, :more => 'Splash stopped succesfully'}
|
48
43
|
rescue Errno::ESRCH
|
49
|
-
|
50
|
-
errorcode = 12
|
44
|
+
acase = {:case => :not_found, :more => "Process of PID : #{pid} not found"}
|
51
45
|
end
|
52
46
|
FileUtils::rm config.full_pid_path if File::exist? config.full_pid_path
|
53
47
|
else
|
54
|
-
|
55
|
-
errorcode = 13
|
48
|
+
acase = {:case => :not_found, :more => "Splash is not running"}
|
56
49
|
end
|
57
|
-
return
|
50
|
+
return acase
|
58
51
|
end
|
59
52
|
|
60
53
|
def statusdaemon
|
@@ -75,16 +68,11 @@ module Splash
|
|
75
68
|
puts "and PID file don't exist"
|
76
69
|
end
|
77
70
|
if pid == realpid then
|
78
|
-
|
79
|
-
return 0
|
71
|
+
return {:case => :status_ok }
|
80
72
|
elsif pid.empty? then
|
81
|
-
|
82
|
-
$stderr.puts "Status KO"
|
83
|
-
return 16
|
73
|
+
return {:case => :status_ko, :more => "PID File error, you have to kill process manualy, with : '(sudo )kill -TERM #{realpid}'"}
|
84
74
|
elsif realpid.empty? then
|
85
|
-
|
86
|
-
$stderr.puts "Status KO"
|
87
|
-
return 17
|
75
|
+
return {:case => :status_ko, :more => "Process Splash Dameon missing, run 'splash daemon stop' to reload properly"}
|
88
76
|
end
|
89
77
|
end
|
90
78
|
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
module Splash
|
3
|
+
module Dependencies
|
4
|
+
|
5
|
+
|
6
|
+
# Internal Ruby
|
7
|
+
require 'open3'
|
8
|
+
require 'date'
|
9
|
+
require 'socket'
|
10
|
+
require 'yaml'
|
11
|
+
require 'thread'
|
12
|
+
require 'fileutils'
|
13
|
+
require 'etc'
|
14
|
+
require 'forwardable'
|
15
|
+
|
16
|
+
|
17
|
+
|
18
|
+
# Rubygems
|
19
|
+
begin
|
20
|
+
require 'prometheus/client'
|
21
|
+
require 'prometheus/client/push'
|
22
|
+
require 'thor'
|
23
|
+
require 'bunny'
|
24
|
+
require 'rufus-scheduler'
|
25
|
+
require 'tty-markdown'
|
26
|
+
require 'tty-pager'
|
27
|
+
require "redis"
|
28
|
+
|
29
|
+
rescue Gem::GemNotFoundException
|
30
|
+
$stderr.puts "Loadind error, it's like you try to run Splash, with a lake of dependencies."
|
31
|
+
$stderr.puts "If you run on RVM, please run with rvmsudo and not with sudo."
|
32
|
+
$stderr.puts "If problem is percistant, please, proceed to new install and Setup."
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
# Splash
|
37
|
+
require 'splash/constants'
|
38
|
+
require 'splash/helpers'
|
39
|
+
require 'splash/config'
|
40
|
+
require 'splash/exiter'
|
41
|
+
require 'splash/templates'
|
42
|
+
require 'splash/backends'
|
43
|
+
require 'splash/transports'
|
44
|
+
|
45
|
+
require 'splash/commands'
|
46
|
+
require 'splash/logs'
|
47
|
+
require 'splash/orchestrator'
|
48
|
+
require 'splash/controller'
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Splash
|
2
|
+
module Exiter
|
3
|
+
EXIT_MAP= {
|
4
|
+
|
5
|
+
# context execution
|
6
|
+
:not_root => {:message => "This operation need to be run as root (use sudo or rvmsudo)", :code => 10},
|
7
|
+
:options_incompatibility => {:message => "Options incompatibility", :code => 40},
|
8
|
+
:service_dependence_missing => {:message => "Splash Service dependence missing", :code => 60},
|
9
|
+
|
10
|
+
# config
|
11
|
+
:specific_config_required => {:message => "Specific configuration required", :code => 30},
|
12
|
+
:splash_setup_error => {:message => "Splash Setup terminated unsuccessfully", :code => 25},
|
13
|
+
:splash_setup_success => {:message => "Splash Setup terminated successfully", :code => 0},
|
14
|
+
:splash_sanitycheck_error => {:message => "Splash Sanitycheck terminated unsuccessfully", :code => 20},
|
15
|
+
:splash_sanitycheck_success => {:message => "Splash Sanitycheck terminated successfully", :code => 0},
|
16
|
+
:configuration_error => {:message => "Splash Configuration Error", :code => 50},
|
17
|
+
|
18
|
+
|
19
|
+
# global
|
20
|
+
:quiet_exit => {:code => 0},
|
21
|
+
|
22
|
+
# events
|
23
|
+
:interrupt => {:message => "Splash user operation interrupted", :code => 33},
|
24
|
+
|
25
|
+
# request
|
26
|
+
:not_found => {:message => "Object not found", :code => 44},
|
27
|
+
:already_exist => {:message => "Object already exist", :code => 48},
|
28
|
+
|
29
|
+
# daemon
|
30
|
+
:status_ok => {:message => "Status OK", :code => 0},
|
31
|
+
:status_ko => {:message => "Status KO", :code => 31}
|
32
|
+
|
33
|
+
}
|
34
|
+
|
35
|
+
def splash_exit(options = {})
|
36
|
+
mess = ""
|
37
|
+
mess = EXIT_MAP[options[:case]][:message] if EXIT_MAP[options[:case]].include? :message
|
38
|
+
mess << " : " unless mess.empty? or not options[:more]
|
39
|
+
mess << "#{options[:more]}" if options[:more]
|
40
|
+
if EXIT_MAP[options[:case]][:code] == 0 then
|
41
|
+
puts mess unless mess.empty?
|
42
|
+
exit 0
|
43
|
+
else
|
44
|
+
$stderr.puts mess unless mess.empty?
|
45
|
+
exit EXIT_MAP[options[:case]][:code]
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
data/lib/splash/helpers.rb
CHANGED
@@ -1,7 +1,3 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
require 'fileutils'
|
3
|
-
require 'etc'
|
4
|
-
|
5
1
|
# coding: utf-8
|
6
2
|
module Splash
|
7
3
|
module Helpers
|
@@ -35,11 +31,9 @@ module Splash
|
|
35
31
|
# facilité pour s'assurer qu'on execute une méthode avec les droits root
|
36
32
|
# @param [Symbol] method a method name th wrap
|
37
33
|
# @return [void] le retour de la méthode wrappée
|
38
|
-
def run_as_root(method)
|
34
|
+
def run_as_root(method, options = {})
|
39
35
|
unless is_root?
|
40
|
-
|
41
|
-
$stderr.puts "Please execute with sudo, or rvmsudo."
|
42
|
-
exit 10
|
36
|
+
return {:case => :not_root, :more => "subcommands : #{method.to_s}"}
|
43
37
|
else
|
44
38
|
return self.send method
|
45
39
|
end
|
data/lib/splash/logs.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# coding: utf-8
|
3
2
|
module Splash
|
4
3
|
class LogScanner
|
5
4
|
include Splash::Constants
|
@@ -34,6 +33,7 @@ module Splash
|
|
34
33
|
record[:status] = :missing
|
35
34
|
end
|
36
35
|
end
|
36
|
+
return {:case => :quiet_exit }
|
37
37
|
end
|
38
38
|
|
39
39
|
# pseudo-accessor on @logs_target
|
@@ -44,9 +44,7 @@ module Splash
|
|
44
44
|
# start notification on prometheus for metric logerrors, logmissing; loglines
|
45
45
|
def notify
|
46
46
|
unless verify_service host: @config.prometheus_pushgateway_host ,port: @config.prometheus_pushgateway_port then
|
47
|
-
|
48
|
-
$stderr.puts "Exit without notification."
|
49
|
-
exit 30
|
47
|
+
return { :case => :service_dependence_missing, :more => "Prometheus Notification not send." }
|
50
48
|
end
|
51
49
|
puts "Sending metrics to Prometheus Pushgateway"
|
52
50
|
@logs_target.each do |item|
|
@@ -61,6 +59,7 @@ module Splash
|
|
61
59
|
url = "http://#{@config.prometheus_pushgateway_host}:#{@config.prometheus_pushgateway_port}"
|
62
60
|
Prometheus::Client::Push.new('Splash',hostname, url).add(@registry)
|
63
61
|
puts "Sending done."
|
62
|
+
return {:case => :quiet_exit }
|
64
63
|
end
|
65
64
|
|
66
65
|
end
|
data/lib/splash/orchestrator.rb
CHANGED
@@ -1,6 +1,4 @@
|
|
1
|
-
|
2
|
-
require 'yaml'
|
3
|
-
|
1
|
+
# coding: utf-8
|
4
2
|
module Splash
|
5
3
|
module Orchestrator
|
6
4
|
|
@@ -35,7 +33,6 @@ module Splash
|
|
35
33
|
end
|
36
34
|
end
|
37
35
|
|
38
|
-
|
39
36
|
class Scheduler
|
40
37
|
include Splash::Constants
|
41
38
|
include Splash::Helpers
|
@@ -46,8 +43,10 @@ module Splash
|
|
46
43
|
@server = Rufus::Scheduler::new
|
47
44
|
@server.extend SchedulerHooks
|
48
45
|
@server.init_log
|
46
|
+
@config = get_config
|
49
47
|
@result = LogScanner::new
|
50
|
-
@
|
48
|
+
sched,value = @config.daemon_logmon_scheduling.flatten
|
49
|
+
@server.send sched,value do
|
51
50
|
begin
|
52
51
|
puts "Notify"
|
53
52
|
@result.analyse
|
data/lib/splash/templates.rb
CHANGED
data/lib/splash/transports.rb
CHANGED
data/prometheus-splash.gemspec
CHANGED
@@ -23,7 +23,9 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_runtime_dependency 'prometheus-client','~> 2.0.0'
|
24
24
|
spec.add_runtime_dependency 'rufus-scheduler','~> 3.6.0'
|
25
25
|
spec.add_runtime_dependency 'redis','~> 4.1.3'
|
26
|
-
spec.add_runtime_dependency 'bunny','~> 2.15.0'
|
26
|
+
spec.add_runtime_dependency 'bunny','~> 2.15.0'
|
27
|
+
spec.add_runtime_dependency 'tty-markdown','~> 0.6.0'
|
28
|
+
spec.add_runtime_dependency 'tty-pager','~> 0.12.1'
|
27
29
|
spec.add_development_dependency 'rake', '~> 13.0.1'
|
28
30
|
spec.add_development_dependency 'rspec', '~> 3.9.0'
|
29
31
|
spec.add_development_dependency 'yard', '~> 0.9.24'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: prometheus-splash
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Romain GEORGES
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-04-
|
11
|
+
date: 2020-04-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -80,6 +80,34 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: 2.15.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: tty-markdown
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.6.0
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.6.0
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: tty-pager
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.12.1
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.12.1
|
83
111
|
- !ruby/object:Gem::Dependency
|
84
112
|
name: rake
|
85
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -200,10 +228,18 @@ files:
|
|
200
228
|
- lib/splash/backends.rb
|
201
229
|
- lib/splash/backends/file.rb
|
202
230
|
- lib/splash/backends/redis.rb
|
231
|
+
- lib/splash/cli.rb
|
232
|
+
- lib/splash/cli/commands.rb
|
233
|
+
- lib/splash/cli/config.rb
|
234
|
+
- lib/splash/cli/daemon.rb
|
235
|
+
- lib/splash/cli/documentation.rb
|
236
|
+
- lib/splash/cli/logs.rb
|
203
237
|
- lib/splash/commands.rb
|
204
238
|
- lib/splash/config.rb
|
205
239
|
- lib/splash/constants.rb
|
206
240
|
- lib/splash/controller.rb
|
241
|
+
- lib/splash/dependencies.rb
|
242
|
+
- lib/splash/exiter.rb
|
207
243
|
- lib/splash/helpers.rb
|
208
244
|
- lib/splash/logs.rb
|
209
245
|
- lib/splash/orchestrator.rb
|