Skip to content

Instantly share code, notes, and snippets.

@ptierno
Forked from bitflingr/README.md
Last active August 29, 2015 14: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 ptierno/4b3c3c5fea3ad7ffc692 to your computer and use it in GitHub Desktop.
Save ptierno/4b3c3c5fea3ad7ffc692 to your computer and use it in GitHub Desktop.

##Description Simple Dashing widget (and associated job) to display general puppetdb status. Pulled the api calls from Nedap's Puppetboard. Excellent tool BTW.

WARNING: This only works if puppetdb is listening on HTTP. I have not gotten around to getting this to work with SSL client certificates yet. If you know how, please leave them at the comments below.

##Screenshot

##Dependencies None

##Usage To use this widget, copy puppetdb_stats.html, puppetdb_stats.coffee, and puppetdb_stats.scss into the /widgets/puppetdb_stats directory. Put the puppetdb_stats.rb file in your /jobs folder. Or you can do this the easy way and run the following in your dashing directory

$> dashing install a49981b299dff184c04a
  create  widgets/puppetdb_stats/puppetdb_stats.coffee
  create  widgets/puppetdb_stats/puppetdb_stats.html
  create  jobs/puppetdb_stats.rb
  create  widgets/puppetdb_stats/puppetdb_stats.scss
Don't forget to edit the Gemfile and run bundle install if needed. More information for this widget can be found at https://gist.github.com/a49981b299dff184c04a

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="2" data-sizey="1">
  <div data-id="puppetdb_stats" data-view="PuppetdbStats"></div>
</li>
class Dashing.PuppetdbStats extends Dashing.Widget
ready: ->
# This is fired when the widget is done being rendered
onData: (data) ->
# Handle incoming data
# You can access the html node of this widget with `@node`
# Example: $(@node).fadeOut().fadeIn() will make the node flash each time data comes in.
<h1>Puppet Status</h1>
<div class="row">
<div class="col">
<h2 class="success" data-bind="successes"></h2><span>with status change</span>
</div>
<div class="col" style="float:right;">
<h2 class="failure" data-bind="failures"></h2><span>with status failed</span>
</div>
</div>
<div class="row">
<div class="col" style="width: 33%;">
<h2 data-bind="num_nodes"></h2><span>Population</span>
</div>
<div class="col" style="float:left; width: 33%;">
<h2 data-bind="num_resources"></h2><span>Resources managed</span>
</div>
<div class="col" style="float:left; width: 33%;">
<h2 data-bind="avg_resource"></h2><span>Avg. resource/node</span>
</div>
</div>
require 'net/http'
require 'json'
# Currently do not have this working with client side SSL, perhaps someone can help with that in the comments.
host = 'YOUR_PUPPETDB_HOST_HERE'
port = 'PORT_NUMBER'
http = Net::HTTP.new(host, port)
nodes_uri = '/v3/metrics/mbean/com.puppetlabs.puppetdb.query.population:type=default,name=num-nodes'
resources_uri = '/v3/metrics/mbean/com.puppetlabs.puppetdb.query.population:type=default,name=num-resources'
avg_resources_uri = '/v3/metrics/mbean/com.puppetlabs.puppetdb.query.population:type=default,name=avg-resources-per-node'
agg_eventcounts_uri = '/v3/aggregate-event-counts?query=%5B%22%3D%22%2C%22latest-report%3F%22%2Ctrue%5D&summarize-by=certname'
SCHEDULER.every '5m', :first_in => 0 do |job|
num_nodes = JSON.parse(http.get(nodes_uri).body)
num_resources = JSON.parse(http.get(resources_uri).body)
avg_resource = JSON.parse(http.get(avg_resources_uri).body)
agg_eventcounts = JSON.parse(http.get(agg_eventcounts_uri).body)
send_event('puppetdb_stats', { num_nodes: num_nodes['Value'],
num_resources: num_resources['Value'],
avg_resource: avg_resource['Value'].to_f.round(2),
successes: agg_eventcounts['successes'],
failures: agg_eventcounts['failures'] })
end
.widget-puppetdb-stats {
.row {
clear: both;
padding: 10px 0 30px 0;
position: relative;
}
.col {
float: left;
width: 50%;
}
h1 {
text-transform: uppercase;
font-size: 56px;
font-weight: 700;
color: white;
}
h2 {
text-transform: uppercase;
font-size: 48px;
font-weight: 700;
color: gray;
}
.success {
color: green;
}
.failure {
color: red;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment