collectd-interface 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. data/bin/collectd-interface-daemon +4 -1
  2. data/lib/collectd/interface/config.rb +132 -64
  3. data/lib/collectd/interface/options.rb +10 -10
  4. data/lib/collectd/interface/service.rb +13 -0
  5. data/views/reports/processes.erb +1 -1
  6. metadata +4 -80
  7. data/public/images/cpus.png +0 -0
  8. data/public/images/device/ops/sda.png +0 -0
  9. data/public/images/device/ops/sda1.png +0 -0
  10. data/public/images/device/ops/sda2.png +0 -0
  11. data/public/images/device/ops/sda5.png +0 -0
  12. data/public/images/device/ops/sda6.png +0 -0
  13. data/public/images/device/ops/sda7.png +0 -0
  14. data/public/images/device/ops/sda8.png +0 -0
  15. data/public/images/device/ops/sda9.png +0 -0
  16. data/public/images/device/ops/sdb.png +0 -0
  17. data/public/images/device/ops/sdb1.png +0 -0
  18. data/public/images/device/ops/sdh.png +0 -0
  19. data/public/images/device/ops/sdh1.png +0 -0
  20. data/public/images/device/ops/sdh2.png +0 -0
  21. data/public/images/device/ops/sdh3.png +0 -0
  22. data/public/images/device/ops/sdh4.png +0 -0
  23. data/public/images/device/ops/sr0.png +0 -0
  24. data/public/images/device/time/sda.png +0 -0
  25. data/public/images/device/time/sda1.png +0 -0
  26. data/public/images/device/time/sda2.png +0 -0
  27. data/public/images/device/time/sda5.png +0 -0
  28. data/public/images/device/time/sda6.png +0 -0
  29. data/public/images/device/time/sda7.png +0 -0
  30. data/public/images/device/time/sda8.png +0 -0
  31. data/public/images/device/time/sda9.png +0 -0
  32. data/public/images/device/time/sdb.png +0 -0
  33. data/public/images/device/time/sdb1.png +0 -0
  34. data/public/images/device/time/sdh.png +0 -0
  35. data/public/images/device/time/sdh1.png +0 -0
  36. data/public/images/device/time/sdh2.png +0 -0
  37. data/public/images/device/time/sdh3.png +0 -0
  38. data/public/images/device/time/sdh4.png +0 -0
  39. data/public/images/device/time/sr0.png +0 -0
  40. data/public/images/device/traffic/sda.png +0 -0
  41. data/public/images/device/traffic/sda1.png +0 -0
  42. data/public/images/device/traffic/sda2.png +0 -0
  43. data/public/images/device/traffic/sda5.png +0 -0
  44. data/public/images/device/traffic/sda6.png +0 -0
  45. data/public/images/device/traffic/sda7.png +0 -0
  46. data/public/images/device/traffic/sda8.png +0 -0
  47. data/public/images/device/traffic/sda9.png +0 -0
  48. data/public/images/device/traffic/sdb.png +0 -0
  49. data/public/images/device/traffic/sdb1.png +0 -0
  50. data/public/images/device/traffic/sdh.png +0 -0
  51. data/public/images/device/traffic/sdh1.png +0 -0
  52. data/public/images/device/traffic/sdh2.png +0 -0
  53. data/public/images/device/traffic/sdh3.png +0 -0
  54. data/public/images/device/traffic/sdh4.png +0 -0
  55. data/public/images/device/traffic/sr0.png +0 -0
  56. data/public/images/irqs.png +0 -0
  57. data/public/images/load.png +0 -0
  58. data/public/images/memory.png +0 -0
  59. data/public/images/network/packets/eth0.png +0 -0
  60. data/public/images/network/packets/lo.png +0 -0
  61. data/public/images/network/packets/nbr0-nic.png +0 -0
  62. data/public/images/network/packets/nbr0.png +0 -0
  63. data/public/images/network/packets/virbr0.png +0 -0
  64. data/public/images/network/packets/vnet0.png +0 -0
  65. data/public/images/network/packets/vnet1.png +0 -0
  66. data/public/images/network/packets/vnet2.png +0 -0
  67. data/public/images/network/packets/vnet3.png +0 -0
  68. data/public/images/network/packets/vnet4.png +0 -0
  69. data/public/images/network/packets/vnet5.png +0 -0
  70. data/public/images/network/traffic/eth0.png +0 -0
  71. data/public/images/network/traffic/lo.png +0 -0
  72. data/public/images/network/traffic/nbr0-nic.png +0 -0
  73. data/public/images/network/traffic/nbr0.png +0 -0
  74. data/public/images/network/traffic/virbr0.png +0 -0
  75. data/public/images/network/traffic/vnet0.png +0 -0
  76. data/public/images/network/traffic/vnet1.png +0 -0
  77. data/public/images/network/traffic/vnet2.png +0 -0
  78. data/public/images/network/traffic/vnet3.png +0 -0
  79. data/public/images/network/traffic/vnet4.png +0 -0
  80. data/public/images/network/traffic/vnet5.png +0 -0
  81. data/public/images/processes.png +0 -0
  82. data/public/images/users.png +0 -0
