kstats-node 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/bin/kstats-node CHANGED
@@ -16,6 +16,37 @@ optparse = OptionParser.new do |opts|
16
16
  opts.on('-c', '--config CONF', 'Set configuration file (required)') do |config|
17
17
  options[:config] = config
18
18
  end
19
+
20
+ opts.on('-i', '--install', 'Build into current directory all startup files.') do
21
+ pwd = `pwd`.gsub("\n", "")
22
+
23
+ puts "Create #{pwd}/conf..."
24
+ `mkdir conf`
25
+
26
+ puts "Create #{pwd}/probes..."
27
+ `mkdir probes`
28
+
29
+ puts "Create #{pwd}/conf/conf.yml..."
30
+ File.open('conf/conf.yml', 'w') do |f|
31
+ content = <<CONF
32
+ probes_dir: #{pwd}/probes
33
+ db_dir: #{pwd}/db.sqlite3
34
+ server:
35
+ port: 1234
36
+ bind: 0.0.0.0
37
+ CONF
38
+ f.write content
39
+ end
40
+
41
+ Dir[File.expand_path('../../lib/kstats/probes/*', __FILE__)].each do |probefile|
42
+ puts "cp #{probefile} #{pwd}/probes/"
43
+ `cp #{probefile} #{pwd}/probes/`
44
+ end
45
+
46
+ puts "Done"
47
+
48
+ exit
49
+ end
19
50
  end
20
51
 
21
52
  optparse.parse!
@@ -26,67 +57,19 @@ if options[:config].nil?
26
57
  exit
27
58
  end
28
59
 
29
- require 'sinatra'
30
-
31
60
  puts "KStats::Node"
32
61
 
33
62
  puts "Load configuration file"
34
63
  config = YAML::load(File.read(options[:config]))
35
64
  Kstats::Node::Config.init(config)
36
65
 
37
- set :port, Kstats::Node::Config['server.port', 4567].to_i
38
- set :bind, Kstats::Node::Config['server.bind', '0.0.0.0']
39
-
40
66
  puts "Initialize database"
41
67
  Kstats::Node::Database.init
42
68
 
43
- get '/probes/list' do
44
- Kstats::Node::Probe.list.to_json
45
- end
46
-
47
- #Display data for daily infos
48
- get '/probe/:id/:target' do
49
- now = Time.now
50
-
51
- case params[:target]
52
- when 'tick'
53
- start = now - (60*60*24)
54
- when 'weekly'
55
- start = now - 7*(60*60*24)
56
- when 'monthly'
57
- start = now - 30*(60*60*24)
58
- when 'yearly'
59
- start = now - 365*(60*60*24)
60
- else
61
- return 403
62
- end
63
-
64
-
65
- data =Kstats::Node::Database.db.execute(
66
- "SELECT probe_key, date, probe_value FROM probe_data WHERE period_type=? AND probe_id = ? AND date >= ? ORDER BY date ASC",
67
- params[:target],
68
- params[:id],
69
- start.to_s
70
- )
71
-
72
- datas = {}
73
- data.each do |record|
74
- key, date, value = record
75
- datas[key] ||= []
76
- datas[key] << [Time.parse(date), value]
77
- end
78
-
79
- datas.each do |key, value|
80
- datas[key] = Kstats::Node::Helper.generate_array(value, start, (now-start)/60, 288)
81
- end
82
-
83
- {
84
- start_at: start,
85
- format: Kstats::Node::Probe.get_format(params[:id]),
86
- data: datas
87
- }.to_json
88
- end
89
69
 
90
70
  Kstats::Node::Worker.launch!
91
71
 
72
+ require 'kstats/node/app'
73
+ Kstats::Node::App.run!
74
+
92
75
  puts "Service is launched"
data/kstats-node.gemspec CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["Yacine Petitprez"]
10
10
  spec.email = ["yacine@kosmogo.com"]
11
11
  spec.summary = %q{Node for the project kstats}
12
- spec.description = %q{Provide a simple way to make probe on system values, and monitorign theses values.}
12
+ spec.description = %q{Provide a simple way to make probe on system values, and monitoring theses values.}
13
13
  spec.homepage = ""
14
14
  spec.license = "MIT"
15
15
  spec.executables << 'kstats-node'
