Class: Metrico::Point

Inherits:
Object
  • Object
show all
Defined in:
lib/metrico/point.rb

Constant Summary collapse

ESCAPES =
{
  measurement:  [' '.freeze, ','.freeze],
  tag_key:      ['='.freeze, ' '.freeze, ','.freeze],
  tag_value:    ['='.freeze, ' '.freeze, ','.freeze],
  field_key:    ['='.freeze, ' '.freeze, ','.freeze, '"'.freeze],
  field_value:  ["\\".freeze, '"'.freeze],
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, fields, tags = {}) ⇒ Point



5
6
7
8
9
10
# File 'lib/metrico/point.rb', line 5

def initialize(name, fields, tags = {})
  @name = measurement(name)
  @fields = escape_fields(fields)
  tags = { hostname: Metrico.config.hostname }.merge(tags)
  @tags = escape_tags(tags)
end

Instance Attribute Details

#fieldsObject

Returns the value of attribute fields.



3
4
5
# File 'lib/metrico/point.rb', line 3

def fields
  @fields
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/metrico/point.rb', line 3

def name
  @name
end

#tagsObject

Returns the value of attribute tags.



3
4
5
# File 'lib/metrico/point.rb', line 3

def tags
  @tags
end

Instance Method Details

#to_sObject

docs.influxdata.com/influxdb/v1.3/write_protocols/line_protocol_tutorial/ InfluxDB Line Protocol weather,location=us-midwest temperature=82 1465839830100400200

|    -------------------- --------------  |
|             |             |             |
|             |             |             |

-----------——–-———-———+ |measurement|,tag_set| |field_set| |timestamp| -----------——–-———-———+



21
22
23
24
25
26
27
# File 'lib/metrico/point.rb', line 21

def to_s
  str = "#{name}"
  str << ",#{tags}" if tags
  str << " #{fields}"
  str << " #{timestamp}"
  str
end