Class: NewRelic::Agent::NewRelicService

Inherits:
Object
  • Object
show all
Defined in:
lib/new_relic/agent/new_relic_service.rb

Defined Under Namespace

Classes: CollectorError, JsonMarshaller, Marshaller, PrubyMarshaller

Constant Summary collapse

PROTOCOL_VERSION =

Specifies the version of the agent’s communication protocol with the NewRelic hosted site.

10

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(license_key = nil, collector = control.server) ⇒ NewRelicService

Returns a new instance of NewRelicService.



22
23
24
25
26
27
# File 'lib/new_relic/agent/new_relic_service.rb', line 22

def initialize(license_key=nil, collector=control.server)
  @license_key = license_key || Agent.config[:license_key]
  @collector = collector
  @request_timeout = Agent.config[:timeout]
  load_marshaller
end

Instance Attribute Details

#agent_idObject

cf0d1ff1: v9 (tag 3.5.0) 14105: v8 (tag 2.10.3) (no v7) 10379: v6 (not tagged) 4078: v5 (tag 2.5.4) 2292: v4 (tag 2.3.6) 1754: v3 (tag 2.3.0) 534: v2 (shows up in 2.1.0, our first tag)



19
20
21
# File 'lib/new_relic/agent/new_relic_service.rb', line 19

def agent_id
  @agent_id
end

#collectorObject (readonly)

Returns the value of attribute collector.



20
21
22
# File 'lib/new_relic/agent/new_relic_service.rb', line 20

def collector
  @collector
end

#marshallerObject (readonly)

Returns the value of attribute marshaller.



20
21
22
# File 'lib/new_relic/agent/new_relic_service.rb', line 20

def marshaller
  @marshaller
end

#request_timeoutObject

cf0d1ff1: v9 (tag 3.5.0) 14105: v8 (tag 2.10.3) (no v7) 10379: v6 (not tagged) 4078: v5 (tag 2.5.4) 2292: v4 (tag 2.3.6) 1754: v3 (tag 2.3.0) 534: v2 (shows up in 2.1.0, our first tag)



19
20
21
# File 'lib/new_relic/agent/new_relic_service.rb', line 19

def request_timeout
  @request_timeout
end

Instance Method Details

#agent_command_results(command_id, error = nil) ⇒ Object



82
83
84
85
86
87
# File 'lib/new_relic/agent/new_relic_service.rb', line 82

def agent_command_results(command_id, error=nil)
  results = {}
  results["error"] = error unless error.nil?

  invoke_remote(:agent_command_results, @agent_id, { command_id.to_s => results })
end

#connect(settings = {}) ⇒ Object



40
41
42
43
44
45
46
47
# File 'lib/new_relic/agent/new_relic_service.rb', line 40

def connect(settings={})
  if host = get_redirect_host
    @collector = NewRelic::Control.instance.server_from_host(host)
  end
  response = invoke_remote(:connect, settings)
  @agent_id = response['agent_run_id']
  response
end

#error_data(unsent_errors) ⇒ Object



62
63
64
# File 'lib/new_relic/agent/new_relic_service.rb', line 62

def error_data(unsent_errors)
  invoke_remote(:error_data, @agent_id, unsent_errors)
end

#get_agent_commandsObject



78
79
80
# File 'lib/new_relic/agent/new_relic_service.rb', line 78

def get_agent_commands
  invoke_remote(:get_agent_commands, @agent_id)
end

#get_redirect_hostObject



49
50
51
# File 'lib/new_relic/agent/new_relic_service.rb', line 49

def get_redirect_host
  invoke_remote(:get_redirect_host)
end

#load_marshallerObject



29
30
31
32
33
34
35
36
37
38
# File 'lib/new_relic/agent/new_relic_service.rb', line 29

def load_marshaller
  if Agent.config[:marshaller] == :json
    require 'json'
    @marshaller = JsonMarshaller.new
  else
    @marshaller = PrubyMarshaller.new
  end
rescue LoadError
  @marshaller = PrubyMarshaller.new
end

#metric_data(last_harvest_time, now, unsent_timeslice_data) ⇒ Object



57
58
59
60
# File 'lib/new_relic/agent/new_relic_service.rb', line 57

def metric_data(last_harvest_time, now, unsent_timeslice_data)
  invoke_remote(:metric_data, @agent_id, last_harvest_time, now,
                unsent_timeslice_data)
end

#profile_data(profile) ⇒ Object



74
75
76
# File 'lib/new_relic/agent/new_relic_service.rb', line 74

def profile_data(profile)
  invoke_remote(:profile_data, @agent_id, profile.to_compressed_array) || ''
end

#shutdown(time) ⇒ Object



53
54
55
# File 'lib/new_relic/agent/new_relic_service.rb', line 53

def shutdown(time)
  invoke_remote(:shutdown, @agent_id, time.to_i) if @agent_id
end

#sql_trace_data(sql_traces) ⇒ Object



70
71
72
# File 'lib/new_relic/agent/new_relic_service.rb', line 70

def sql_trace_data(sql_traces)
  invoke_remote(:sql_trace_data, sql_traces)
end

#transaction_sample_data(traces) ⇒ Object



66
67
68
# File 'lib/new_relic/agent/new_relic_service.rb', line 66

def transaction_sample_data(traces)
  invoke_remote(:transaction_sample_data, @agent_id, traces)
end