Class: DTK::State::Component::Attribute::Influxdb::Measurement
- Inherits:
-
Object
- Object
- DTK::State::Component::Attribute::Influxdb::Measurement
show all
- Defined in:
- lib/state/component/providers/influxdb/measurement.rb,
lib/state/component/providers/influxdb/measurement/errors.rb,
lib/state/component/providers/influxdb/measurement/events.rb,
lib/state/component/providers/influxdb/measurement/states.rb,
lib/state/component/providers/influxdb/measurement/attribute_measurement.rb
Defined Under Namespace
Classes: Attributes, Errors, Events, InfluxdbEncoding, States
Instance Method Summary
collapse
Constructor Details
#initialize(name, client) ⇒ Measurement
Returns a new instance of Measurement.
9
10
11
12
|
# File 'lib/state/component/providers/influxdb/measurement.rb', line 9
def initialize(name, client)
@name = name
@client = client
end
|
Instance Method Details
#flux_filter(params_hash) ⇒ Object
14
15
16
17
18
19
20
|
# File 'lib/state/component/providers/influxdb/measurement.rb', line 14
def flux_filter(params_hash)
filter = ''
params_hash.each_pair do |key,value|
filter += "|> filter(fn: (r) => r.#{key} == \"#{value}\")"
end
filter
end
|
#get_last_point(params_hash = {}) ⇒ Object
22
23
24
25
26
27
28
29
|
# File 'lib/state/component/providers/influxdb/measurement.rb', line 22
def get_last_point(params_hash = {})
check_params_hash(params_hash)
flux_query = 'from(bucket:"' + client.connection_parameters[:bucket] + '") |> range(start:-5) |> filter(fn: (r) => r._measurement == "' + name.to_s + '")' + flux_filter(params_hash) + ' |> last()' + '|> drop(columns: ["_start", "_stop", "_field", "_measurement", "attribute_name", "assembly_name", "task_id", "component_name", "namespace"])'
result = self.client.query(query: flux_query)
result.values.map(&:records).flatten.map(&:values)
rescue => e
raise "Failed while getting last attribute point. Error: #{e}"
end
|
31
32
33
34
35
36
37
38
39
|
# File 'lib/state/component/providers/influxdb/measurement.rb', line 31
def get_required_tags(namespace, component_name, assembly_name, attribute_name)
required_tags = {
namespace: namespace,
component_name: component_name,
assembly_name: assembly_name,
attribute_name: attribute_name,
task_id: "1"
}
end
|