@@ -2,7 +2,6 @@
2
2
 
3
3
  require 'collectd/interface/options'
4
4
  require 'collectd/interface/config'
5
- require 'collectd/interface/service'
6
5
 
7
6
  exec_name = File.split(__FILE__)[-1]
8
7
  help = <<-EOF
@@ -34,6 +33,8 @@ Options
34
33
  Write the log output to PATH.
35
34
  --pid-file-path, -P PATH:
36
35
  Write the process ID to a file in PATH.
36
+ --plugin-path, -I PATH:
37
+ Path to additional graph and report plugins.
37
38
 
38
39
  Examples
39
40
  --------
@@ -64,6 +65,8 @@ begin
64
65
  $stdout.sync = true
65
66
  $stderr.reopen($stdout)
66
67
  end
68
+ # don't require Sinatra before options have been set in the configuration object!
69
+ require 'collectd/interface/service'
67
70
  Collectd::Interface::Service.run!
68
71
 
69
72
  rescue => exc
@@ -6,81 +6,96 @@ require 'forwardable'
6
6
  module Collectd
7
7
  module Interface
8
8
  class Config
9
+
9
10
  include Singleton
11
+
10
12
  def initialize
13
+ # Holds all configurations
11
14
  @data = Hash.new
12
- defaults()
13
- find_graphs()
14
- find_data()
15
- find_reports()
15
+ # No debugging by default
16
+ @data['debug'] = false
17
+ # defaults for the Sinatra application
18
+ @data['service'] = Hash.new
19
+ @data['service']['port'] = 5000
20
+ @data['service']['pid_path'] = String.new
21
+ @data['service']['log_path'] = String.new
22
+ # User defined path to graphs and reports plug-ins
23
+ @data['plugin_path'] = String.new
24
+ # find the application root directory relative to this configuration file
25
+ @data['root'] = File.expand_path(File.join(File.dirname(File.expand_path(__FILE__)),'..','..','..'))
26
+ _hostname = `hostname -f`.chop
27
+ # Path to the RRD file written by Collectd
28
+ @data['rrd_path'] = File.join('/var/lib/collectd/rrd/',_hostname)
29
+ graphs_add_build_ins()
30
+ reports_add_build_ins()
31
+ data_add_all_sources()
16
32
  end
17
- # Hash like access to the internals
33
+
18
34
  def [](key); @data[key] end
19
35
  def []=(key,value); @data[key] = value end
20
- # type casts & inspection
36
+
21
37
  def to_json; JSON.pretty_generate(@data) end
38
+
22
39
  def inspect
23
40
  %Q[-- Config --\n#{self.to_json}\n------------]
24
41
  end
25
- # short cuts for attributes
26
- def debug?; @data['debug'] end
27
- # does the user wants to write a file containing the PID
42
+
43
+ # Is the application in debugging mode?
44
+ def debug?; self['debug'] end
45
+
46
+ # Path to the application root directory.
47
+ def root; self['root'] end
48
+
49
+ # Does the user wants to write a file containing the PID?
28
50
  def pid_file?
29
51
  self['service']['pid_path'].empty?
30
52
  end
53
+ # Path to the PID file.
31
54
  def pid_file(name)
32
55
  File.join(self['service']['pid_path'],"#{name}.pid")
33
56
  end
57
+ # Does the user wants to write a log file?
34
58
  def log_file?
35
59
  self['service']['log_path'].empty?
36
60
  end
61
+ # Path to the log file.
37
62
  def log_file(name)
38
63
  File.join(self['service']['log_path'],"#{name}.log")
39
64
  end
40
- def root; @data['root'] end
65
+
66
+ # Add optional user plug-ins to the configuration, where
67
+ # _path_ is the path to the directory containing graph
68
+ # and report plug-ins.
69
+ def plugin_path(path)
70
+ # will be added to the Sinatra views array
71
+ self['plugin_path'] = path
72
+ # add all optional graphs
73
+ _path = File.join(path,'graphs')
74
+ if File.directory? _path
75
+ Dir["#{_path}/**/*.erb"].each do |file|
76
+ graphs_add_plugin(_path,file)
77
+ end
78
+ end
79
+ # add all optional reports
80
+ _path = File.join(path,'reports')
81
+ if File.directory? _path
82
+ Dir["#{_path}/**/*.erb"].each do |file|
83
+ reports_add_plugin(_path,file)
84
+ end
85
+ end
86
+ end
87
+
88
+ # Make sure all instance methods are accessible for client objects
41
89
  class << self
42
90
  extend Forwardable
43
91
  def_delegators :instance, *Config.instance_methods(false)
44
92
  end
93
+
45
94
  private
46
- def defaults
47
- @data['debug'] = false
48
- # defaults for the Sinatra application
49
- @data['service'] = Hash.new
50
- @data['service']['port'] = 5000
51
- @data['service']['pid_path'] = String.new
52
- @data['service']['log_path'] = String.new
53
- @data['service']['config_path'] = String.new
54
- # find the application root directory relative to this configuration file
55
- @data['root'] = File.expand_path(File.join(File.dirname(File.expand_path(__FILE__)),'..','..','..'))
56
- _hostname = `hostname -f`.chop
57
- @data['rrd_path'] = File.join('/var/lib/collectd/rrd/',_hostname)
58
- end
59
- def find_graphs
60
- self['graphs'] = Hash.new
61
- # path to the plug-ins shipped with this software
62
- _path = File.join(self.root,'views','graphs')
63
- Dir["#{_path}/**/*.erb"].each do |file|
64
- # strip the template suffix
65
- _name = file.gsub(/\.erb/,'')
66
- # remove the path to the graph template directory
67
- _name = _name.gsub(%r<#{_path}>,'')[1..-1]
68
- # strip the application path from the file name
69
- _file = file.gsub(%r<#{_path}/>,'').gsub(/\.erb/,'')
70
- # does the plug-in supports URI parameters
71
- if _name.include?('/')
72
- @config = true
73
- @rrd_path = self['rrd_path']
74
- _supports = JSON.parse(ERB.new(File.read(file)).result(binding))
75
- _supports.each do |path|
76
- self['graphs']["#{_name}/#{path}"] = _file
77
- end
78
- else
79
- self['graphs'][_name] = _file
80
- end
81
- end
82
- end
83
- def find_data
95
+
96
+ # Find all RRD files written by Collectd and construct
97
+ # a list of URL paths used to access them.
98
+ def data_add_all_sources
84
99
  self['data'] = Array.new
85
100
  Dir["#{self['rrd_path']}/**/*.rrd"].each do |file|
86
101
  plugin = file.gsub(%r<#{self['rrd_path']}>,'').split('/')[1]
@@ -90,28 +105,81 @@ module Collectd
90
105
  end
91
106
  end
92
107
  end
93
- def find_reports
94
- self['reports'] = Hash.new
95
- _path = File.join(self.root,'views','reports')
96
- Dir["#{_path}/**/*.erb"].each do |file|
97
- # strip the template suffix
98
- _name = file.gsub(/\.erb/,'')
99
- # remove the path to the graph template directory
100
- _name = _name.gsub(%r<#{_path}>,'')[1..-1]
101
- # strip the application path from the file name
102
- _file = file.gsub(%r<#{_path}/>,'').gsub(/\.erb/,'')
103
- # path to the template file
104
- if _name.include?('/')
105
- @config = true
106
- _supports = JSON.parse(ERB.new(File.read(file)).result(binding))
108
+
109
+ # Adds a graph plug-in to the configuration, where _path_ is the URL path
110
+ # used to call it and _file_ is the location of the plug-in in the file-system.
111
+ def graphs_add_plugin(path,file)
112
+ # strip the template suffix
113
+ _name = file.gsub(/\.erb/,'')
114
+ # remove the path to the graph template directory
115
+ _name = _name.gsub(%r<#{path}>,'')[1..-1]
116
+ # strip the application path from the file name
117
+ _file = file.gsub(%r<#{path}/>,'').gsub(/\.erb/,'')
118
+ # does the plug-in supports URI parameters
119
+ if _name.include?('/')
120
+ # ask the plug-in for supported paths
121
+ @config = true
122
+ @rrd_path = self['rrd_path']
123
+ _supports = JSON.parse(ERB.new(File.read(file)).result(binding))
124
+ if _supports.empty?
125
+ self['graphs'][_name] = _file
126
+ else
107
127
  _supports.each do |path|
108
- self['reports']["#{_name}/#{path}"] = _file
128
+ self['graphs']["#{_name}/#{path}"] = _file
109
129
  end
110
- else
130
+ end
131
+ else
132
+ self['graphs'][_name] = _file
133
+ end
134
+ end
135
+
136
+ # Searches for all graph plug-ins shipped with this application.
137
+ def graphs_add_build_ins
138
+ self['graphs'] = Hash.new
139
+ # path to the plug-ins shipped with this software
140
+ _path = File.join(self.root,'views','graphs')
141
+ Dir["#{_path}/**/*.erb"].each do |file|
142
+ graphs_add_plugin(_path,file)
143
+ end
144
+ end
145
+
146
+ # Adds a report plug-in to the configuration, where _path_ is the URL path
147
+ # used to call it and _file_ is the location of the plug-in in the file-system.
148
+ def reports_add_plugin(path,file)
149
+ # strip the template suffix
150
+ _name = file.gsub(/\.erb/,'')
151
+ # remove the path to the graph template directory
152
+ _name = _name.gsub(%r<#{path}>,'')[1..-1]
153
+ # strip the application path from the file name
154
+ _file = file.gsub(%r<#{path}/>,'').gsub(/\.erb/,'')
155
+ # if the plug-in lives inside a sub-directory
156
+ if _name.include?('/')
157
+ # ask the plug-in for its configuration
158
+ @config = true
159
+ _supports = JSON.parse(ERB.new(File.read(file)).result(binding))
160
+ # if the answer is empty the plug-in supports only a single URL path
161
+ if _supports.empty?
111
162
  self['reports'][_name] = _file
163
+ # otherwise add the list of paths to the configuration
164
+ else
165
+ _supports.each do |path|
166
+ self['reports']["#{_name}/#{path}"] = _file
167
+ end
112
168
  end
169
+ else
170
+ self['reports'][_name] = _file
113
171
  end
114
172
  end
173
+
174
+ # Searches for all reports shipped with this application.
175
+ def reports_add_build_ins
176
+ self['reports'] = Hash.new
177
+ _path = File.join(self.root,'views','reports')
178
+ Dir["#{_path}/**/*.erb"].each do |file|
179
+ reports_add_plugin(_path,file)
180
+ end
181
+ end
182
+
115
183
  end
116
184
  end
117
185
  end
@@ -16,9 +16,9 @@ module Collectd
16
16
  ['--port','-p',GetoptLong::REQUIRED_ARGUMENT],
17
17
  ['--log-file-path','-l',GetoptLong::REQUIRED_ARGUMENT],
18
18
  ['--pid-file-path','-P',GetoptLong::REQUIRED_ARGUMENT],
19
- ['--config-dump','-C',GetoptLong::NO_ARGUMENT],
20
- ['--config','-c',GetoptLong::REQUIRED_ARGUMENT],
21
- ['--version',GetoptLong::NO_ARGUMENT]
19
+ ['--plugin-path','-I',GetoptLong::REQUIRED_ARGUMENT],
20
+ ['--version',GetoptLong::NO_ARGUMENT],
21
+ ['--config-dump','-C',GetoptLong::NO_ARGUMENT]
22
22
  )
23
23
  end
24
24
  def parse
@@ -38,6 +38,13 @@ module Collectd
38
38
  else
39
39
  raise("#{arg} is not a directory!")
40
40
  end
41
+ when '--plugin-path'
42
+ _path = File.expand_path(arg)
43
+ if File.directory? arg
44
+ Config.plugin_path(_path)
45
+ else
46
+ raise("#{arg} is not a directory!")
47
+ end
41
48
  when '--config-dump'
42
49
  $stdout.puts Config.inspect
43
50
  exit 0
@@ -46,13 +53,6 @@ module Collectd
46
53
  when '--help'
47
54
  $stdout.puts @help
48
55
  exit 0
49
- when '--config'
50
- _config = File.expand_path(arg)
51
- if File.directory? _config
52
- Config['service']['config_path'] = _config
53
- else
54
- raise %Q[Configuration directory "#{config}" missing!]
55
- end
56
56
  when '--version'
57
57
  $stdout.puts '0.5.0'
58
58
  exit 0
@@ -1,3 +1,4 @@
1
+ require 'rubygems'
1
2
  require 'json'
2
3
  require 'sinatra/base'
3
4
  require 'collectd/interface/config'
@@ -14,6 +15,18 @@ module Collectd
14
15
  # read the configuration object and set the Sinatra defaults
15
16
  set :root, Config.root
16
17
  set :port, Config['service']['port']
18
+ # by default lookup templates in the application views/ directory
19
+ _views = [ File.join(Config.root,'views') ]
20
+ # optionally add a template directory defined by the user
21
+ _views << Config['plugin_path'] unless Config['plugin_path'].empty?
22
+ set :views, _views
23
+ # overwrite the template lookup method to cover all
24
+ # paths in views
25
+ def find_template(views, name, engine, &block)
26
+ Array(views).each do |path|
27
+ super(path, name, engine, &block)
28
+ end
29
+ end
17
30
  set :rrd_path, Config['rrd_path']
18
31
  set :public_folder, File.join(Config.root,'public')
19
32
  set :static, true
@@ -1,4 +1,4 @@
1
- <% content = `ps -d -o pid,user,pcpu,pmem,state,time,args --sort pcpu | sed '/^ 0.0 /d' | tail -n 30` %>
1
+ <% content = `ps -d -o pid,user,pcpu,pmem,state,time,args --sort pcpu | sed '/^ 0.0 /d'` %>
2
2
  <% if @type == 'text' then %>
3
3
  <%= content.split("\n").reverse.join("\n") %>
4
4
  <% elsif @type == 'json' %>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: collectd-interface
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,12 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-13 00:00:00.000000000 +01:00
12
+ date: 2012-03-15 00:00:00.000000000 +01:00
13
13
  default_executable: collectd-interface-daemon
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: sinatra
17
- requirement: &14088680 !ruby/object:Gem::Requirement
17
+ requirement: &18048560 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,7 +22,7 @@ dependencies:
22
22
  version: '1.3'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *14088680
25
+ version_requirements: *18048560
26
26
  description: ''
27
27
  email: vic.penso@gmail.com
28
28
  executables:
@@ -36,82 +36,6 @@ files:
36
36
  - public/script/toggle.js
37
37
  - public/style/default.css
38
38
  - public/style/nav.css
39
- - public/images/load.png
40
- - public/images/network/packets/vnet3.png
41
- - public/images/network/packets/eth0.png
42
- - public/images/network/packets/vnet4.png
43
- - public/images/network/packets/lo.png
44
- - public/images/network/packets/vnet2.png
45
- - public/images/network/packets/vnet5.png
46
- - public/images/network/packets/nbr0.png
47
- - public/images/network/packets/vnet0.png
48
- - public/images/network/packets/nbr0-nic.png
49
- - public/images/network/packets/vnet1.png
50
- - public/images/network/packets/virbr0.png
51
- - public/images/network/traffic/vnet3.png
52
- - public/images/network/traffic/eth0.png
53
- - public/images/network/traffic/vnet4.png
54
- - public/images/network/traffic/lo.png
55
- - public/images/network/traffic/vnet2.png
56
- - public/images/network/traffic/vnet5.png
57
- - public/images/network/traffic/nbr0.png
58
- - public/images/network/traffic/vnet0.png
59
- - public/images/network/traffic/nbr0-nic.png
60
- - public/images/network/traffic/vnet1.png
61
- - public/images/network/traffic/virbr0.png
62
- - public/images/irqs.png
63
- - public/images/processes.png
64
- - public/images/users.png
65
- - public/images/device/traffic/sdh.png
66
- - public/images/device/traffic/sdh2.png
67
- - public/images/device/traffic/sdh1.png
68
- - public/images/device/traffic/sda6.png
69
- - public/images/device/traffic/sda9.png
70
- - public/images/device/traffic/sdh3.png
71
- - public/images/device/traffic/sr0.png
72
- - public/images/device/traffic/sdh4.png
73
- - public/images/device/traffic/sda.png
74
- - public/images/device/traffic/sda8.png
75
- - public/images/device/traffic/sdb.png
76
- - public/images/device/traffic/sda7.png
77
- - public/images/device/traffic/sda5.png
78
- - public/images/device/traffic/sda1.png
79
- - public/images/device/traffic/sda2.png
80
- - public/images/device/traffic/sdb1.png
81
- - public/images/device/ops/sdh.png
82
- - public/images/device/ops/sdh2.png
83
- - public/images/device/ops/sdh1.png
84
- - public/images/device/ops/sda6.png
85
- - public/images/device/ops/sda9.png
86
- - public/images/device/ops/sdh3.png
87
- - public/images/device/ops/sr0.png
88
- - public/images/device/ops/sdh4.png
89
- - public/images/device/ops/sda.png
90
- - public/images/device/ops/sda8.png
91
- - public/images/device/ops/sdb.png
92
- - public/images/device/ops/sda7.png
93
- - public/images/device/ops/sda5.png
94
- - public/images/device/ops/sda1.png
95
- - public/images/device/ops/sda2.png
96
- - public/images/device/ops/sdb1.png
97
- - public/images/device/time/sdh.png
98
- - public/images/device/time/sdh2.png
99
- - public/images/device/time/sdh1.png
100
- - public/images/device/time/sda6.png
101
- - public/images/device/time/sda9.png
102
- - public/images/device/time/sdh3.png
103
- - public/images/device/time/sr0.png
104
- - public/images/device/time/sdh4.png
105
- - public/images/device/time/sda.png
106
- - public/images/device/time/sda8.png
107
- - public/images/device/time/sdb.png
108
- - public/images/device/time/sda7.png
109
- - public/images/device/time/sda5.png
110
- - public/images/device/time/sda1.png
111
- - public/images/device/time/sda2.png
112
- - public/images/device/time/sdb1.png
113
- - public/images/cpus.png
114
- - public/images/memory.png
115
39
  - public/readme/user-interface.png
116
40
  - lib/collectd/interface/service/data.rb
117
41
  - lib/collectd/interface/service/graph.rb
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file