@@ -0,0 +1,58 @@
1
+ require 'sinatra'
2
+
3
+ module Kstats
4
+ module Node
5
+ class App < Sinatra::Base
6
+ set :port, Kstats::Node::Config['server.port', 4567].to_i
7
+ set :bind, Kstats::Node::Config['server.bind', '0.0.0.0']
8
+
9
+ get '/probes/list' do
10
+ Kstats::Node::Probe.list.to_json
11
+ end
12
+
13
+ #Display data for daily infos
14
+ get '/probe/:id/:target' do
15
+ now = Time.now
16
+
17
+ case params[:target]
18
+ when 'tick'
19
+ start = now - (60*60*24)
20
+ when 'weekly'
21
+ start = now - 7*(60*60*24)
22
+ when 'monthly'
23
+ start = now - 30*(60*60*24)
24
+ when 'yearly'
25
+ start = now - 365*(60*60*24)
26
+ else
27
+ return 403
28
+ end
29
+
30
+
31
+ data =Kstats::Node::Database.db.execute(
32
+ "SELECT probe_key, date, probe_value FROM probe_data WHERE period_type=? AND probe_id = ? AND date >= ? ORDER BY date ASC",
33
+ params[:target],
34
+ params[:id],
35
+ start.to_s
36
+ )
37
+
38
+ datas = {}
39
+ data.each do |record|
40
+ key, date, value = record
41
+ datas[key] ||= []
42
+ datas[key] << [Time.parse(date), value]
43
+ end
44
+
45
+ datas.each do |key, value|
46
+ datas[key] = Kstats::Node::Helper.generate_array(value, start, (now-start)/60, 288)
47
+ end
48
+
49
+ {
50
+ start_at: start,
51
+ format: Kstats::Node::Probe.get_format(params[:id]),
52
+ data: datas
53
+ }.to_json
54
+ end
55
+ end
56
+ end
57
+ end
58
+
@@ -1,5 +1,5 @@
1
1
  module Kstats
2
2
  module Node
3
- VERSION = "1.0.2"
3
+ VERSION = "1.0.3"
4
4
  end
5
5
  end
data/lib/kstats/node.rb CHANGED
@@ -5,9 +5,9 @@ require "kstats/node/probe"
5
5
  require "kstats/node/database"
6
6
  require "kstats/node/helper"
7
7
 
8
+ require 'sinatra'
8
9
 
9
10
  module Kstats
10
11
  module Node
11
- # Your code goes here...
12
12
  end
13
13
  end
