Class: Monitoring::Client::Profiler

Inherits:
Object
  • Object
show all
Defined in:
lib/monitoring/client/profiler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(program_name, decorations = {}) ⇒ Profiler

Returns a new instance of Profiler.



13
14
15
16
17
# File 'lib/monitoring/client/profiler.rb', line 13

def initialize(program_name, decorations = {})
  self.config = Config.global
  self.program_name = program_name
  self.decorations = default_decorations.merge(decorations)
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



11
12
13
# File 'lib/monitoring/client/profiler.rb', line 11

def config
  @config
end

#decorationsObject

Returns the value of attribute decorations.



11
12
13
# File 'lib/monitoring/client/profiler.rb', line 11

def decorations
  @decorations
end

#program_nameObject

Returns the value of attribute program_name.



11
12
13
# File 'lib/monitoring/client/profiler.rb', line 11

def program_name
  @program_name
end

Instance Method Details

#compile(routine) ⇒ Object



28
29
30
# File 'lib/monitoring/client/profiler.rb', line 28

def compile(routine)
  Compiler.compile(self, routine)
end

#default_decorationsObject



41
42
43
44
45
46
# File 'lib/monitoring/client/profiler.rb', line 41

def default_decorations
  {
    :hostname => config.hostname,
    :hostgroup => config.hostgroup,
  }
end

#json_encode(what) ⇒ Object



37
38
39
# File 'lib/monitoring/client/profiler.rb', line 37

def json_encode(what)
  Yajl::Encoder.encode(what)
end

#post_metrics(compiled) ⇒ Object



32
33
34
35
# File 'lib/monitoring/client/profiler.rb', line 32

def post_metrics(compiled)
  UDPSocket.new().send(json_encode(compiled) + "\n",
                       0, "localhost", 57475)
end

#routine(routine_name) {|routine| ... } ⇒ Object

Yields:



20
21
22
23
24
25
26
# File 'lib/monitoring/client/profiler.rb', line 20

def routine(routine_name)
  routine = Routine.new(routine_name)
  yield(routine)
  compiled = compile(routine)
  post_metrics(compiled)
  routine
end