Skip to content

Commit

Permalink
Merge pull request #255 from alphagov/sidekiq_monitoring
Browse files Browse the repository at this point in the history
Add Sidekiq Prometheus instrumentation
  • Loading branch information
fredericfran-gds authored Aug 12, 2022
2 parents f63ddb7 + e600fd6 commit 48636bb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/govuk_app_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
# This require is deprecated and should be removed on next major version bump
# and should be required by applications directly.
require "govuk_app_config/govuk_unicorn"
require "govuk_app_config/govuk_prometheus_exporter"

if defined?(Rails)
require "govuk_app_config/govuk_prometheus_exporter"
require "govuk_app_config/govuk_logging"
require "govuk_app_config/govuk_content_security_policy"
require "govuk_app_config/railtie"
Expand Down
34 changes: 28 additions & 6 deletions lib/govuk_app_config/govuk_prometheus_exporter.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,35 @@
module GovukPrometheusExporter
def self.should_configure
ENV["GOVUK_PROMETHEUS_EXPORTER"] == "true" && !(defined?(Rails) && Rails.env == "test")
end

def self.configure
unless Rails.env == "test" || (ENV["GOVUK_PROMETHEUS_EXPORTER"]) != "true"
require "prometheus_exporter"
require "prometheus_exporter/server"
require "prometheus_exporter/middleware"
return unless should_configure

require "prometheus_exporter"
require "prometheus_exporter/server"
require "prometheus_exporter/middleware"

if defined?(Sidekiq)
Sidekiq.configure_server do |config|
require "prometheus_exporter/instrumentation"
config.server_middleware do |chain|
chain.add PrometheusExporter::Instrumentation::Sidekiq
end
config.death_handlers << PrometheusExporter::Instrumentation::Sidekiq.death_handler
config.on :startup do
PrometheusExporter::Instrumentation::Process.start(type: "sidekiq")
PrometheusExporter::Instrumentation::SidekiqProcess.start
PrometheusExporter::Instrumentation::SidekiqQueue.start
PrometheusExporter::Instrumentation::SidekiqStats.start
end
end
end

server = PrometheusExporter::Server::WebServer.new bind: "0.0.0.0", port: 9394
server.start
server = PrometheusExporter::Server::WebServer.new bind: "0.0.0.0", port: 9394
server.start

if defined?(Rails)
Rails.application.middleware.unshift PrometheusExporter::Middleware
end
end
Expand Down

0 comments on commit 48636bb

Please sign in to comment.