Class: Metrix::Metric

Inherits:
Object
  • Object
show all
Defined in:
lib/metrix/metric.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, value, time, tags = {}) ⇒ Metric

Returns a new instance of Metric.



7
8
9
10
11
12
# File 'lib/metrix/metric.rb', line 7

def initialize(key, value, time, tags = {})
  @key = key
  @value = value
  @time = time
  @tags = tags
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



5
6
7
# File 'lib/metrix/metric.rb', line 5

def key
  @key
end

#tagsObject (readonly)

Returns the value of attribute tags.



5
6
7
# File 'lib/metrix/metric.rb', line 5

def tags
  @tags
end

#timeObject (readonly)

Returns the value of attribute time.



5
6
7
# File 'lib/metrix/metric.rb', line 5

def time
  @time
end

#valueObject (readonly)

Returns the value of attribute value.



5
6
7
# File 'lib/metrix/metric.rb', line 5

def value
  @value
end

Instance Method Details

#databaseObject



29
30
31
# File 'lib/metrix/metric.rb', line 29

def database
  tags[:database]
end

#graphite_prefixObject



33
34
35
# File 'lib/metrix/metric.rb', line 33

def graphite_prefix
  "metrix.#{Metrix.hostname}"
end

#to_graphiteObject



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

def to_graphite
  chunks = [graphite_prefix]
  chunks << "databases.#{database}" if database
  chunks << key
  "#{chunks.join(".")} #{value} #{time.utc.to_i}"
end

#to_opentsdbObject



14
15
16
17
18
19
20
# File 'lib/metrix/metric.rb', line 14

def to_opentsdb
  chunks = [:put, key, time.utc.to_i, value]
  tags.merge(hostname: Metrix.hostname, database: database).each do |k, v|
    chunks << "#{k}=#{v}" if v
  end
  chunks.join(" ")
end