Class: FFWD::Metric

Inherits:
MetricStruct show all
Defined in:
lib/ffwd/metric.rb

Overview

A convenience class for each individual metric.

Instance Attribute Summary

Attributes inherited from MetricStruct

#external_attr, #external_tags, #fixed_attr, #fixed_tags, #host, #key, #source, #time, #value

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.make(opts = {}) ⇒ Object



43
44
45
46
47
# File 'lib/ffwd/metric.rb', line 43

def self.make opts={}
  new(opts[:time], opts[:key], opts[:value], opts[:host], opts[:source],
      opts[:tags], opts[:fixed_tags],
      opts[:attributes], opts[:fixed_attr])
end

Instance Method Details

#attributesObject

maintained for backwards compatibility, but implementors are encouraged to use internal/external attributes directly.



51
52
53
# File 'lib/ffwd/metric.rb', line 51

def attributes
  FFWD.merge_hashes fixed_attr, external_attr
end

#tagsObject



55
56
57
# File 'lib/ffwd/metric.rb', line 55

def tags
  FFWD.merge_sets fixed_tags, external_tags
end

#to_hObject

Convert metric to a sparse hash.



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/ffwd/metric.rb', line 60

def to_h
  d = {}
  d[:time] = time.to_i if time
  d[:key] = key if key
  d[:value] = value if value
  d[:host] = host if host
  d[:source] = source if source

  if t = tags and not t.empty?
    d[:tags] = t
  end

  if a = attributes and not a.empty?
    d[:attributes] = a
  end

  d
end