prometheus-splash 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/splash/logs.rb CHANGED
@@ -5,6 +5,9 @@ module Splash
5
5
  include Splash::Constants
6
6
  include Splash::Config
7
7
 
8
+
9
+ # LogScanner Constructor
10
+ # return [LogScanner]
8
11
  def initialize
9
12
  @logs_target = get_config.logs
10
13
  @config = get_config
@@ -17,6 +20,8 @@ module Splash
17
20
  @registry.register(@metric_lines)
18
21
  end
19
22
 
23
+
24
+ # start log analyse for log target in config
20
25
  def analyse
21
26
  @logs_target.each do |record|
22
27
  record[:count]=0 if record[:count].nil?
@@ -31,10 +36,12 @@ module Splash
31
36
  end
32
37
  end
33
38
 
39
+ # pseudo-accessor on @logs_target
34
40
  def output
35
41
  return @logs_target
36
42
  end
37
43
 
44
+ # start notification on prometheus for metric logerrors, logmissing; loglines
38
45
  def notify
39
46
  unless verify_service host: @config.prometheus_pushgateway_host ,port: @config.prometheus_pushgateway_port then
40
47
  $stderr.puts "Prometheus PushGateway Service IS NOT running"
@@ -1,3 +1,6 @@
1
+ require 'socket'
2
+ require 'yaml'
3
+
1
4
  module Splash
2
5
  module Orchestrator
3
6
 
@@ -15,11 +18,30 @@ module Splash
15
18
  end
16
19
  end
17
20
 
21
+ module Commander
22
+ include Splash::Transports
23
+ def send_message (options)
24
+ client = get_default_client
25
+ client.publish options
26
+ end
27
+ end
28
+
29
+ module Grammar
30
+
31
+ VERBS=[:ping]
32
+
33
+ def ping(payload)
34
+ return "Pong : #{payload[:hostname]} !"
35
+ end
36
+ end
37
+
18
38
 
19
39
  class Scheduler
20
40
  include Splash::Constants
21
41
  include Splash::Helpers
22
42
  include Splash::Config
43
+ include Splash::Transports
44
+ include Splash::Orchestrator::Grammar
23
45
  def initialize
24
46
  @server = Rufus::Scheduler::new
25
47
  @server.extend SchedulerHooks
@@ -35,7 +57,17 @@ module Splash
35
57
  $stderr.puts "PushGateway seems to be done, please start it."
36
58
  end
37
59
  end
38
- @server.join
60
+ hostname = Socket.gethostname
61
+ transport = get_default_subscriber queue: "splash.#{hostname}.input"
62
+ transport.subscribe(:block => true) do |delivery_info, properties, body|
63
+ content = YAML::load(body)
64
+ if VERBS.include? content[:verb]
65
+ res = self.send content[:verb], content[:payload]
66
+ get_default_client.publish queue: content[:return_to], message: res.to_yaml
67
+ else
68
+ get_default_client.publish queue: content[:return_to], message: "Unkown verb #{content[:verb]}".to_yaml
69
+ end
70
+ end
39
71
  end
40
72
 
41
73
  def terminate
@@ -1,11 +1,14 @@
1
1
  module Splash
2
2
  module Templates
3
+
4
+ # KISS template Engine
3
5
  class Template
4
6
 
5
7
  attr_reader :list_token
6
8
  attr_reader :template_file
7
9
  attr_reader :content
8
10
 
11
+ # constructor : generate the pseudo accessor for template Class from token list
9
12
  def initialize(_options)
10
13
 
11
14
 
@@ -28,12 +31,17 @@ module Splash
28
31
  @list_token.each{|_token| eval("def #{_token}; @hash_token['#{_token}'] ;end")}
29
32
  end
30
33
 
34
+ # generic accessor
35
+ # @param [Symbol] _token in the token list
36
+ # @param [String] _value a text value
37
+ # @raise [ArgumentError] if _valu is not a String
31
38
  def token(_token,_value)
32
39
  raise ArgumentError::new('Not a String') unless _value.class == String
33
40
  @hash_token[_token.to_s] = _value
34
41
  end
35
42
 
36
-
43
+ # map a hash against templates token_list
44
+ # @param [Hash] _hash a hash data to map
37
45
  def map(_hash)
38
46
  _data = {}
39
47
  _hash.each { |item,val|
@@ -44,11 +52,14 @@ module Splash
44
52
  @hash_token = _data
45
53
  end
46
54
 
55
+ # collector for pseudo accessor to prevent bad mapping
56
+ # @raise [NotAToken] if caling an accessor not mapped in token list
47
57
  def method_missing(_name,*_args)
48
58
  raise NotAToken
49
59
  end
50
60
 
51
-
61
+ # the templater;proceed to templating
62
+ # @return [String] the template output
52
63
  def output
53
64
  _my_res = String::new('')
54
65
  _my_res = @content
@@ -1,18 +1,34 @@
1
1
  require 'bunny'
2
+ require 'yaml'
3
+ require 'forwardable'
4
+
2
5
  module Splash
3
6
  module Transports
4
- module RabbitMQ
7
+ module Rabbitmq
5
8
 
6
9
  class Subscriber
7
- def initialize
10
+ include Splash::Config
11
+ extend Forwardable
12
+
13
+ def_delegators :@queue, :subscribe
14
+
15
+ def initialize(options = {})
16
+ @config = get_config.transports
17
+ @connection = Bunny.new url: @config[:rabbitmq][:url]
18
+ @connection.start
19
+ @channel = @connection.create_channel
20
+ @queue = @channel.queue options[:queue]
8
21
 
9
22
  end
23
+
10
24
  end
11
25
 
12
26
 
13
27
  class Client
28
+ include Splash::Config
14
29
  def initialize
15
- @connection = Bunny.new
30
+ @config = get_config.transports
31
+ @connection = Bunny.new url: @config[:rabbitmq][:url]
16
32
  @connection.start
17
33
  @channel = @connection.create_channel
18
34
  end
@@ -22,16 +38,17 @@ module Splash
22
38
  return @channel.default_exchange.publish(options[:message], :routing_key => options[:queue])
23
39
  end
24
40
 
25
- def ack
26
- return @channel.acknowledge(delivery_info.delivery_tag, false)
41
+ def ack(ack)
42
+ return @channel.acknowledge(ack, false)
27
43
  end
28
44
 
29
45
 
30
46
  def get(options ={})
31
47
  queue = @channel.queue(options[:queue])
48
+ opt = {}; opt[:manual_ack] = (options[:manual_ack])? true : false
32
49
  delivery_info, properties, payload = queue.pop
33
50
  res = {:message => payload}
34
- res[:ack] = delivery_info.delivery_tag if options[:noack]
51
+ res[:ack] = delivery_info.delivery_tag if options[:manual_ack]
35
52
  return res
36
53
  end
37
54
 
@@ -4,9 +4,9 @@ module Splash
4
4
  module Transports
5
5
  include Splash::Config
6
6
 
7
- def get_default_subscriber
8
- aclass = "Splash::Transports::#{get_config[:transports][:active].to_s.capitalize}::Suscriber"
9
- return Kernel.const_get(aclass)::new
7
+ def get_default_subscriber(queue)
8
+ aclass = "Splash::Transports::#{get_config[:transports][:active].to_s.capitalize}::Subscriber"
9
+ return Kernel.const_get(aclass)::new(queue)
10
10
  end
11
11
 
12
12
  def get_default_client
@@ -22,7 +22,8 @@ Gem::Specification.new do |spec|
22
22
  spec.add_runtime_dependency 'thor','~> 1.0.1'
23
23
  spec.add_runtime_dependency 'prometheus-client','~> 2.0.0'
24
24
  spec.add_runtime_dependency 'rufus-scheduler','~> 3.6.0'
25
- spec.add_runtime_dependency 'redis','~> 4.1.3'
25
+ spec.add_runtime_dependency 'redis','~> 4.1.3'
26
+ spec.add_runtime_dependency 'bunny','~> 2.15.0'
26
27
  spec.add_development_dependency 'rake', '~> 13.0.1'
27
28
  spec.add_development_dependency 'rspec', '~> 3.9.0'
28
29
  spec.add_development_dependency 'yard', '~> 0.9.24'
data/templates/report.txt CHANGED
@@ -1,7 +1,8 @@
1
1
  Command Execution report
2
2
  ========================
3
3
 
4
- Date : %%DATE%%
4
+ Date START: %%START_DATE%%
5
+ Date END: %%END_DATE%%
5
6
  Command : %%CMD_NAME%%
6
7
  full command line : %%CMD_LINE%%
7
8
  Description : %%DESC%%
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.0.3
4
+ version: 0.1.0
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-06 00:00:00.000000000 Z
11
+ date: 2020-04-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: 4.1.3
69
+ - !ruby/object:Gem::Dependency
70
+ name: bunny
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 2.15.0
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 2.15.0
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: rake
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -177,6 +191,10 @@ files:
177
191
  - LICENSE.txt
178
192
  - README.md
179
193
  - Rakefile
194
+ - assets/images/detail_prom_splash.png
195
+ - assets/images/logo_splash.png
196
+ - assets/images/logo_splash_reduce.png
197
+ - assets/images/prom_pg_logs.png
180
198
  - bin/splash
181
199
  - config/splash.yml
182
200
  - lib/splash/backends.rb