Class: InfluxDB2::WriteApi
- Inherits:
-
DefaultApi
- Object
- DefaultApi
- InfluxDB2::WriteApi
- Defined in:
- lib/influxdb2/client/write_api.rb
Overview
Write time series data into InfluxDB.
Defined Under Namespace
Classes: BatchItem, BatchItemKey
Constant Summary
Constants inherited from DefaultApi
DefaultApi::DEFAULT_REDIRECT_COUNT, DefaultApi::DEFAULT_TIMEOUT, DefaultApi::HEADER_CONTENT_TYPE
Instance Attribute Summary collapse
-
#closed ⇒ Object
readonly
Returns the value of attribute closed.
Instance Method Summary collapse
-
#close! ⇒ true
Always true.
-
#initialize(options:, write_options: SYNCHRONOUS, point_settings: InfluxDB2::PointSettings.new) ⇒ WriteApi
constructor
A new instance of WriteApi.
-
#write(data:, precision: nil, bucket: nil, org: nil) ⇒ Object
Write data into specified Bucket.
- #write_raw(payload, precision: nil, bucket: nil, org: nil) ⇒ Object
Methods inherited from DefaultApi
Constructor Details
#initialize(options:, write_options: SYNCHRONOUS, point_settings: InfluxDB2::PointSettings.new) ⇒ WriteApi
Returns a new instance of WriteApi.
129 130 131 132 133 134 135 |
# File 'lib/influxdb2/client/write_api.rb', line 129 def initialize(options:, write_options: SYNCHRONOUS, point_settings: InfluxDB2::PointSettings.new) super(options: ) @write_options = @point_settings = point_settings @closed = false @options[:tags].each { |key, value| point_settings.add_default_tag(key, value) } if @options.key?(:tags) end |
Instance Attribute Details
#closed ⇒ Object (readonly)
Returns the value of attribute closed.
136 137 138 |
# File 'lib/influxdb2/client/write_api.rb', line 136 def closed @closed end |
Instance Method Details
#close! ⇒ true
Returns Always true.
191 192 193 194 195 |
# File 'lib/influxdb2/client/write_api.rb', line 191 def close! _worker.flush_all unless _worker.nil? @closed = true true end |
#write(data:, precision: nil, bucket: nil, org: nil) ⇒ Object
Write data into specified Bucket.
)
hash = { name: 'h2o', tags: { host: 'aws', region: 'us' }, fields: { level: 5, saturation: '99%' }, time: 123 }
write(data: ['h2o,location=west value=33i 15', point, hash])
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/influxdb2/client/write_api.rb', line 170 def write(data:, precision: nil, bucket: nil, org: nil) precision_param = precision || @options[:precision] bucket_param = bucket || @options[:bucket] org_param = org || @options[:org] _check('precision', precision_param) _check('bucket', bucket_param) _check('org', org_param) (data) payload = _generate_payload(data, bucket: bucket_param, org: org_param, precision: precision_param) return nil if payload.nil? if WriteType::BATCHING == @write_options.write_type _worker.push(payload) else write_raw(payload, precision: precision_param, bucket: bucket_param, org: org_param) end end |
#write_raw(payload, precision: nil, bucket: nil, org: nil) ⇒ Object
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'lib/influxdb2/client/write_api.rb', line 201 def write_raw(payload, precision: nil, bucket: nil, org: nil) precision_param = precision || @options[:precision] bucket_param = bucket || @options[:bucket] org_param = org || @options[:org] _check('precision', precision_param) _check('bucket', bucket_param) _check('org', org_param) return nil unless payload.instance_of?(String) || payload.empty? uri = _parse_uri('/api/v2/write') uri.query = URI.encode_www_form(bucket: bucket_param, org: org_param, precision: precision_param.to_s) _post_text(payload, uri) end |