diff --git a/Dockerfile b/Dockerfile index 2ca5e30..9711dce 100644 --- a/Dockerfile +++ b/Dockerfile @@ -111,6 +111,8 @@ USER root RUN install -m 755 /srv/http/sync_assets.sh /usr/local/bin/sync_assets # Instalar la configuraciĆ³n de monit RUN install -m 640 -o root -g root /srv/http/monit.conf /etc/monit.d/sutty.conf +RUN apk add --no-cache daemonize +RUN install -m 755 /srv/http/prometheus.sh /usr/local/bin/prometheus # Mantener estos directorios! VOLUME "/srv/http/data" diff --git a/Gemfile b/Gemfile index 3ef2678..78ef8ef 100644 --- a/Gemfile +++ b/Gemfile @@ -78,6 +78,7 @@ gem 'flamegraph' gem 'memory_profiler' gem 'rack-mini-profiler' gem 'stackprof' +gem 'prometheus_exporter' group :themes do gem 'adhesiones-jekyll-theme', require: false diff --git a/Gemfile.lock b/Gemfile.lock index cbe94f7..da30456 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -205,7 +205,7 @@ GEM http_parser.rb (0.6.0) i18n (1.8.5) concurrent-ruby (~> 1.0) - icalendar (2.6.1) + icalendar (2.7.0) ice_cube (~> 0.16) ice_cube (0.16.3) image_processing (1.11.0) @@ -214,7 +214,7 @@ GEM inline_svg (1.7.1) activesupport (>= 3.0) nokogiri (>= 1.6) - jbuilder (2.10.0) + jbuilder (2.10.1) activesupport (>= 5.0.0) jekyll (4.1.1) addressable (~> 2.4) @@ -309,6 +309,7 @@ GEM forwardable-extended (~> 2.6) pg (1.2.3) popper_js (1.16.0) + prometheus_exporter (0.5.3) pry (0.13.1) coderay (~> 1.1) method_source (~> 1.0) @@ -405,7 +406,7 @@ GEM rubocop-ast (>= 0.3.0, < 1.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 1.4.0, < 2.0) - rubocop-ast (0.3.0) + rubocop-ast (0.4.0) parser (>= 2.7.1.4) rubocop-rails (2.8.0) activesupport (>= 4.2.0) @@ -453,7 +454,7 @@ GEM sprockets (4.0.2) concurrent-ruby (~> 1.0) rack (> 1, < 3) - sprockets-rails (3.2.1) + sprockets-rails (3.2.2) actionpack (>= 4.0) activesupport (>= 4.0) sprockets (>= 3.0.0) @@ -565,6 +566,7 @@ DEPENDENCIES minima mobility pg + prometheus_exporter pry puma pundit diff --git a/Procfile b/Procfile index d692266..082ad0c 100644 --- a/Procfile +++ b/Procfile @@ -4,3 +4,4 @@ blazer_5m: bundle exec rake blazer:run_checks SCHEDULE="5 minutes" blazer_1h: bundle exec rake blazer:run_checks SCHEDULE="1 hour" blazer_1d: bundle exec rake blazer:run_checks SCHEDULE="1 day" blazer: bundle exec rake blazer:send_failing_checks +prometheus: bundle exec prometheus_exporter -b 0.0.0.0 --prefix "sutty_" -d diff --git a/config/initializers/prometheus.rb b/config/initializers/prometheus.rb new file mode 100644 index 0000000..e7a9245 --- /dev/null +++ b/config/initializers/prometheus.rb @@ -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 diff --git a/config/puma.rb b/config/puma.rb index 629b81f..58f7ea8 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -56,4 +56,9 @@ end # on_worker_boot do ActiveRecord::Base.establish_connection if defined?(ActiveRecord) + + require 'prometheus_exporter/instrumentation' + PrometheusExporter::Instrumentation::ActiveRecord.start(custom_labels: { type: 'puma_worker' }, config_labels: %i[database host]) + PrometheusExporter::Instrumentation::Puma.start + PrometheusExporter::Instrumentation::Process.start(type: 'web') end diff --git a/entrypoint.sh b/entrypoint.sh index 079a513..98e6870 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,24 +1,6 @@ #!/bin/sh set -e -export RAILS_ENV=production case $1 in - rails) - cd /srv/http - bundle exec rake db:migrate - bundle exec rake db:seed - bundle exec puma -d config.ru - exit $? - ;; - darkhttpd) - darkhttpd /srv/http/public \ - --no-server-id \ - --pidfile /tmp/darkhttpd.pid \ - --uid darkhttpd \ - --gid www-data \ - --no-listing \ - --daemon \ - --port 8080 - exit $? - ;; + prometheus) daemonize -c /srv/http -p /tmp/prometheus.pid -l /tmp/prometheus.pid -u app /usr/bin/foreman start prometheus ;; esac diff --git a/monit.conf b/monit.conf index c2879cb..c366397 100644 --- a/monit.conf +++ b/monit.conf @@ -3,6 +3,10 @@ check process sutty with pidfile /srv/http/tmp/puma.pid as uid "app" and gid "www-data" stop program = "/bin/sh -c 'cat /srv/http/tmp/puma.pid | xargs kill'" +check process prometheus with pidfile /tmp/prometheus.pid + start program = "/usr/local/bin/prometheus" + stop program = "/bin/sh -c 'cat /tmp/prometheus.pid | xargs kill'" + check program sync_assets with path /usr/local/bin/sync_assets if status = 0 then unmonitor diff --git a/prometheus.sh b/prometheus.sh new file mode 100755 index 0000000..98e6870 --- /dev/null +++ b/prometheus.sh @@ -0,0 +1,6 @@ +#!/bin/sh +set -e + +case $1 in + prometheus) daemonize -c /srv/http -p /tmp/prometheus.pid -l /tmp/prometheus.pid -u app /usr/bin/foreman start prometheus ;; +esac