Skip to content

Commit

Permalink
Add configuration to for prometheus exporter (#5385)
Browse files Browse the repository at this point in the history
**Story card:**
[sc-11693](https://app.shortcut.com/simpledotorg/story/11693/add-application-performance-monitoring)

## Because

We are migrating our monitoring infrastructure from datadog to
prometheus

## This addresses

This adds necessary instrumentation to monitor the various processes
using prometheus.

## Test instructions
- Start rails server
- In another terminal run `bundle exec prometheus-exporter`
- Visit the dashboard to send some requests to the server
- `curl http://localhost:9394/metrics`
  • Loading branch information
govindkrjoshi committed Feb 21, 2024
1 parent 7c9b7ca commit a2cbf0f
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ gem "whenever", require: false
gem "wkhtmltoimage-binary"
gem "table_print"
gem "doorkeeper", "~> 5.6"
gem "prometheus_exporter"

group :development, :test do
gem "active_record_query_trace", require: false
Expand Down
4 changes: 4 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,8 @@ GEM
prawn (2.4.0)
pdf-core (~> 0.9.0)
ttfunk (~> 1.7)
prometheus_exporter (2.1.0)
webrick
prosopite (1.1.3)
pry (0.14.1)
coderay (~> 1.1)
Expand Down Expand Up @@ -687,6 +689,7 @@ GEM
rack-proxy (>= 0.6.1)
railties (>= 5.2)
semantic_range (>= 2.3.0)
webrick (1.8.1)
websocket (1.2.9)
websocket-driver (0.7.5)
websocket-extensions (>= 0.1.0)
Expand Down Expand Up @@ -779,6 +782,7 @@ DEPENDENCIES
pg_query
pg_search
phonelib
prometheus_exporter
prosopite
pry-rails
puma
Expand Down
2 changes: 2 additions & 0 deletions config.ru
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ require_relative "config/environment"
if defined?(PhusionPassenger)
PhusionPassenger.on_event(:starting_worker_process) do |forked|
if forked
require "prometheus_exporter/instrumentation"
PrometheusExporter::Instrumentation::Process.start(type: "web")
Statsd.instance.reset!
end
end
Expand Down
6 changes: 6 additions & 0 deletions config/initializers/prometheus.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
unless Rails.env.test?
require "prometheus_exporter/middleware"

# This reports stats per request like HTTP status and timings
Rails.application.middleware.unshift PrometheusExporter::Middleware
end
8 changes: 8 additions & 0 deletions config/initializers/sidekiq.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ def self.connection_pool
SIDEKIQ_STATS_PREFIX = "#{SimpleServer.env}.#{CountryConfig.current[:abbreviation]}"

Sidekiq.configure_server do |config|
config.on :startup do
require "prometheus_exporter/instrumentation"
PrometheusExporter::Instrumentation::ActiveRecord.start(
custom_labels: {type: "sidekiq"},
config_labels: [:database, :host]
)
end

config.on(:shutdown) { Statsd.instance.close }

config.client_middleware do |chain|
Expand Down

0 comments on commit a2cbf0f

Please sign in to comment.