Class: PCPEasy::Metric

Inherits:
Object
  • Object
show all
Defined in:
lib/pcp_easy/metric.rb,
lib/pcp_easy/metric/value.rb

Defined Under Namespace

Classes: Value

Instance Method Summary collapse

Constructor Details

#initialize(name, pm_desc, metric_values) ⇒ Metric

Returns a new instance of Metric.



6
7
8
9
10
# File 'lib/pcp_easy/metric.rb', line 6

def initialize(name, pm_desc, metric_values)
  @name = name
  @pm_desc = pm_desc
  @metric_values = metric_values
end

Instance Method Details

#==(other) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/pcp_easy/metric.rb', line 20

def ==(other)
  self.class == other.class && \
  name == other.name && \
  values == other.values && \
  semantics == other.semantics && \
  type == other.type && \
  units == other.units
end

#inspectObject



102
103
104
# File 'lib/pcp_easy/metric.rb', line 102

def inspect
  "<#{self.class.to_s} name=#{name} values=#{values} semantics=#{semantics} type=#{type} units=#{units}>"
end

#nameObject



12
13
14
# File 'lib/pcp_easy/metric.rb', line 12

def name
  @name
end

#semanticsObject



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/pcp_easy/metric.rb', line 29

def semantics
  case @pm_desc.sem
    when PCPEasy::PMAPI::PM_SEM_COUNTER
      :counter
    when PCPEasy::PMAPI::PM_SEM_INSTANT
      :instant
    when PCPEasy::PMAPI::PM_SEM_DISCRETE
      :discrete
    else
      :unknown
  end
end

#typeObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/pcp_easy/metric.rb', line 43

def type
  case @pm_desc.type
    when PCPEasy::PMAPI::PM_TYPE_NOSUPPORT
      :no_support
    when PCPEasy::PMAPI::PM_TYPE_32
      :int32
    when PCPEasy::PMAPI::PM_TYPE_U32
      :uint32
    when PCPEasy::PMAPI::PM_TYPE_64
      :int64
    when PCPEasy::PMAPI::PM_TYPE_U64
      :uint64
    when PCPEasy::PMAPI::PM_TYPE_FLOAT
      :float
    when PCPEasy::PMAPI::PM_TYPE_DOUBLE
      :double
    when PCPEasy::PMAPI::PM_TYPE_STRING
      :string
    when PCPEasy::PMAPI::PM_TYPE_AGGREGATE
      :aggregate
    when PCPEasy::PMAPI::PM_TYPE_AGGREGATE_STATIC
      :aggregate_static
    when PCPEasy::PMAPI::PM_TYPE_EVENT
      :event
    when PCPEasy::PMAPI::PM_TYPE_HIGHRES_EVENT
      :highres_event
    else
      :unknown
  end
end

#unitsObject



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/pcp_easy/metric.rb', line 74

def units
  pm_units = @pm_desc.units

  if pm_units.dim_space == 1 && pm_units.dim_time == 0 && pm_units.dim_count == 0
    {:domain => space_unit(pm_units.scale_space), :range => nil}
  elsif pm_units.dim_space == 1 && pm_units.dim_time == -1 && pm_units.dim_count == 0
    {:domain => space_unit(pm_units.scale_space), :range => time_unit(pm_units.scale_time)}
  elsif pm_units.dim_space == 1 && pm_units.dim_time == 0 && pm_units.dim_count == -1
    {:domain => space_unit(pm_units.scale_space), :range => count_unit(pm_units.scale_count)}

  elsif pm_units.dim_space == 0 && pm_units.dim_time == 1 && pm_units.dim_count == 0
    {:domain => time_unit(pm_units.scale_time), :range => nil}
  elsif pm_units.dim_space == -1 && pm_units.dim_time == 1 && pm_units.dim_count == 0
    {:domain => time_unit(pm_units.scale_time), :range => space_unit(pm_units.scale_space)}
  elsif pm_units.dim_space == 0 && pm_units.dim_time == 1 && pm_units.dim_count == -1
    {:domain => time_unit(pm_units.scale_time), :range => count_unit(pm_units.scale_count)}

  elsif pm_units.dim_space == 0 && pm_units.dim_time == 0 && pm_units.dim_count == 1
    {:domain => count_unit(pm_units.scale_count), :range => nil}
  elsif pm_units.dim_space == -1 && pm_units.dim_time == 0 && pm_units.dim_count == 1
    {:domain => count_unit(pm_units.scale_count), :range => space_unit(pm_units.scale_space)}
  elsif pm_units.dim_space == 0 && pm_units.dim_time == -1 && pm_units.dim_count == 1
    {:domain => count_unit(pm_units.scale_count), :range => time_unit(pm_units.scale_time)}
  else
    {:domain => nil, :range => nil}
  end
end

#valuesObject



16
17
18
# File 'lib/pcp_easy/metric.rb', line 16

def values
  @metric_values
end