Module: InfluxDB::Query::RetentionPolicy

Included in:
Client
Defined in:
lib/influxdb/query/retention_policy.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#alter_retention_policy(name, database, duration, replication, default = false, shard_duration: nil) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/influxdb/query/retention_policy.rb', line 33

def alter_retention_policy(name,
                           database,
                           duration,
                           replication,
                           default = false,
                           shard_duration: nil)
  execute(
    "ALTER RETENTION POLICY \"#{name}\" ON \"#{database}\" " \
    "DURATION #{duration} REPLICATION #{replication}" \
    "#{shard_duration ? " SHARD DURATION #{shard_duration}" : ''}" \
    "#{default ? ' DEFAULT' : ''}"
  )
end

#create_retention_policy(name, database, duration, replication, default = false, shard_duration: nil) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/influxdb/query/retention_policy.rb', line 4

def create_retention_policy(name,
                            database,
                            duration,
                            replication,
                            default = false,
                            shard_duration: nil)
  execute(
    "CREATE RETENTION POLICY \"#{name}\" ON \"#{database}\" " \
    "DURATION #{duration} REPLICATION #{replication}" \
    "#{shard_duration ? " SHARD DURATION #{shard_duration}" : ''}" \
    "#{default ? ' DEFAULT' : ''}"
  )
end

#delete_retention_policy(name, database) ⇒ Object



29
30
31
# File 'lib/influxdb/query/retention_policy.rb', line 29

def delete_retention_policy(name, database)
  execute("DROP RETENTION POLICY \"#{name}\" ON \"#{database}\"")
end

#list_retention_policies(database) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/influxdb/query/retention_policy.rb', line 18

def list_retention_policies(database)
  resp = execute("SHOW RETENTION POLICIES ON \"#{database}\"", parse: true)
  data = fetch_series(resp).fetch(0, {})

  data.fetch("values".freeze, []).map do |policy|
    policy.each.with_index.inject({}) do |hash, (value, index)|
      hash.tap { |h| h[data['columns'.freeze][index]] = value }
    end
  end
end