Skip to content

Instantly share code, notes, and snippets.

@james
Last active Nov 16, 2016
Embed
What would you like to do?
Pingdom Dashing Widget
class Dashing.Pingdom extends Dashing.Widget
<h1 class="title" data-bind="title"></h1>
<ul>
<li class="check" data-foreach-check="checks" data-bind-data-state="check.state">
<span data-bind="check.name"></span>
</li>
</ul>
require 'pingdom-client'
api_key = ENV['PINGDOM_API_KEY'] || ''
user = ENV['PINGDOM_USER'] || ''
password = ENV['PINGDOM_PASSWORD'] || ''
SCHEDULER.every '1m', :first_in => 0 do
client = Pingdom::Client.new :username => user, :password => password, :key => api_key
if client.checks
checks = client.checks.map { |check|
if check.status == 'up'
color = 'green'
else
color = 'red'
end
{ name: check.name, state: color }
}
checks.sort_by { |check| check['name'] }
send_event('pingdom', { checks: checks })
end
end
// ----------------------------------------------------------------------------
// Sass declarations
// ----------------------------------------------------------------------------
$background-color: #dc5945;
// ----------------------------------------------------------------------------
// Widget-clock styles
// ----------------------------------------------------------------------------
.widget-pingdom {
background-color: $background-color;
.check {
float: left;
padding: 4px 0px;
width:100%
}
.check[data-state="green"] {
background-color: green;
}
.check[data-state="red"] {
background-color: red;
}
.check span {
padding: 0px 4px;
}
}

Description

Simple Dashing widget (and associated job) to display Pingdom checks.

##Dependencies

pingdom-client

Add it to dashing's gemfile:

gem 'pingdom-client'

and run bundle install. Everything should work now :)

##Usage

To use this widget, copy pingdom.html, pingdom.coffee, and pingdom.scss into the /widgets/pingdom directory. Put the pingdom.rb file in your /jobs folder.

To include the widget in a dashboard, add the following snippet to the dashboard layout file:

<li data-row="1" data-col="1" data-sizex="1" data-sizey="1">
  <div data-id="pingdom" data-view="Pingdom" data-title="Pingdom" data-cols="1"></div>
</li>

##Settings

You'll need to add your pingdom API key and login settings. You can either add it straight to the source code on lines 4-6 of pingdom.rb, or set the variables in the ENV. For heroku, you can do this with

heroku config:set PINGDOM_API_KEY=
heroku config:set PINGDOM_USER=
heroku config:set PINGDOM_PASSWORD=

Pingdom is checked every minute, but you can change that by editing the job schedule.

Contributions

This has been extracted from a dashboard for the UK Ministry of Justice, with minimal generalising. Feel free to submit patches to @james

@matthijsgroen
Copy link

matthijsgroen commented Jul 30, 2013

Hmm I get errors using the gem specified, because of a Faraday dependency conflict. When using another Github fork of the library, I get

scheduler caught exception:
:logger is not registered on Faraday::Adapter
/Users/matthijsgroen/dashing/vendor/bundle/ruby/1.9.1/gems/faraday-0.8.7/lib/faraday.rb:64:in `lookup_middleware'
/

@jwalton
Copy link

jwalton commented Sep 19, 2013

This is my version: https://gist.github.com/jwalton/6625777

It removes the dependency on pingdom-client, and thus the troublesome Faraday problems, and adds showing the most recent ping for each server.

@jwalton
Copy link

jwalton commented Sep 19, 2013

@james feel free to pull from mine. :)

@petermanser
Copy link

petermanser commented Feb 6, 2014

@jwalton @james https://gist.github.com/james/5670035#file-pingdom-rb-L21 should be:

checks.sort_by! { |check| check[:name] }

@foxhunt72
Copy link

foxhunt72 commented Feb 13, 2014

Hello,

I have a question, how can i change did so it just shows the down checks, because we have something like more than 40 checks in pingdom so it doesn't fit on the screen.

Richard

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment