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.
@@ -1,68 +1,70 @@
1
1
  # coding: utf-8
2
2
  module Splash
3
- class LogScanner
4
- include Splash::Constants
5
- include Splash::Config
3
+ module Logs
4
+ class LogScanner
5
+ include Splash::Constants
6
+ include Splash::Config
6
7
 
7
8
 
8
- # LogScanner Constructor
9
- # return [LogScanner]
10
- def initialize
11
- @logs_target = get_config.logs
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
+ # LogScanner Constructor
10
+ # return [LogScanner]
11
+ def initialize
12
+ @logs_target = get_config.logs
13
+ @config = get_config
14
+ @registry = Prometheus::Client::Registry::new
15
+ @metric_count = Prometheus::Client::Gauge.new(:logerrors, docstring: 'SPLASH metric log error', labels: [:log ])
16
+ @metric_missing = Prometheus::Client::Gauge.new(:logmissing, docstring: 'SPLASH metric log missing', labels: [:log ])
17
+ @metric_lines = Prometheus::Client::Gauge.new(:loglines, docstring: 'SPLASH metric log lines numbers', labels: [:log ])
18
+ @registry.register(@metric_count)
19
+ @registry.register(@metric_missing)
20
+ @registry.register(@metric_lines)
21
+ end
21
22
 
22
23
 
23
- # start log analyse for log target in config
24
- def analyse
25
- @logs_target.each do |record|
26
- record[:count]=0 if record[:count].nil?
27
- record[:status] = :clean if record[:status].nil?
28
- if File.exist?(record[:log]) then
29
- record[:count] = File.readlines(record[:log]).grep(/#{record[:pattern]}/).size
30
- record[:status] = :matched if record[:count] > 0
31
- record[:lines] = `wc -l "#{record[:log]}"`.strip.split(/\s+/)[0].to_i unless record[:status] == :missing
32
- else
33
- record[:status] = :missing
24
+ # start log analyse for log target in config
25
+ def analyse
26
+ @logs_target.each do |record|
27
+ record[:count]=0 if record[:count].nil?
28
+ record[:status] = :clean if record[:status].nil?
29
+ if File.exist?(record[:log]) then
30
+ record[:count] = File.readlines(record[:log]).grep(/#{record[:pattern]}/).size
31
+ record[:status] = :matched if record[:count] > 0
32
+ record[:lines] = `wc -l "#{record[:log]}"`.strip.split(/\s+/)[0].to_i unless record[:status] == :missing
33
+ else
34
+ record[:status] = :missing
35
+ end
34
36
  end
37
+ return {:case => :quiet_exit }
35
38
  end
36
- return {:case => :quiet_exit }
37
- end
38
-
39
- # pseudo-accessor on @logs_target
40
- def output
41
- return @logs_target
42
- end
43
39
 
44
- # start notification on prometheus for metric logerrors, logmissing; loglines
45
- def notify(options = {})
46
- log = get_logger
47
- unless verify_service host: @config.prometheus_pushgateway_host ,port: @config.prometheus_pushgateway_port then
48
- return { :case => :service_dependence_missing, :more => "Prometheus Notification not send." }
40
+ # pseudo-accessor on @logs_target
41
+ def output
42
+ return @logs_target
49
43
  end
50
- session = (options[:session]) ? options[:session] : log.get_session
51
- log.info "Sending metrics to Prometheus Pushgateway", session
52
- @logs_target.each do |item|
53
- missing = (item[:status] == :missing)? 1 : 0
54
- log.item "Sending metrics for #{item[:log]}", session
55
- @metric_count.set(item[:count], labels: { log: item[:log] })
56
- @metric_missing.set(missing, labels: { log: item[:log] })
57
- lines = (item[:lines])? item[:lines] : 0
58
- @metric_lines.set(lines, labels: { log: item[:log] })
44
+
45
+ # start notification on prometheus for metric logerrors, logmissing; loglines
46
+ def notify(options = {})
47
+ log = get_logger
48
+ unless verify_service host: @config.prometheus_pushgateway_host ,port: @config.prometheus_pushgateway_port then
49
+ return { :case => :service_dependence_missing, :more => "Prometheus Notification not send." }
50
+ end
51
+ session = (options[:session]) ? options[:session] : log.get_session
52
+ log.info "Sending metrics to Prometheus Pushgateway", session
53
+ @logs_target.each do |item|
54
+ missing = (item[:status] == :missing)? 1 : 0
55
+ log.item "Sending metrics for #{item[:log]}", session
56
+ @metric_count.set(item[:count], labels: { log: item[:log] })
57
+ @metric_missing.set(missing, labels: { log: item[:log] })
58
+ lines = (item[:lines])? item[:lines] : 0
59
+ @metric_lines.set(lines, labels: { log: item[:log] })
60
+ end
61
+ hostname = Socket.gethostname
62
+ url = "http://#{@config.prometheus_pushgateway_host}:#{@config.prometheus_pushgateway_port}"
63
+ Prometheus::Client::Push.new('Splash',hostname, url).add(@registry)
64
+ log.ok "Sending to Prometheus PushGateway done.", session
65
+ return {:case => :quiet_exit }
59
66
  end
60
- hostname = Socket.gethostname
61
- url = "http://#{@config.prometheus_pushgateway_host}:#{@config.prometheus_pushgateway_port}"
62
- Prometheus::Client::Push.new('Splash',hostname, url).add(@registry)
63
- log.ok "Sending to Prometheus PushGateway done.", session
64
- return {:case => :quiet_exit }
65
- end
66
67
 
68
+ end
67
69
  end
68
70
  end
@@ -0,0 +1,4 @@
1
+ ---
2
+ - name: restart Splashd
3
+ service: name=splashd state=restarted
4
+ become: yes
@@ -26,4 +26,27 @@
26
26
  owner: root
27
27
  group: root
28
28
  mode: 0644
29
- #notify: restart Splash
29
+ notify: restart Splashd
30
+
31
+ - name: SPLASH Check if Systemd service installed
32
+ stat:
33
+ path: /etc/systemd/system/splashd.service
34
+ register: stat_splash_result
35
+
36
+ - name: SPLASH Install systemd service
37
+ shell: splash conf service
38
+ when: not stat_splash_result.stat.exists
39
+
40
+ - name: SPLASH Splashd running
41
+ service:
42
+ name: splashd
43
+ state: started
44
+ enabled: yes
45
+
46
+ - name: SPLASH LogRotate template
47
+ template:
48
+ src: logrotate.splash.j2
49
+ dest: /etc/logrotate.d/splash
50
+ owner: root
51
+ group: root
52
+ mode: 0644
@@ -0,0 +1,11 @@
1
+ /var/log/splash.log /var/run/splash/traces/stderr.txt /var/run/splash/traces/stdout.txt {
2
+
3
+ daily
4
+ rotate 7
5
+ size 100M
6
+ compress
7
+ delaycompress
8
+ missingok
9
+ notifempty
10
+ copytruncate
11
+ }
@@ -30,7 +30,7 @@
30
30
  :user: {{ mq_splash_username }}
31
31
  :daemon:
32
32
  :logmon_scheduling:
33
- :every: 20s
33
+ :every: 1m
34
34
  :process_name: "Splash : daemon."
35
35
  :paths:
36
36
  :pid_path: /var/run/splash
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prometheus-splash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Romain GEORGES
@@ -267,11 +267,17 @@ files:
267
267
  - lib/splash/cli/logs.rb
268
268
  - lib/splash/commands.rb
269
269
  - lib/splash/config.rb
270
+ - lib/splash/config/flush.rb
270
271
  - lib/splash/config/sanitycheck.rb
271
272
  - lib/splash/config/service.rb
272
273
  - lib/splash/config/setup.rb
273
274
  - lib/splash/constants.rb
274
- - lib/splash/controller.rb
275
+ - lib/splash/daemon.rb
276
+ - lib/splash/daemon/controller.rb
277
+ - lib/splash/daemon/metrics.rb
278
+ - lib/splash/daemon/orchestrator.rb
279
+ - lib/splash/daemon/orchestrator/grammar.rb
280
+ - lib/splash/daemon/orchestrator/hooks.rb
275
281
  - lib/splash/dependencies.rb
276
282
  - lib/splash/exiter.rb
277
283
  - lib/splash/helpers.rb
@@ -280,9 +286,6 @@ files:
280
286
  - lib/splash/loggers/daemon.rb
281
287
  - lib/splash/loggers/dual.rb
282
288
  - lib/splash/logs.rb
283
- - lib/splash/orchestrator.rb
284
- - lib/splash/orchestrator/grammar.rb
285
- - lib/splash/orchestrator/hooks.rb
286
289
  - lib/splash/templates.rb
287
290
  - lib/splash/transports.rb
288
291
  - lib/splash/transports/rabbitmq.rb
@@ -300,7 +303,9 @@ files:
300
303
  - templates/ansible-splash/roles/mq/handlers/main.yml
301
304
  - templates/ansible-splash/roles/mq/tasks/main.yml
302
305
  - templates/ansible-splash/roles/mq/templates/rabbitmq-env.conf.j2
306
+ - templates/ansible-splash/roles/splash/handlers/main.yml
303
307
  - templates/ansible-splash/roles/splash/tasks/main.yml
308
+ - templates/ansible-splash/roles/splash/templates/logrotate.splash.j2
304
309
  - templates/ansible-splash/roles/splash/templates/splash.yml.j2
305
310
  - templates/ansible-splash/roles/supervision_gateway/handlers/main.yml
306
311
  - templates/ansible-splash/roles/supervision_gateway/tasks/main.yml
@@ -1,54 +0,0 @@
1
- # coding: utf-8
2
- module Splash
3
- module Orchestrator
4
- module Grammar
5
-
6
- include Splash::Config
7
- include Splash::Loggers
8
-
9
-
10
- VERBS=[:ping,:list_commands,:execute_command,:ack_command, :shutdown]
11
-
12
-
13
- def shutdown
14
- terminate
15
- end
16
-
17
- def ping(content)
18
- return "Pong : #{content[:payload][:hostname]} !"
19
- end
20
-
21
-
22
- def list_commands(content)
23
- return get_config.commands
24
- end
25
-
26
- def ack_command(content)
27
- return execute command: content[:payload][:name], ack: true
28
- end
29
-
30
-
31
- def execute_command(content)
32
- payload = content[:payload]
33
- unless get_config.commands.include? payload[:name].to_sym
34
- @log.item "Command not found", content[:session]
35
- return { :case => :not_found }
36
- end
37
- if payload.include? :schedule then
38
- sched,value = payload[:schedule].flatten
39
- @log.schedule "remote call command #{payload[:name]}, scheduling : #{sched.to_s} #{value}", content[:session]
40
- @server.send sched,value do
41
- @log.trigger "Executing Scheduled command #{payload[:name]} for Scheduling : #{sched.to_s} #{value}", content[:session]
42
- execute command: payload[:name], session: content[:session]
43
- end
44
- return { :case => :quiet_exit }
45
- else
46
- @log.info "Execute direct command", content[:session]
47
- res = execute command: payload[:name], session: content[:session]
48
- return res
49
- end
50
- end
51
-
52
- end
53
- end
54
- end
@@ -1,16 +0,0 @@
1
- # coding: utf-8
2
- module Splash
3
- module Orchestrator
4
-
5
- module SchedulerHooks
6
- def on_pre_trigger(job, trigger_time)
7
-
8
- end
9
-
10
- def on_post_trigger(job, trigger_time)
11
-
12
- end
13
-
14
- end
15
- end
16
- end