Skip to content

Easily monitor your sidekiq queus with Slack or some other notification service.

License

Notifications You must be signed in to change notification settings

jayelkaake/sidekiq-heartbeat_monitor

Repository files navigation

Sidekiq Montior Gem

This gem adds 2 things:

  1. A lightweight heartbeat task that runs every few minutes and alerts if it takes longer than a few seconds to start.
  2. A scheduler task that periodically checks the size of each sidekiq queue to ensure no queues are backed up.

Table of Contents

Installation

Add this line to your application's Gemfile:

gem 'sidekiq-heartbeat_monitor'

And then execute: $ bundle Or install it yourself as: $ gem install sidekiq-heartbeat_monitor

Configuration is required - see the Configuration section below

(Optional) Install Cron Task

The gem will automatically try to install your cron task when you run your sidekiq server, however if for some reason it does not install the cron task then you can install it manually using the available rake task command:

rake sidekiq::heartbeat_monitor:install

Requirements

  1. Dont Repeat For Gem - To allow you to only send notifications every so often.
  2. Redis
  3. (optional) SlackNotifier - If you're using slack notifications then this is needed.

Configuration

STEP 1. Create slack webhook

To add a webhook to your slack account, go to: https://api.slack.com/incoming-webhooks Make note of the URL or add it to your environment and note the name.

STEP 2. Add Initializer

To configure with a simple slack webhook notification URL, simply specify the notification URL in the "slack_notifier_url" attribute.

2. Option 1 - Simple notification
# config/initializers/sidekiq/hearbeat_monitor.rb
Sidekiq::HeartbeatMonitor.configure(slack_notifier_url: ENV['SLACK_WEBHOOK_URL'])
2. Option 2 - Dont Repeat For
# config/initializers/sidekiq/hearbeat_monitor.rb
Sidekiq::HeartbeatMonitor.configure(
    slack_notifier_url: ENV['SLACK_WEBHOOK_URL'],
    dont_repeat_for: 15.minutes # Won't repeat the notifications for the same queue more than once every 15 minutes.
)
2. Option 2 - Custom Alert Method
# config/initializers/sidekiq/hearbeat_monitor.rb
Sidekiq::HeartbeatMonitor.configure(
    on_backed_up: -> (msg, queue) { Rails.logger.log("Queue #{queue.name} is backed up!"); },
    on_slowed_down: -> (msg, queue) { Rails.logger.log("Queue #{queue.name} is being slow!"); },
)

Note: on_backed_up and on_slowed_down accept an array and will always add to existing callbacks (you can combine slack_notiifer_url with them)

Testing Your Config

To test your config:

  1. Open your rails console.
  2. Run Sidekiq::HeartbeatMontior.send_test! and you should see notifications come up in your Slack (or however you have them configured). If there's something wrong it should show an error.

Other Things

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/jayelkaake/sidekiq-heartbeat_monitor. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

Supported versions

Battle-tested @ Fera.ai with:

  • Ruby 2.4 - 2.6.7 (but up to 3.0 should be fine)
  • Sidekiq 3-5

License

The gem is available as open source under the terms of the MIT License.

About

Easily monitor your sidekiq queus with Slack or some other notification service.

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published