Skip to content

Instantly share code, notes, and snippets.

@pallan
Last active May 17, 2016 16:44
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pallan/57f778cace40fd56fb4d to your computer and use it in GitHub Desktop.
Save pallan/57f778cace40fd56fb4d to your computer and use it in GitHub Desktop.

Preview

Simple Dashing widget to display the current stats for Sidekiq.

Dependencies

Sidekiq version 3.0 or greater is required. Add to dashing's gemfile:

gem 'sidekiq', '~>3.0'

and run bundle install.

Usage

To use this widget, copy sidekiq.html, sidekiq.coffee, and sidekiq.scss into the /widgets/sidekiq directory. Put the sidekiq.rb file in your /jobs folder. Copy sidekiq_log.png into the /assets/images directory.

Add the widget HTML to your dashboard

    <li data-row="2" data-col="4" data-sizex="2" data-sizey="2">
      <div data-id="sidekiq" data-view="Sidekiq" data-title="Sidekiq" style=""></div>
    </li>

Settings

In /jobs/sidekiq.rb you need to configure the connection to your Redis server that backs Sidekiq.

The MIT License (MIT)
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
class Dashing.Sidekiq extends Dashing.Widget
<h1 class="title" data-bind="title"></h1>
<ul>
<li data-foreach-metric="metrics">
<span class="label" data-bind="metric.label"></span>
<span class="value" data-bind="metric.value"></span>
</li>
</ul>
<p class="updated-at" data-bind="updatedAtMessage"></p>
require 'sidekiq/api'
redis_uri = "redis://:#{YOUR_REDIS_PASSWORD}@#{YOUR_REDIS_HOST}:#{YOUR_REDIS_PORT}"
Sidekiq.configure_client do |config|
config.redis = { url: redis_uri, namespace: "YOUR_NAMESPACE" }
end
SCHEDULER.every '30s' do
stats = Sidekiq::Stats.new
metrics = [
{label: 'Processed', value: stats.processed},
{label: 'Failed', value: stats.failed},
{label: 'Retries', value: stats.retry_size},
{label: 'Dead', value: stats.dead_size}
]
send_event('sidekiq', {metrics: metrics})
end
// ----------------------------------------------------------------------------
// Sass declarations
// ----------------------------------------------------------------------------
$background-color: #f0f0f0;
$value-color: #636466;
// ----------------------------------------------------------------------------
// Widget-sidekiq styles
// ----------------------------------------------------------------------------
.widget-sidekiq {
background: $background-color url(/assets/sidekiq_logo.png) 20px 25px no-repeat;
&.large h3 {
font-size: 65px;
}
.title {
color: $value-color;
}
.more-info {
color: $value-color;
}
.updated-at {
color: rgba(0, 0, 0, 1);
}
ul {
margin: 0 15px;
text-align: left;
color: $value-color;
}
li {
margin-bottom: 5px;
}
.list-nostyle {
list-style: none;
}
.label {
color: $value-color;
}
.value {
float: right;
margin-left: 12px;
font-weight: 600;
color: $value-color;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment