Class: Fog::Joyent::Analytics::Instrumentation

Inherits:
Model
  • Object
show all
Defined in:
lib/fog/joyent/models/analytics/instrumentation.rb

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Instrumentation


23
24
25
26
27
28
29
30
31
# File 'lib/fog/joyent/models/analytics/instrumentation.rb', line 23

def initialize(attributes={})
  self.decomposition = []
  self.value_arity = 'scalar'
  self.retention_time = 600
  self.idle_max = 3600
  self.persist_data = false
  self.value_scope = 'interval'
  super
end

Instance Method Details

#crtime=(new_crtime) ⇒ Object


33
34
35
# File 'lib/fog/joyent/models/analytics/instrumentation.rb', line 33

def crtime=(new_crtime)
  attributes[:crtime] = Time.at(new_crtime.to_i / 1000)
end

#decomposition=(value) ⇒ Object


37
38
39
40
41
# File 'lib/fog/joyent/models/analytics/instrumentation.rb', line 37

def decomposition=(value)
  attributes[:decomposition] = value
  self.value_dimension = self.decomposition.size + 1
  self.decomposition
end

#destroyObject


61
62
63
64
65
# File 'lib/fog/joyent/models/analytics/instrumentation.rb', line 61

def destroy
  requires :id
  service.delete_instrumentation(self.identity)
  true
end

#saveObject


43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/fog/joyent/models/analytics/instrumentation.rb', line 43

def save
  requires :joyent_module, :stat
  munged_attributes = self.attributes.dup
  remap_attributes(munged_attributes, {
      :joyent_module => 'module',
      :value_dimension => 'value-dimension',
      :value_arity => 'value-arity',
      :retention_time => 'retention-time',
      :idle_max => 'idle-max',
      :persist_data => 'persist-data',
      :value_scope => 'value-scope'
  })

  data = service.create_instrumentation(munged_attributes)
  merge_attributes(data.body)
  true
end

#values(start_time, ndatapoints) ⇒ Object

Get a set of datapoints back for an instrumentation use start_time and ndatapoints so we can get back a range of datapoints the interval between datapoints should correspond to the granularity of the instrumentation


72
73
74
75
76
77
78
# File 'lib/fog/joyent/models/analytics/instrumentation.rb', line 72

def values(start_time, ndatapoints)
  requires :id, :granularity
  data = service.get_instrumentation_value(self.uris.find {|uri| uri['name'] == 'value_raw'}['uri'], start_time, ndatapoints, self.granularity).body
  data.map do |datum|
    Fog::Joyent::Analytics::Value.new(datum)
  end
end