Class: CollectdServer::DatapointBuilder::CPU

Inherits:
CollectdServer::DatapointBuilder show all
Defined in:
lib/collectd_server/datapoint_builder.rb

Instance Attribute Summary

Attributes inherited from CollectdServer::DatapointBuilder

#host, #interval, #parts, #plugin, #plugin_instance, #timestamp, #type, #type_instance, #values

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from CollectdServer::DatapointBuilder

from_parts, inherited, #initialize, subclasses

Constructor Details

This class inherits a constructor from CollectdServer::DatapointBuilder

Class Method Details

.plugin_nameObject



71
72
73
# File 'lib/collectd_server/datapoint_builder.rb', line 71

def self.plugin_name
  'cpu'
end

Instance Method Details

#generate_datapointsObject



79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/collectd_server/datapoint_builder.rb', line 79

def generate_datapoints
  current_value = @values.values.first.value
  datapoints = []
  unless previous_value.nil?
    delta = current_value - previous_value
    rate = delta.to_f / interval
    datapoints = [Datapoint.new(metric_name, timestamp, rate)]
  end

  self.previous_value = current_value

  datapoints
end

#metric_nameObject



75
76
77
# File 'lib/collectd_server/datapoint_builder.rb', line 75

def metric_name
  super [@host, @plugin, @plugin_instance, @type_instance, 'jiffies/s']
end

#previous_valueObject



93
94
95
# File 'lib/collectd_server/datapoint_builder.rb', line 93

def previous_value
  @previous_value ||= PREVIOUS_VALUES[metric_name]
end

#previous_value=(value) ⇒ Object



97
98
99
# File 'lib/collectd_server/datapoint_builder.rb', line 97

def previous_value=(value)
  PREVIOUS_VALUES[metric_name] = value
end