Class: Pinba::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/pinba/request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Request

Returns a new instance of Request.



4
5
6
# File 'lib/pinba/request.rb', line 4

def initialize(options)
  self.options = options
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



3
4
5
# File 'lib/pinba/request.rb', line 3

def options
  @options
end

Instance Method Details

#cmdObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/pinba/request.rb', line 8

def cmd
  req = Proto::Pinba::Request.new 
  req.hostname = Config[:host]
  req.server_name = options[:data][:server_name]
  req.script_name = options[:data][:script_name]
  req.request_count = options[:data][:request_count]
  req.document_size = options[:data][:document_size]
  req.memory_peak = options[:data][:memory_peak]
  req.request_time = options[:data][:request_time]
  req.ru_utime = options[:data][:ru_utime]
  req.ru_stime = options[:data][:ru_stime]
  Pinba.timers.each do |timer|
     req.timer_hit_count << timer[:counter]
     req.timer_value << timer[:period]
     req.timer_tag_count << timer[:tags].size
     timer[:normalized_tags].each do |tag|
       req.timer_tag_name << tag[:name_id]
       req.dictionary << tag[:name]
       req.timer_tag_value << tag[:value_id]
       req.dictionary << tag[:value]
     end
   end
  req.status = options[:data][:status]
  # require 'ruby-debug'
  # debugger
  req.serialize_to_string
end

#performObject



36
37
38
39
40
41
42
43
44
45
# File 'lib/pinba/request.rb', line 36

def perform
  sock = nil
  begin
    sock = UDPSocket.open        
    sock.send(cmd, 0, Config[:pinba_host], Config[:pinba_port])
  rescue IOError, SystemCallError
  ensure
    sock.close if sock
  end
end