Class: HeapScope::TrendStore
- Inherits:
-
Object
- Object
- HeapScope::TrendStore
- Defined in:
- lib/heapscope/trend_store.rb
Overview
Persists monitor samples for historical trend reports.
Instance Method Summary collapse
- #append(sample_hash) ⇒ Object
-
#initialize(path) ⇒ TrendStore
constructor
A new instance of TrendStore.
- #load ⇒ Object
- #summary ⇒ Object
Constructor Details
#initialize(path) ⇒ TrendStore
Returns a new instance of TrendStore.
8 9 10 |
# File 'lib/heapscope/trend_store.rb', line 8 def initialize(path) @path = path end |
Instance Method Details
#append(sample_hash) ⇒ Object
12 13 14 15 16 17 |
# File 'lib/heapscope/trend_store.rb', line 12 def append(sample_hash) rows = load rows << sample_hash File.write(@path, JSON.pretty_generate(rows)) rows.size end |
#load ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/heapscope/trend_store.rb', line 19 def load return [] unless File.exist?(@path) JSON.parse(File.read(@path), symbolize_names: true) rescue StandardError [] end |
#summary ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/heapscope/trend_store.rb', line 27 def summary rows = load return { samples: 0 } if rows.empty? rss = rows.map { |r| r[:rss_bytes].to_i } live = rows.map { |r| r[:live_slots].to_i } { samples: rows.size, rss: { first: rss.first, last: rss.last, delta: rss.last - rss.first, max: rss.max }, live_slots: { first: live.first, last: live.last, delta: live.last - live.first, max: live.max }, top_classes: rows.map { |r| r[:top_class] }.compact.tally.sort_by { |_, v| -v }.first(5) } end |