Class: Prometheus::Client::DataStores::DirectFileStore
- Inherits:
-
Object
- Object
- Prometheus::Client::DataStores::DirectFileStore
- Defined in:
- lib/prometheus/client/data_stores/direct_file_store.rb
Overview
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, they are ‘SUM`med, which is what most use cases call for (counters and histograms, for example). However, for Gauges, it’s possible to set MAX or MIN as aggregation, to get the highest value of all the processes / threads.
Defined Under Namespace
Classes: FileMappedDict, InvalidStoreSettingsError
Constant Summary collapse
- AGGREGATION_MODES =
[MAX = :max, MIN = :min, SUM = :sum, ALL = :all]
- DEFAULT_METRIC_SETTINGS =
{ aggregation: SUM }
- DEFAULT_GAUGE_SETTINGS =
{ aggregation: ALL }
Instance Method Summary collapse
- #for_metric(metric_name, metric_type:, metric_settings: {}) ⇒ Object
-
#initialize(dir:) ⇒ DirectFileStore
constructor
A new instance of DirectFileStore.
Constructor Details
#initialize(dir:) ⇒ DirectFileStore
Returns a new instance of DirectFileStore.
32 33 34 35 |
# File 'lib/prometheus/client/data_stores/direct_file_store.rb', line 32 def initialize(dir:) @store_settings = { dir: dir } FileUtils.mkdir_p(dir) end |
Instance Method Details
#for_metric(metric_name, metric_type:, metric_settings: {}) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/prometheus/client/data_stores/direct_file_store.rb', line 37 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 |