Class: InfluxDB2::Point
- Inherits:
-
Object
- Object
- InfluxDB2::Point
- Defined in:
- lib/influxdb2/client/point.rb
Overview
Point defines the values that will be written to the database. Ref: bit.ly/influxdata-point
Instance Attribute Summary collapse
-
#precision ⇒ Object
readonly
Returns the value of attribute precision.
Class Method Summary collapse
-
.from_hash(data) ⇒ Object
Create DataPoint instance from specified data.
Instance Method Summary collapse
-
#add_field(key, value) ⇒ Object
Adds or replaces a field value for a point.
-
#add_tag(key, value) ⇒ Object
Adds or replaces a tag value for a point.
-
#initialize(name:, tags: nil, fields: nil, time: nil, precision: DEFAULT_WRITE_PRECISION) ⇒ Point
constructor
Create DataPoint instance for specified measurement name.
-
#time(time, precision) ⇒ Object
Updates the timestamp for the point.
-
#to_line_protocol ⇒ Object
If there is no field then return nil.
Constructor Details
#initialize(name:, tags: nil, fields: nil, time: nil, precision: DEFAULT_WRITE_PRECISION) ⇒ Point
Create DataPoint instance for specified measurement name.
43 44 45 46 47 48 49 |
# File 'lib/influxdb2/client/point.rb', line 43 def initialize(name:, tags: nil, fields: nil, time: nil, precision: DEFAULT_WRITE_PRECISION) @name = name @tags = || {} @fields = fields || {} @time = time @precision = precision end |
Instance Attribute Details
#precision ⇒ Object (readonly)
Returns the value of attribute precision.
50 51 52 |
# File 'lib/influxdb2/client/point.rb', line 50 def precision @precision end |
Class Method Details
.from_hash(data) ⇒ Object
Create DataPoint instance from specified data.
})
62 63 64 65 |
# File 'lib/influxdb2/client/point.rb', line 62 def self.from_hash(data) obj = new(name: data[:name], tags: data[:tags], fields: data[:fields], time: data[:time]) obj end |
Instance Method Details
#add_field(key, value) ⇒ Object
Adds or replaces a field value for a point.
88 89 90 91 |
# File 'lib/influxdb2/client/point.rb', line 88 def add_field(key, value) @fields[key] = value self end |
#add_tag(key, value) ⇒ Object
Adds or replaces a tag value for a point.
75 76 77 78 |
# File 'lib/influxdb2/client/point.rb', line 75 def add_tag(key, value) @tags[key] = value self end |
#time(time, precision) ⇒ Object
Updates the timestamp for the point.
107 108 109 110 111 |
# File 'lib/influxdb2/client/point.rb', line 107 def time(time, precision) @time = time @precision = precision self end |
#to_line_protocol ⇒ Object
If there is no field then return nil.
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/influxdb2/client/point.rb', line 116 def to_line_protocol line_protocol = '' measurement = _escape_key(@name || '', ESCAPE_MEASUREMENT_LIST) line_protocol << measurement = line_protocol << ",#{}" unless .empty? line_protocol << ' '.freeze if line_protocol[-1] == '\\' fields = _escape_fields return nil if fields.empty? line_protocol << " #{fields}" if fields = _escape_time(@time) line_protocol << " #{}" if line_protocol end |