Skip to content

Commit

Permalink
Add Sidekiq Prometheus instrumentation
Browse files Browse the repository at this point in the history
If Sidekiq is present, add the Sidekiq Prometheus instrumentation.

Ref:
1. [trello card](https://trello.com/c/K8aUtwz4/974-graphs-for-sidekiq-queues-in-grafana)
  • Loading branch information
fredericfran-gds committed Aug 5, 2022
1 parent f63ddb7 commit 57af294
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 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
24 changes: 22 additions & 2 deletions lib/govuk_app_config/govuk_prometheus_exporter.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,34 @@
module GovukPrometheusExporter
def self.configure
unless Rails.env == "test" || (ENV["GOVUK_PROMETHEUS_EXPORTER"]) != "true"
if (ENV["GOVUK_PROMETHEUS_EXPORTER"]) == "true"
return if defined?(Rails) ? Rails.env == "test" : false

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

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

0 comments on commit 57af294

Please sign in to comment.