Last active
September 26, 2018 09:32
-
-
Save rojosinalma/e64c847c7d11516b6daf9b123f581ec8 to your computer and use it in GitHub Desktop.
Sidekiq Monitor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace :sidekiq do | |
desc 'Start Sidekiq and Monitor' | |
task :start do | |
trap('SIGTERM') { puts "Exiting processes"; exit } | |
system "rake sidekiq:monitor & sidekiq" | |
end | |
desc 'Starts /health/monitor endpoint for sidekiq' | |
task :monitor do | |
require 'sidekiq/web' | |
app = Sidekiq::Web | |
app.get '/monitor/health' do | |
content_type :json | |
Sidekiq.dump_json( | |
{ | |
status: 'OK', | |
commit: ENV['BUILD_COMMIT'], | |
build: ENV['BUILD_ID'], | |
cluster: ENV['CLUSTER'] | |
} | |
) | |
end | |
# Logger | |
::Logger.class_eval { alias :write :'<<' } | |
access_log = ::File.join(::File.dirname(::File.expand_path(__FILE__)),'..', '..', 'log','sidekiq_monitor.log') | |
access_logger = ::Logger.new(access_log) | |
error_logger = ::File.new(::File.join(::File.dirname(::File.expand_path(__FILE__)),'..', '..', 'log','sidekiq_monitor.log'),"a+") | |
error_logger.sync = true | |
app.configure do | |
use ::Rack::CommonLogger, access_logger | |
end | |
app.before { | |
env["rack.errors"] = error_logger | |
} | |
# Settings | |
app.set :logging, true | |
app.set :environment, :production | |
app.set :bind, '0.0.0.0' | |
app.set :port, 9494 | |
puts "-- Sidekiq Monitor Starting" | |
Process.daemon | |
app.run! | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment