Class: CpuInspectCore::Backends::FileBackend
- Inherits:
-
Object
- Object
- CpuInspectCore::Backends::FileBackend
- Defined in:
- lib/cpu_inspect_core/backends/file_backend.rb
Overview
Default backend: in-process Store + rotating local log file. Works correctly on a single dyno or in local development. On Heroku with multiple dynos each dyno has its own isolated instance —use RedisBackend to aggregate across dynos.
Instance Method Summary collapse
-
#all_dynos ⇒ Object
Returns { dyno_name => sample } for the local process only.
-
#initialize(config) ⇒ FileBackend
constructor
A new instance of FileBackend.
-
#latest ⇒ Object
Most recent sample from this process.
- #write(payload) ⇒ Object
Constructor Details
#initialize(config) ⇒ FileBackend
Returns a new instance of FileBackend.
13 14 15 16 |
# File 'lib/cpu_inspect_core/backends/file_backend.rb', line 13 def initialize(config) @store = Store.new @log_writer = LogWriter.new(config) end |
Instance Method Details
#all_dynos ⇒ Object
Returns { dyno_name => sample } for the local process only.
29 30 31 32 33 34 |
# File 'lib/cpu_inspect_core/backends/file_backend.rb', line 29 def all_dynos sample = @store.latest return {} if sample.nil? { ENV.fetch('DYNO', 'local') => sample } end |
#latest ⇒ Object
Most recent sample from this process.
24 25 26 |
# File 'lib/cpu_inspect_core/backends/file_backend.rb', line 24 def latest @store.latest end |
#write(payload) ⇒ Object
18 19 20 21 |
# File 'lib/cpu_inspect_core/backends/file_backend.rb', line 18 def write(payload) @store.push(payload) @log_writer.write(payload) end |