From c338a0c8cc889385dc33656fb730c673e51369c3 Mon Sep 17 00:00:00 2001 From: Georg Gadinger Date: Mon, 13 Feb 2023 20:36:15 +0100 Subject: [PATCH] add prometheus initialiser this ensures it works great in multi-process setups (like with puma) --- config/initializers/prometheus.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 config/initializers/prometheus.rb diff --git a/config/initializers/prometheus.rb b/config/initializers/prometheus.rb new file mode 100644 index 00000000..7d86c92f --- /dev/null +++ b/config/initializers/prometheus.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +return if Rails.env.test? # no need for the direct file store in testing + +require "prometheus/client/data_stores/direct_file_store" + +Rails.application.config.before_configuration do + dir = Rails.root.join("tmp/prometheus_metrics") + FileUtils.mkdir_p dir + + Prometheus::Client.config.data_store = Prometheus::Client::DataStores::DirectFileStore.new(dir:) +end + +Rails.application.config.after_initialize do + # ensure the version metric is populated + Retrospring::Metrics::VERSION_INFO +end