Class: NewRelic::Binding::Request

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context) ⇒ Request

Returns a new instance of Request.



7
8
9
10
11
12
13
# File 'lib/newrelic_platform_binding/request.rb', line 7

def initialize(context)
  @context = context
  @duration = nil
  @metrics = {}
  @delivered = false
  return self
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



5
6
7
# File 'lib/newrelic_platform_binding/request.rb', line 5

def context
  @context
end

Instance Method Details

#add_metric(component, name, value, options = {}) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/newrelic_platform_binding/request.rb', line 33

def add_metric(component, name, value, options = {})
  metric = find_metric(component, name)
  new_metric =  Metric.new(self, name, value, options)
  if metric.nil?
    metric = new_metric
    @metrics[component.key] ||= []
    @metrics[component.key].push(metric)
  else
    metric.aggregate(new_metric)
  end
  return metric
end

#component_countObject



54
55
56
# File 'lib/newrelic_platform_binding/request.rb', line 54

def component_count
  @metrics.size
end

#deliverObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/newrelic_platform_binding/request.rb', line 15

def deliver
  metrics_hash = build_request_data_structure
  connection = Connection.new(@context)
  if connection.send_request(metrics_hash.to_json)
    @delivered = true
    delivered_at = Time.now
    context.last_request_delivered_at = delivered_at
    duration_warning = false
    @context.components.each do |component|
      if @metrics.has_key?(component.key)
        duration_warning = true if component.duration > 600
        component.last_delivered_at = delivered_at
      end
    end
    PlatformLogger.warn("Duration of more than 10 minutes between sending data to New Relic, this will cause plugins to show up as not reporting") if duration_warning
  end
end

#delivered?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/newrelic_platform_binding/request.rb', line 58

def delivered?
  @delivered
end

#metric_countObject



46
47
48
49
50
51
52
# File 'lib/newrelic_platform_binding/request.rb', line 46

def metric_count
  count = 0
  @metrics.each do |m|
    count = count + m.size
  end
  count
end