Class: CollectdServer::DatapointBuilder
- Inherits:
-
Object
- Object
- CollectdServer::DatapointBuilder
- Defined in:
- lib/collectd_server/datapoint_builder.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#interval ⇒ Object
readonly
Returns the value of attribute interval.
-
#parts ⇒ Object
readonly
Returns the value of attribute parts.
-
#plugin ⇒ Object
readonly
Returns the value of attribute plugin.
-
#plugin_instance ⇒ Object
readonly
Returns the value of attribute plugin_instance.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#type_instance ⇒ Object
readonly
Returns the value of attribute type_instance.
-
#values ⇒ Object
readonly
Returns the value of attribute values.
Class Method Summary collapse
Instance Method Summary collapse
- #generate_datapoints ⇒ Object
-
#initialize(parts, values) ⇒ DatapointBuilder
constructor
A new instance of DatapointBuilder.
- #metric_name(parts = nil) ⇒ Object
Constructor Details
#initialize(parts, values) ⇒ DatapointBuilder
Returns a new instance of DatapointBuilder.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/collectd_server/datapoint_builder.rb', line 32 def initialize(parts, values) @parts = parts.dup parts.each do |part| next if part.content == "" case part when Packet::Host then @host = part.content when Packet::Time then @timestamp = part.content when Packet::Interval then @interval = part.content when Packet::Plugin then @plugin = part.content when Packet::PluginInstance then @plugin_instance = part.content when Packet::Type then @type = part.content when Packet::TypeInstance then @type_instance = part.content end end @values = values end |
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
27 28 29 |
# File 'lib/collectd_server/datapoint_builder.rb', line 27 def host @host end |
#interval ⇒ Object (readonly)
Returns the value of attribute interval.
27 28 29 |
# File 'lib/collectd_server/datapoint_builder.rb', line 27 def interval @interval end |
#parts ⇒ Object (readonly)
Returns the value of attribute parts.
27 28 29 |
# File 'lib/collectd_server/datapoint_builder.rb', line 27 def parts @parts end |
#plugin ⇒ Object (readonly)
Returns the value of attribute plugin.
27 28 29 |
# File 'lib/collectd_server/datapoint_builder.rb', line 27 def plugin @plugin end |
#plugin_instance ⇒ Object (readonly)
Returns the value of attribute plugin_instance.
27 28 29 |
# File 'lib/collectd_server/datapoint_builder.rb', line 27 def plugin_instance @plugin_instance end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
27 28 29 |
# File 'lib/collectd_server/datapoint_builder.rb', line 27 def @timestamp end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
27 28 29 |
# File 'lib/collectd_server/datapoint_builder.rb', line 27 def type @type end |
#type_instance ⇒ Object (readonly)
Returns the value of attribute type_instance.
27 28 29 |
# File 'lib/collectd_server/datapoint_builder.rb', line 27 def type_instance @type_instance end |
#values ⇒ Object (readonly)
Returns the value of attribute values.
27 28 29 |
# File 'lib/collectd_server/datapoint_builder.rb', line 27 def values @values end |
Class Method Details
.from_parts(parts, values) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/collectd_server/datapoint_builder.rb', line 8 def self.from_parts(parts, values) begin plugin_name = parts.detect { |p| p.is_a?(Packet::Plugin) }.content rescue NoMethodError => e puts "failed to find plugin part of #{parts.inspect}" return [] #raise e end builder = subclasses.detect { |c| c.plugin_name == plugin_name } if builder builder.new(parts, values) else warn "No builder found for plugin '#{plugin_name}'. Using default" self.new(parts, values) end.generate_datapoints end |
.inherited(subclass) ⇒ Object
65 66 67 |
# File 'lib/collectd_server/datapoint_builder.rb', line 65 def self.inherited(subclass) subclasses << subclass end |
.subclasses ⇒ Object
61 62 63 |
# File 'lib/collectd_server/datapoint_builder.rb', line 61 def self.subclasses @subclasses ||= [] end |
Instance Method Details
#generate_datapoints ⇒ Object
50 51 52 53 54 |
# File 'lib/collectd_server/datapoint_builder.rb', line 50 def generate_datapoints @values.values.map do |val| Datapoint.new(metric_name, , val.value) end end |
#metric_name(parts = nil) ⇒ Object
56 57 58 59 |
# File 'lib/collectd_server/datapoint_builder.rb', line 56 def metric_name(parts = nil) parts ||= [@host, @plugin, @plugin_instance, @type, @type_instance] parts.compact.to_csv.chomp end |