Sha256: 9e102ac1aa0628c0138db42ada6ab65b5ecb4fb5e893829298cfe2361b7de123

Contents?: true

Size: 1.43 KB

Versions: 33

Compression:

Stored size: 1.43 KB

Contents

require 'prometheus/client/helper/entry_parser'
require 'prometheus/client/helper/file_locker'
require 'fast_mmaped_file'

module Prometheus
  module Client
    module Helper
      class MmapedFile < FastMmapedFile
        include EntryParser

        attr_reader :filepath, :size

        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

        def close
          munmap
        end

        private

        def initial_mmap_file_size
          Prometheus::Client.configuration.initial_mmap_file_size
        end

        public

        class << self
          def open(filepath)
            MmapedFile.new(filepath)
          end

          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

          def open_exclusive_file(file_prefix = 'mmaped_file')
            filename = Helper::MmapedFile.ensure_exclusive_file(file_prefix)
            open(filename)
          end
        end
      end
    end
  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
prometheus-client-mmap-0.15.0 lib/prometheus/client/helper/mmaped_file.rb
prometheus-client-mmap-0.14.0 lib/prometheus/client/helper/mmaped_file.rb
prometheus-client-mmap-0.13.0 lib/prometheus/client/helper/mmaped_file.rb
prometheus-client-mmap-0.12.0 lib/prometheus/client/helper/mmaped_file.rb
prometheus-client-mmap-0.11.0 lib/prometheus/client/helper/mmaped_file.rb
prometheus-client-mmap-0.10.0 lib/prometheus/client/helper/mmaped_file.rb
prometheus-client-mmap-0.9.10 lib/prometheus/client/helper/mmaped_file.rb
prometheus-client-mmap-0.9.9 lib/prometheus/client/helper/mmaped_file.rb
prometheus-client-mmap-0.9.8 lib/prometheus/client/helper/mmaped_file.rb
prometheus-client-mmap-0.9.7 lib/prometheus/client/helper/mmaped_file.rb
prometheus-client-mmap-0.9.6 lib/prometheus/client/helper/mmaped_file.rb
prometheus-client-mmap-0.9.5 lib/prometheus/client/helper/mmaped_file.rb
prometheus-client-mmap-0.9.4 lib/prometheus/client/helper/mmaped_file.rb
prometheus-client-mmap-0.9.3 lib/prometheus/client/helper/mmaped_file.rb
prometheus-client-mmap-0.9.2 lib/prometheus/client/helper/mmaped_file.rb
prometheus-client-mmap-0.9.1 lib/prometheus/client/helper/mmaped_file.rb
prometheus-client-mmap-0.9.1.pre.rc.2 lib/prometheus/client/helper/mmaped_file.rb
prometheus-client-mmap-0.9.1.pre.rc.1 lib/prometheus/client/helper/mmaped_file.rb
prometheus-client-mmap-0.9.0.pre.rc.1 lib/prometheus/client/helper/mmaped_file.rb
prometheus-client-mmap-0.9.0 lib/prometheus/client/helper/mmaped_file.rb