Module: Timescaledb::StatsReport

Defined in:
lib/timescaledb/stats_report.rb

Class Method Summary collapse

Class Method Details

.approximate_row_count(scope) ⇒ Object



29
30
31
32
33
# File 'lib/timescaledb/stats_report.rb', line 29

def approximate_row_count(scope)
  scope.to_a.map do |hypertable|
    { hypertable.hypertable_name => hypertable.approximate_row_count }
  end.inject(&:merge!)
end

.compression_resume(scope) ⇒ Object



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

def compression_resume(scope)
  sum = -> (method) { (scope.map(&method).inject(:+) || 0).to_s(:human_size)}
  {
    uncompressed: sum[:before_total_bytes],
    compressed: sum[:after_total_bytes]
  }
end

.resume(scope = Hypertable.all) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/timescaledb/stats_report.rb', line 6

def resume(scope=Hypertable.all)
  base_filter = {hypertable_name: scope.pluck(:hypertable_name)}
  {
    hypertables: {
      count: scope.count,
      uncompressed: scope.to_a.count { |h| h.compression_stats.empty? },
      approximate_row_count: approximate_row_count(scope),
      chunks: Chunk.where(base_filter).resume,
      size: compression_resume(scope)
    },
    continuous_aggregates: ContinuousAggregates.where(base_filter).resume,
    jobs_stats: JobStats.where(base_filter).resume
  }
end