Class: Prometheus::Client::Helper::MmapedFile
- Inherits:
-
FastMmapedFileRs
- Object
- FastMmapedFileRs
- Prometheus::Client::Helper::MmapedFile
- Includes:
- EntryParser
- Defined in:
- lib/prometheus/client/helper/mmaped_file.rb
Constant Summary
Constants included from EntryParser
EntryParser::ENCODED_LENGTH_BYTES, EntryParser::MINIMUM_SIZE, EntryParser::START_POSITION, EntryParser::VALUE_BYTES
Instance Attribute Summary collapse
-
#filepath ⇒ Object
readonly
Returns the value of attribute filepath.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
Class Method Summary collapse
- .ensure_exclusive_file(file_prefix = 'mmaped_file') ⇒ Object
- .open(filepath) ⇒ Object
- .open_exclusive_file(file_prefix = 'mmaped_file') ⇒ Object
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(filepath) ⇒ MmapedFile
constructor
A new instance of MmapedFile.
Methods included from EntryParser
#empty?, #entries, #multiprocess_mode, #parsed_entries, #parts, #pid, #to_metrics, #type, #used
Constructor Details
#initialize(filepath) ⇒ MmapedFile
Returns a new instance of MmapedFile.
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/prometheus/client/helper/mmaped_file.rb', line 20 def initialize(filepath) @filepath = filepath File.open(filepath, 'a+b') do |file| file.truncate(initial_mmap_file_size) if file.size < MINIMUM_SIZE @size = file.size end super(filepath) end |
Instance Attribute Details
#filepath ⇒ Object (readonly)
Returns the value of attribute filepath.
18 19 20 |
# File 'lib/prometheus/client/helper/mmaped_file.rb', line 18 def filepath @filepath end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
18 19 20 |
# File 'lib/prometheus/client/helper/mmaped_file.rb', line 18 def size @size end |
Class Method Details
.ensure_exclusive_file(file_prefix = 'mmaped_file') ⇒ Object
49 50 51 52 53 54 |
# File 'lib/prometheus/client/helper/mmaped_file.rb', line 49 def ensure_exclusive_file(file_prefix = 'mmaped_file') (0..Float::INFINITY).lazy .map { |f_num| "#{file_prefix}_#{Prometheus::Client.pid}-#{f_num}.db" } .map { |filename| File.join(Prometheus::Client.configuration.multiprocess_files_dir, filename) } .find { |path| Helper::FileLocker.lock_to_process(path) } end |
.open(filepath) ⇒ Object
45 46 47 |
# File 'lib/prometheus/client/helper/mmaped_file.rb', line 45 def open(filepath) MmapedFile.new(filepath) end |
.open_exclusive_file(file_prefix = 'mmaped_file') ⇒ Object
56 57 58 59 |
# File 'lib/prometheus/client/helper/mmaped_file.rb', line 56 def open_exclusive_file(file_prefix = 'mmaped_file') filename = Helper::MmapedFile.ensure_exclusive_file(file_prefix) open(filename) end |
Instance Method Details
#close ⇒ Object
31 32 33 34 |
# File 'lib/prometheus/client/helper/mmaped_file.rb', line 31 def close munmap FileLocker.unlock(filepath) end |