@@ -0,0 +1,32 @@
1
+ Kstats::Node::Probe.register 'cpu' do
2
+ category 'Hardware'
3
+ name 'CPU usage'
4
+
5
+ type :curve
6
+
7
+ command{ `cat /proc/loadavg`.split(/\s/).map(&:to_f) }
8
+
9
+ variable :load_avg_1mn do
10
+ desc 'Load average (1mn)'
11
+ color '#0000FF'
12
+ probe do
13
+ command[0]
14
+ end
15
+ end
16
+
17
+ variable :load_avg_5mn do
18
+ desc 'Load average (5mn)'
19
+ color '#00FF00'
20
+ probe do
21
+ command[1]
22
+ end
23
+ end
24
+
25
+ variable :load_avg_15mn do
26
+ desc 'Load average (15mn)'
27
+ color '#FF0000'
28
+ probe do
29
+ command[2]
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,35 @@
1
+ Kstats::Node::Probe.register 'disk' do
2
+ category 'Hardware'
3
+ name 'Disk usage'
4
+
5
+ type :curve
6
+
7
+ _self = self
8
+ instance_eval do
9
+ def parsedf
10
+ disks = `df`.split(/\n/).map do |x|
11
+ x.split(/\s+/)
12
+ end
13
+
14
+ disks.reject!{|x| x[0] == 'udev' || x[0] == 'none' || x[0] == 'tmpfs' || x[0] == 'Filesystem' }
15
+ disks.map!{|x| {name: x[0], space: 100*(x[2].to_f/x[1].to_f) }}
16
+ end
17
+ end
18
+
19
+ parsedf.each do |infos|
20
+ var = infos[:name]
21
+
22
+ variable var do
23
+ desc "Filling of `#{infos[:name]}`"
24
+ color "#0000FF"
25
+ probe do
26
+ val = _self.parsedf.select{|x| x[:name] == var }.first[:space]
27
+
28
+ puts val
29
+
30
+ val
31
+ end
32
+ end
33
+ end
34
+
35
+ end
File without changes
@@ -0,0 +1,5 @@
1
+ probes_dir: /home/yacine/Workspaces/kstats/kstats-node/test/probes
2
+ db_dir: /home/yacine/Workspaces/kstats/kstats-node/test/db.sqlite3
3
+ server:
4
+ port: 1234
5
+ bind: 0.0.0.0
data/test/db.sqlite3 ADDED
Binary file
@@ -0,0 +1,37 @@
1
+ Kstats::Node::Probe.register 'hwmem' do
2
+ category 'Hardware'
3
+ name 'Memory usage'
4
+
5
+ type :curve
6
+
7
+ command do
8
+ cmd = `cat /proc/meminfo`
9
+ lines = cmd.split(/\n/)
10
+
11
+ memtotal = lines.select{|x| x =~ /MemTotal/ }.first.gsub(/[^0-9]/, '').to_f
12
+ active = lines.select{|x| x =~ /Active/ }.first.gsub(/[^0-9]/, '').to_f
13
+ inactive = lines.select{|x| x =~ /Inactive/ }.first.gsub(/[^0-9]/, '').to_f
14
+ memfree = lines.select{|x| x =~ /MemFree/ }.first.gsub(/[^0-9]/, '').to_f
15
+ swaptotal = lines.select{|x| x =~ /SwapTotal/ }.first.gsub(/[^0-9]/, '').to_f
16
+ swapfree = lines.select{|x| x =~ /SwapFree/ }.first.gsub(/[^0-9]/, '').to_f
17
+
18
+ [memtotal, active, inactive, memfree, swaptotal, swapfree]
19
+ end
20
+
21
+ variable :mem_load do
22
+ desc 'Memory load (%)'
23
+ color '#0000FF'
24
+ probe do
25
+ 1-(command[3]/command[0])
26
+ end
27
+ end
28
+
29
+ variable :swap_load do
30
+ desc 'Swap load (%)'
31
+ color '#FF0000'
32
+
33
+ probe do
34
+ 1-(command[5]/command[4])
35
+ end
36
+ end
37
+ end
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.2
4
+ version: 1.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-05-28 00:00:00.000000000 Z
12
+ date: 2014-05-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sinatra
@@ -75,7 +75,7 @@ dependencies:
75
75
  - - ! '>='
76
76
  - !ruby/object:Gem::Version
77
77
  version: '0'
78
- description: Provide a simple way to make probe on system values, and monitorign theses
78
+ description: Provide a simple way to make probe on system values, and monitoring theses
79
79
  values.
80
80
  email:
81
81
  - yacine@kosmogo.com
@@ -92,16 +92,22 @@ files:
92
92
  - bin/kstats-node
93
93
  - kstats-node.gemspec
94
94
  - lib/kstats/node.rb
95
+ - lib/kstats/node/app.rb
95
96
  - lib/kstats/node/config.rb
96
97
  - lib/kstats/node/database.rb
97
98
  - lib/kstats/node/helper.rb
98
99
  - lib/kstats/node/probe.rb
99
100
  - lib/kstats/node/version.rb
100
101
  - lib/kstats/node/worker.rb
102
+ - lib/kstats/probes/cpu.rb
103
+ - lib/kstats/probes/disk.rb
104
+ - lib/kstats/probes/mem.rb
101
105
  - test/conf.yml
106
+ - test/conf/conf.yml
107
+ - test/db.sqlite3
102
108
  - test/probes/cpu.rb
103
109
  - test/probes/disk.rb
104
- - test/probes/memory.rb
110
+ - test/probes/mem.rb
105
111
  homepage: ''
106
112
  licenses:
107
113
  - MIT
@@ -129,7 +135,9 @@ specification_version: 3
129
135
  summary: Node for the project kstats
130
136
  test_files:
131
137
  - test/conf.yml
138
+ - test/conf/conf.yml
139
+ - test/db.sqlite3
132
140
  - test/probes/cpu.rb
133
141
  - test/probes/disk.rb
134
- - test/probes/memory.rb
142
+ - test/probes/mem.rb
135
143
  has_rdoc: