Skip to content

Instantly share code, notes, and snippets.

@linko
Created March 20, 2015 15:26
Show Gist options
  • Save linko/fa5979c9c96f4d813632 to your computer and use it in GitHub Desktop.
Save linko/fa5979c9c96f4d813632 to your computer and use it in GitHub Desktop.
Sidekiq Watcher
require 'net/http'
require 'json'
def alert_to_slack(env)
uri = URI.parse('https://hooks.slack.com/services/<uri>')
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Post.new(uri.request_uri, {'Content-Type' => 'application/json'})
request.body = {
"channel" => '#channel',
"username" => "FailBot",
"text" => "<!channel>: Sidekiq has been failed on #{env}",
"icon_emoji" => ":scream:"
}.to_json
response = http.request(request)
end
if `ps aux | grep '[s]idekiq 3.2.1 domain.com'`.empty?
alert_to_slack 'production'
end
if `ps aux | grep '[s]idekiq 3.2.1 staging.domain.com'`.empty?
alert_to_slack 'staging'
end
# */3 * * * * /bin/bash -l -c 'cd /home/project && ruby /home/project/apps/sidekiq_watcher.rb >> /home/project/apps/sidekiq_checker.log 2>&1'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment