kstats-node 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,13 +2,6 @@
2
2
  lib = File.expand_path('../../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
-
6
- class Time
7
- def to_db
8
- strftime "%Y%m%d%H%M%S"
9
- end
10
- end
11
-
12
5
  require 'optparse'
13
6
  require 'yaml'
14
7
  require 'kstats/node'
@@ -20,18 +13,31 @@ optparse = OptionParser.new do |opts|
20
13
 
21
14
  opts.on('-h', '--help', 'Show help screen'){ puts opts; exit }
22
15
 
23
- opts.on('-c', '--config CONF', 'Set configuration file') do |config|
16
+ opts.on('-c', '--config CONF', 'Set configuration file (required)') do |config|
24
17
  options[:config] = config
25
18
  end
26
19
  end
27
20
 
28
21
  optparse.parse!
29
- require 'sinatra'
30
22
 
31
23
  #Parse the configuration file:
24
+ if options[:config].nil?
25
+ puts optparse
26
+ exit
27
+ end
28
+
29
+ require 'sinatra'
30
+
31
+ puts "KStats::Node"
32
+
33
+ puts "Load configuration file"
32
34
  config = YAML::load(File.read(options[:config]))
33
- Kstats::Node::CONFIG.merge!(config)
35
+ Kstats::Node::Config.init(config)
36
+
37
+ set :port, Kstats::Node::Config['server.port', 4567].to_i
38
+ set :bind, Kstats::Node::Config['server.bind', '0.0.0.0']
34
39
 
40
+ puts "Initialize database"
35
41
  Kstats::Node::Database.init
36
42
 
37
43
  get '/probes/list' do
@@ -82,3 +88,5 @@ get '/probe/:id/:target' do
82
88
  end
83
89
 
84
90
  Kstats::Node::Worker.launch!
91
+
92
+ puts "Service is launched"
@@ -1,5 +1,38 @@
1
1
  module Kstats
2
2
  module Node
3
- CONFIG={}
3
+ module Config
4
+ def self.init config_file
5
+ @config ||= {}
6
+ @config.merge!(config_file)
7
+ end
8
+
9
+ def self.[] key, default = nil
10
+ path = key.to_s.split(/\./)
11
+
12
+ explore_path(path) || default
13
+ end
14
+
15
+ private
16
+
17
+ def self.explore_path path, current = nil, idx=0
18
+ if idx == 0 && current.nil?
19
+ current = @config
20
+ end
21
+
22
+ if current.nil?
23
+ nil
24
+ else
25
+ if idx == path.count-1
26
+ if current.instance_of?(Hash)
27
+ current[path[idx]]
28
+ else
29
+ nil
30
+ end
31
+ else
32
+ explore_path path, current[path[idx]], idx+1
33
+ end
34
+ end
35
+ end
36
+ end
4
37
  end
5
38
  end
@@ -7,7 +7,7 @@ module Kstats
7
7
  attr_reader :db
8
8
 
9
9
  def init
10
- @db = SQLite3::Database.new( Kstats::Node::CONFIG['db_dir'] )
10
+ @db = SQLite3::Database.new( Kstats::Node::Config['db_dir'] )
11
11
  @db.execute [
12
12
  "CREATE TABLE IF NOT EXISTS probe_data (id INTEGER PRIMARY KEY ASC, date DATETIME, period_type STRING, probe_id STRING, probe_key STRING, probe_value NUMBER)",
13
13
  "CREATE INDEX IF NOT EXISTS probe_data_period_type ON probe_data(period_type)",
@@ -26,7 +26,7 @@ module Kstats
26
26
 
27
27
  probes.each do |name, values|
28
28
  @db.close
29
- @db = SQLite3::Database.new( Kstats::Node::CONFIG['db_dir'] )
29
+ @db = SQLite3::Database.new( Kstats::Node::Config['db_dir'] )
30
30
 
31
31
  sql = <<SQL
32
32
  INSERT INTO probe_data (date, period_type, probe_id, probe_key, probe_value)
@@ -30,7 +30,7 @@ module Kstats
30
30
  @fixed_registered = @registered
31
31
  @registered = []
32
32
 
33
- dir = Kstats::Node::CONFIG['probes_dir']
33
+ dir = Kstats::Node::Config['probes_dir']
34
34
 
35
35
  Dir[File.join(dir, "*.rb")].each do |probe_file|
36
36
  begin
@@ -1,5 +1,5 @@
1
1
  module Kstats
2
2
  module Node
3
- VERSION = "1.0.1"
3
+ VERSION = "1.0.2"
4
4
  end
5
5
  end
@@ -9,7 +9,7 @@ module Kstats
9
9
  thread = Thread.new do
10
10
  begin
11
11
  begin
12
- puts "New probe tick."
12
+ puts "***GATHERING INFORMATIONS #{`date`}."
13
13
  probes = Kstats::Node::Probe.reload_and_test!
14
14
 
15
15
  if insert_month == 0
@@ -1,2 +1,8 @@
1
1
  probes_dir: test/probes
2
- db_dir: test/db/test.sqlite3
2
+ db_dir: test/db/test.sqlite3
3
+ server:
4
+ port: 1234
5
+ bind: 0.0.0.0
6
+ probes:
7
+ pgsql:
8
+ host: localhost
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kstats-node
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: