diff --git a/.app_version b/.app_version index 19270385..c3f65805 100644 --- a/.app_version +++ b/.app_version @@ -1 +1 @@ -0.16.5 +0.16.6 diff --git a/CHANGELOG.md b/CHANGELOG.md index e1863d71..8aa52b7a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,21 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +# 0.16.6 - 2024-11-20 + +### Added + +- Dawarich now can export metrics to Prometheus. You can find the metrics at `your.host:9394/metrics` endpoint. The metrics are being exported in the Prometheus format and can be scraped by Prometheus server. To enable exporting, set the `PROMETHEUS_EXPORTER_ENABLED` env var in your docker-compose.yml to `true`. Example: + +```yaml + dawarich_app: + image: freikin/dawarich:latest + container_name: dawarich_app + environment: + ... + PROMETHEUS_EXPORTER_ENABLED: "true" +``` + # 0.16.5 - 2024-11-18 ### Changed diff --git a/Gemfile b/Gemfile index 45a72399..a1a27f8c 100644 --- a/Gemfile +++ b/Gemfile @@ -18,6 +18,7 @@ gem 'kaminari' gem 'lograge' gem 'oj' gem 'pg' +gem 'prometheus_exporter' gem 'puma' gem 'pundit' gem 'rails' diff --git a/Gemfile.lock b/Gemfile.lock index 12c880ae..e9d78b74 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -236,6 +236,8 @@ GEM patience_diff (1.2.0) optimist (~> 3.0) pg (1.5.9) + prometheus_exporter (2.1.1) + webrick pry (0.14.2) coderay (~> 1.1) method_source (~> 1.0) @@ -413,6 +415,7 @@ GEM addressable (>= 2.8.0) crack (>= 0.3.2) hashdiff (>= 0.4.0, < 2.0.0) + webrick (1.9.0) websocket-driver (0.7.6) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) @@ -446,6 +449,7 @@ DEPENDENCIES lograge oj pg + prometheus_exporter pry-byebug pry-rails puma diff --git a/Procfile.prometheus.dev b/Procfile.prometheus.dev new file mode 100644 index 00000000..2f1921fb --- /dev/null +++ b/Procfile.prometheus.dev @@ -0,0 +1,2 @@ +web: bin/rails server -p 3000 -b 0.0.0.0 +prometheus_exporter: bundle exec prometheus_exporter diff --git a/bin/dev b/bin/dev index 948d9bc6..8aa6cf2b 100755 --- a/bin/dev +++ b/bin/dev @@ -6,4 +6,10 @@ then gem install foreman fi -foreman start -f Procfile.dev +if [ "$PROMETHEUS_EXPORTER_ENABLED" = "true" ]; then + echo "Starting Foreman with Procfile.prometheus.dev..." + foreman start -f Procfile.prometheus.dev +else + echo "Starting Foreman with Procfile.dev..." + foreman start -f Procfile.dev +fi diff --git a/config/initializers/prometheus.rb b/config/initializers/prometheus.rb new file mode 100644 index 00000000..a8ffc08d --- /dev/null +++ b/config/initializers/prometheus.rb @@ -0,0 +1,12 @@ +# in config/initializers/prometheus.rb +if Rails.env != "test" + require 'prometheus_exporter/middleware' + require 'prometheus_exporter/instrumentation' + + # This reports stats per request like HTTP status and timings + Rails.application.middleware.unshift PrometheusExporter::Middleware + + # this reports basic process stats like RSS and GC info, type master + # means it is instrumenting the master process + PrometheusExporter::Instrumentation::Process.start(type: "master") +end diff --git a/config/initializers/sidekiq.rb b/config/initializers/sidekiq.rb index 3d2e4741..d3c9bbea 100644 --- a/config/initializers/sidekiq.rb +++ b/config/initializers/sidekiq.rb @@ -2,6 +2,11 @@ Sidekiq.configure_server do |config| config.redis = { url: ENV['REDIS_URL'] } + + config.server_middleware do |chain| + require 'prometheus_exporter/instrumentation' + chain.add PrometheusExporter::Instrumentation::Sidekiq + end end Sidekiq.configure_client do |config| diff --git a/config/puma.rb b/config/puma.rb index daaf0369..683d0ba0 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -41,3 +41,9 @@ pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" } # Allow puma to be restarted by `bin/rails restart` command. plugin :tmp_restart + +# Promethues exporter +after_worker_boot do + require 'prometheus_exporter/instrumentation' + PrometheusExporter::Instrumentation::Process.start(type:"web") +end diff --git a/docker-compose.yml b/docker-compose.yml index 7324b3b8..bd3d2049 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -65,6 +65,7 @@ services: DISTANCE_UNIT: km PHOTON_API_HOST: photon.komoot.io PHOTON_API_USE_HTTPS: true + PROMETHEUS_EXPORTER_ENABLED: false logging: driver: "json-file" options: