Class: Kstats::Node::Probe

Inherits:
Object
  • Object
show all
Defined in:
lib/kstats/node/probe.rb

Defined Under Namespace

Classes: DSL, Variable

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id) ⇒ Probe

Returns a new instance of Probe.



117
118
119
120
# File 'lib/kstats/node/probe.rb', line 117

def initialize id
  @variables = []
  @id = id
end

Class Attribute Details

.registeredObject

Returns the value of attribute registered.



6
7
8
# File 'lib/kstats/node/probe.rb', line 6

def registered
  @registered
end

Instance Attribute Details

#categoryObject

Returns the value of attribute category.



115
116
117
# File 'lib/kstats/node/probe.rb', line 115

def category
  @category
end

#commandObject

Returns the value of attribute command.



115
116
117
# File 'lib/kstats/node/probe.rb', line 115

def command
  @command
end

#command_blockObject

Returns the value of attribute command_block.



115
116
117
# File 'lib/kstats/node/probe.rb', line 115

def command_block
  @command_block
end

#idObject (readonly)

Returns the value of attribute id.



114
115
116
# File 'lib/kstats/node/probe.rb', line 114

def id
  @id
end

#nameObject

Returns the value of attribute name.



115
116
117
# File 'lib/kstats/node/probe.rb', line 115

def name
  @name
end

#typeObject

Returns the value of attribute type.



115
116
117
# File 'lib/kstats/node/probe.rb', line 115

def type
  @type
end

#variablesObject

Returns the value of attribute variables.



115
116
117
# File 'lib/kstats/node/probe.rb', line 115

def variables
  @variables
end

Class Method Details

.get_format(probe) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/kstats/node/probe.rb', line 12

def get_format probe
  probe = @fixed_registered.select{|x| x.id == probe }.first
  if probe.nil?
    return nil
  else
    {
      type: probe.type,
      variables: probe.variables.inject({}){ |h, x|
        h[x.name] = {}
        h[x.name][:desc] = x.desc
        h[x.name][:color] = x.color
        h
      }
    }
  end
end

.listObject



60
61
62
63
64
65
66
67
68
# File 'lib/kstats/node/probe.rb', line 60

def list
  probe_categories = {}
  @fixed_registered.each do |probe|
    probe_categories[probe.category] ||= []
    probe_categories[probe.category] << { name: probe.name, id: probe.id }
  end

  probe_categories
end

.register(name, &block) ⇒ Object



8
9
10
# File 'lib/kstats/node/probe.rb', line 8

def register name, &block
  @registered << Probe.new(name).from_dsl(&block)
end

.reload_and_test!Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/kstats/node/probe.rb', line 29

def reload_and_test!
  @fixed_registered = @registered
  @registered = []

  dir = Kstats::Node::Config['probes_dir']

  Dir[File.join(dir, "*.rb")].each do |probe_file|
    begin
      load(probe_file)
    rescue => e
      puts "Unable to load #{probe_file}: #{e}"
      puts "*\t#{e.backtrace.join("\n*\t")}"
    end
  end

  probes = {}

    @registered.each do |probe|
      begin
        probes[probe.id] = probe.test
      rescue => e
        puts "Exception for probe #{probe.id} : #{e.message}"
        puts "*\t#{e.backtrace.join("\n*\t")}"
      end
    end

  @fixed_registered  = @registered

  probes
end

Instance Method Details

#add_variable(var) ⇒ Object



128
129
130
# File 'lib/kstats/node/probe.rb', line 128

def add_variable var
  @variables << var
end

#from_dsl(&block) ⇒ Object



122
123
124
125
126
# File 'lib/kstats/node/probe.rb', line 122

def from_dsl &block
  DSL.new(self).instance_eval(&block)

  return self
end

#testObject



132
133
134
135
136
# File 'lib/kstats/node/probe.rb', line 132

def test
  @command = self.command_block.call unless self.command_block.nil?

  @variables.inject({}){|h, x| h[x.name] = x.test; h }
end