Class: NewRelic::Plugin::Agent::Base

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

Direct Known Subclasses

SimpleSyntax::Agent

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context, options = {}) ⇒ Base

Instantiate a newrelic_plugin instance



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/newrelic_plugin/agent.rb', line 91

def initialize context, options = {}
  @context = context
  @options = options
  if self.class.config_options_list
    self.class.config_options_list.each do |config|
      self.send("#{config}=",options[config])
    end
  end
  @last_time = nil

  #
  # Run agent-specific metric setup, if necessary
  setup_metrics if respond_to? :setup_metrics
  @component = @context.create_component(instance_label, guid)
end

Class Attribute Details

.config_options_listObject

Returns the value of attribute config_options_list.



13
14
15
# File 'lib/newrelic_plugin/agent.rb', line 13

def config_options_list
  @config_options_list
end

.guidObject (readonly)

Returns the value of attribute guid.



12
13
14
# File 'lib/newrelic_plugin/agent.rb', line 12

def guid
  @guid
end

.instance_label_procObject (readonly)

Returns the value of attribute instance_label_proc.



12
13
14
# File 'lib/newrelic_plugin/agent.rb', line 12

def instance_label_proc
  @instance_label_proc
end

.labelObject (readonly)

Returns the value of attribute label.



12
13
14
# File 'lib/newrelic_plugin/agent.rb', line 12

def label
  @label
end

.versionObject (readonly)

Returns the value of attribute version.



12
13
14
# File 'lib/newrelic_plugin/agent.rb', line 12

def version
  @version
end

Instance Attribute Details

#nameObject (readonly)

Instance Info



72
73
74
# File 'lib/newrelic_plugin/agent.rb', line 72

def name
  @name
end

Class Method Details

.agent_config_options(*args) ⇒ Object

Specify name of configuration values used in plugin implementation.



60
61
62
63
64
65
66
# File 'lib/newrelic_plugin/agent.rb', line 60

def agent_config_options *args
  @config_options_list||=[]
  args.each do |config|
    attr_accessor config
    @config_options_list << config
  end
end

.agent_guid(str) ⇒ Object

Define the GUID for this agent.



19
20
21
22
# File 'lib/newrelic_plugin/agent.rb', line 19

def agent_guid str
  raise "Did not set GUID" if str.nil? or str==""
  @guid=str
end

.agent_human_labels(label, &block) ⇒ Object

Human Readable labels for plugin. label - Name of the plugin block return - Name of a particular instance of a plugin component.



38
39
40
41
# File 'lib/newrelic_plugin/agent.rb', line 38

def agent_human_labels label,&block
  @label=label
  @instance_label_proc=block
end

.agent_version(str) ⇒ Object

Define version for this agent



27
28
29
# File 'lib/newrelic_plugin/agent.rb', line 27

def agent_version str
  @version = str
end

.config_required?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/newrelic_plugin/agent.rb', line 51

def config_required?
  !@no_config_required
end

.no_config_requiredObject

Support for single instance, non-configurable agents.



48
49
50
# File 'lib/newrelic_plugin/agent.rb', line 48

def no_config_required
  @no_config_required=true
end

Instance Method Details

#guidObject



73
74
75
76
77
78
79
80
81
82
# File 'lib/newrelic_plugin/agent.rb', line 73

def guid
  return @guid if @guid
  @guid = self.class.guid
  #
  # Verify GUID is set correctly...
  #
  invalid_guids = ["", "guid", "_TYPE_YOUR_GUID_HERE_"]
  raise "Did not set GUID" if @guid.nil? or invalid_guids.include?(@guid)
  @guid
end

#instance_labelObject



107
108
109
110
111
112
113
114
# File 'lib/newrelic_plugin/agent.rb', line 107

def instance_label
  if !respond_to? :instance_label_proc_method
    mod=Module.new
    mod.send :define_method,:instance_label_proc_method,self.class.instance_label_proc
    self.extend mod
  end
  self.instance_label_proc_method
end

#labelObject



86
87
88
# File 'lib/newrelic_plugin/agent.rb', line 86

def label
  self.class.label
end

#report_metric(metric_name, units, value, opts = {}) ⇒ Object

Setup & Report Metrics



121
122
123
124
# File 'lib/newrelic_plugin/agent.rb', line 121

def report_metric(metric_name, units, value, opts = {} )
  return if value.nil?
  @request.add_metric(@component, "Component/#{metric_name}[#{units}]", value, opts)
end

#run(request) ⇒ Object

Execute a poll cycle



131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/newrelic_plugin/agent.rb', line 131

def run(request)
  @request = request
  #
  # Start of cycle work, if any
  cycle_start if respond_to? :cycle_start

  #
  # Collect Data
  poll_cycle

  #
  # End of cycle work, if any
  cycle_end if respond_to? :cycle_end
end

#versionObject



83
84
85
# File 'lib/newrelic_plugin/agent.rb', line 83

def version
  self.class.version
end