Class: Collectd::Interface::Config

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Singleton
Defined in:
lib/collectd/interface/config.rb

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/collectd/interface/config.rb', line 12

def initialize
  # Holds all configurations
  @data = Hash.new
  # No debugging by default
  @data['debug'] = false
  # defaults for the Sinatra application
  @data['service'] = Hash.new
  @data['service']['port'] = 5000
  @data['service']['pid_path'] = String.new
  @data['service']['log_path'] = String.new
  # User defined path to graphs and reports plug-ins 
  @data['plugin_path'] = String.new
  # find the application root directory relative to this configuration file
  @data['root'] = File.expand_path(File.join(File.dirname(File.expand_path(__FILE__)),'..','..','..'))
  _hostname = `hostname -f`.chop
  # Path to the RRD file written by Collectd
  @data['rrd_path'] = File.join('/var/lib/collectd/rrd/',_hostname)
  graphs_add_build_ins()
  reports_add_build_ins()
  data_add_all_sources()
end

Instance Method Details

#[](key) ⇒ Object



34
# File 'lib/collectd/interface/config.rb', line 34

def [](key); @data[key] end

#[]=(key, value) ⇒ Object



35
# File 'lib/collectd/interface/config.rb', line 35

def []=(key,value); @data[key] = value end

#debug?Boolean

Is the application in debugging mode?

Returns:

  • (Boolean)


44
# File 'lib/collectd/interface/config.rb', line 44

def debug?; self['debug'] end

#inspectObject



39
40
41
# File 'lib/collectd/interface/config.rb', line 39

def inspect
  %Q[-- Config --\n#{self.to_json}\n------------] 
end

#log_file(name) ⇒ Object

Path to the log file.



62
63
64
# File 'lib/collectd/interface/config.rb', line 62

def log_file(name)
  File.join(self['service']['log_path'],"#{name}.log")
end

#log_file?Boolean

Does the user wants to write a log file?

Returns:

  • (Boolean)


58
59
60
# File 'lib/collectd/interface/config.rb', line 58

def log_file?
  self['service']['log_path'].empty?
end

#pid_file(name) ⇒ Object

Path to the PID file.



54
55
56
# File 'lib/collectd/interface/config.rb', line 54

def pid_file(name)
  File.join(self['service']['pid_path'],"#{name}.pid")
end

#pid_file?Boolean

Does the user wants to write a file containing the PID?

Returns:

  • (Boolean)


50
51
52
# File 'lib/collectd/interface/config.rb', line 50

def pid_file?
  self['service']['pid_path'].empty?
end

#plugin_path(path) ⇒ Object

Add optional user plug-ins to the configuration, where path is the path to the directory containing graph and report plug-ins.



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/collectd/interface/config.rb', line 69

def plugin_path(path)
  # will be added to the Sinatra views array
  self['plugin_path'] = path
  # add all optional graphs
  _path = File.join(path,'graphs')
  if File.directory? _path
    Dir["#{_path}/**/*.erb"].each do |file|
      graphs_add_plugin(_path,file)
    end
  end
  # add all optional reports
  _path = File.join(path,'reports')
  if File.directory? _path
    Dir["#{_path}/**/*.erb"].each do |file|
      reports_add_plugin(_path,file)
    end
  end
end

#rootObject

Path to the application root directory.



47
# File 'lib/collectd/interface/config.rb', line 47

def root; self['root'] end

#to_jsonObject



37
# File 'lib/collectd/interface/config.rb', line 37

def to_json; JSON.pretty_generate(@data) end