Skip to content

Instantly share code, notes, and snippets.

@zircote
Forked from joerayme/LICENSE
Created August 7, 2013 01:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zircote/6170398 to your computer and use it in GitHub Desktop.
Save zircote/6170398 to your computer and use it in GitHub Desktop.

##Description

Coull.com's very simple Dashing widget to display a Graphite graph with the correct dimensions and auto-refresh it every so often.

##Usage

Copy graphite.scss, graphite.html and graphite.coffee into widgets/graphite.

In your dashboard, add a snippet such as this:

<li data-row="1" data-col="1" data-sizex="2" data-sizey="1">
  <div data-view="Graphite" data-image="http://my.graphite.instance.com/render?from=-3hours&amp;width=600&amp;height=400&amp;target=my.graphite.metric&amp;_uniq=0.11581272282637656" data-interval="60000"></div>
</li>

The data-image attribute should be set to a graphite image URL. Don't worry about the width, height and uniq paramters - they'll be replaced by the javascript based on your dashboard settings. data-interval may be set to indicate the number of milliseconds between refreshes of the graph. If omitted, it will default to 60,000 (1 minute).

class Dashing.Graphite extends Dashing.Widget
ready: ->
if @get('interval')
interval = parseInt(@get('interval'))
else
interval = 60000
self = this
setInterval ->
self.updateGraph()
, interval
@updateGraph()
updateGraph: ->
url = @get('image')
$n = $(@node)
width = $n.width()
height = $n.height()
url = @updateUrl url, 'width', width
url = @updateUrl url, 'height', height
url = @updateUrl url, '_uniq', new Date().getTime()
$n.find('img').attr 'src', url
updateUrl: (url, param, value) ->
if url.indexOf(param) >= 0
regexp = new RegExp '([\?&])' + param + '(=[^&]*)?&?'
url = url.replace regexp, '$1'
repl = param + '=' + value
if url.indexOf('?') < 0
url + '?' + repl
else
url + '&' + repl
<img data-bind-width="width" data-bind-height="height" />
.widget.widget-graphite {
padding: 0;
}
Copyright (c) 2013 Couller Ltd. and Joseph Ray
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment