Class: One2Influx::OneObject

Inherits:
Object
  • Object
show all
Defined in:
lib/one2influx/one_object/one_object.rb

Overview

‘Abstract’ class for OpenNebula’s objects representation

Direct Known Subclasses

Cluster, Datastore, Host, VirtualMachine

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xml, client) ⇒ OneObject

Creates mapping between ONE XML names and InfluxDB storage names. Loads all tags, metrics and custom metrics from given XML.

Parameters:

  • xml (string)

    representation of OneObject

  • client (OpenNebula::Client)

    connection link to ONE API



10
11
12
13
14
15
16
17
18
19
# File 'lib/one2influx/one_object/one_object.rb', line 10

def initialize(xml, client)
  @tags ||= Hash.new
  @metrics ||= Hash.new
  @doc ||= Nokogiri::XML(xml)
  @client = client

  init_tags
  init_metrics
  init_custom_metrics
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object

Called in case of misconfiguration and invalid custom metric method was called



39
40
41
42
# File 'lib/one2influx/one_object/one_object.rb', line 39

def method_missing(name, *args, &block)
  $LOG.error "Invalid method '#{name}' was called from #{self.class}! " #+
    #  "Stacktrace: #{e.backtrace}"
end

Instance Attribute Details

#docObject (readonly)

Returns the value of attribute doc.



4
5
6
# File 'lib/one2influx/one_object/one_object.rb', line 4

def doc
  @doc
end

#metricsObject (readonly)

Returns the value of attribute metrics.



4
5
6
# File 'lib/one2influx/one_object/one_object.rb', line 4

def metrics
  @metrics
end

#tagsObject (readonly)

Returns the value of attribute tags.



4
5
6
# File 'lib/one2influx/one_object/one_object.rb', line 4

def tags
  @tags
end

Instance Method Details

#serialize_as_pointsObject

Serialize OneObject instance to InfluxDB point form



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/one2influx/one_object/one_object.rb', line 22

def serialize_as_points
  points = []
  @metrics.each do |metric_name, metric_value|
    points << {
        :name => metric_name,
        :tags => @tags,
        :fields => {
            :value => metric_value.to_f
        }
    }
  end

  return points
end