class Prometheus::Client::DataStores::DirectFileStore
Stores data in binary files, one file per process and per metric. This is generally the recommended store to use to deal with pre-fork servers and other “multi-process” scenarios.
Each process will get a file for a metric, and it will manage its contents by storing keys next to binary-encoded Floats, and keeping track of the offsets of those Floats, to be able to update them directly as they increase.
When exporting metrics, the process that gets scraped by Prometheus
will find all the files that apply to a metric, read their contents, and aggregate them (generally that means SUMming the values for each labelset).
In order to do this, each Metric
needs an `:aggregation` setting, specifying how to aggregate the multiple possible values we can get for each labelset. By default, Counters, Histograms and Summaries get `SUM`med, and Gauges will report `ALL` values, tagging each one with a `pid` label. For Gauges, it's also possible to set `SUM`, MAX` or `MIN` as aggregation, to get the highest / lowest value / or the sum of all the processes / threads.
Before using this Store, please read the “`DirectFileStore` caveats and things to keep in mind” section of the main README in this repository. It includes a number of important things to keep in mind.
Constants
- AGGREGATION_MODES
- DEFAULT_GAUGE_SETTINGS
- DEFAULT_METRIC_SETTINGS
Public Class Methods
# File lib/prometheus/client/data_stores/direct_file_store.rb, line 36 def initialize(dir:) @store_settings = { dir: dir } FileUtils.mkdir_p(dir) end
Public Instance Methods
# File lib/prometheus/client/data_stores/direct_file_store.rb, line 41 def for_metric(metric_name, metric_type:, metric_settings: {}) default_settings = DEFAULT_METRIC_SETTINGS if metric_type == :gauge default_settings = DEFAULT_GAUGE_SETTINGS end settings = default_settings.merge(metric_settings) validate_metric_settings(settings) MetricStore.new(metric_name: metric_name, store_settings: @store_settings, metric_settings: settings) end
Private Instance Methods
# File lib/prometheus/client/data_stores/direct_file_store.rb, line 57 def validate_metric_settings(metric_settings) unless metric_settings.has_key?(:aggregation) && AGGREGATION_MODES.include?(metric_settings[:aggregation]) raise InvalidStoreSettingsError, "Metrics need a valid :aggregation key" end unless (metric_settings.keys - [:aggregation]).empty? raise InvalidStoreSettingsError, "Only :aggregation setting can be specified" end end