Skip to content

Commit

Permalink
Merge pull request realityforge#1 from chrisroberts/dashboard-components
Browse files Browse the repository at this point in the history
Dashboard components
  • Loading branch information
webframp committed Apr 19, 2012
2 parents bc1aae2 + 3901672 commit 0331f2e
Show file tree
Hide file tree
Showing 13 changed files with 275 additions and 73 deletions.
46 changes: 46 additions & 0 deletions README.md
Expand Up @@ -31,3 +31,49 @@ Usage
This cookbook currently sets up gdash and a basic runit service.
Graph creation is left to the user.

Graph Creation
==============

Dashboard creation
------------------

First create a dashboard:

```ruby

gdash_dashboard 'cpu_usage' do
category 'metrics'
description 'CPU Usages'
end
```

Dashboard component creation
----------------------------

Next, add components to the dashboard. Dashboards are referenced by
their name and category when adding components:

```ruby

gdash_dashboard_component 'node1' do
dashboard_name 'cpu_usage'
dashboard_category 'metrics'
linemode 'slope'
description 'Node1 CPU usage'
fields(
:system => {
:scale => 0.001,
:color => 'orange',
:alias => 'System Usage 0',
:data => 'node1.cpu.0.system.value'
},
:user => {
:scale => 0.001,
:color => 'blue',
:alias => 'User Usage 0',
:data => 'node1.cpu.0.user.value'
}
)
end
```

13 changes: 12 additions & 1 deletion attributes/gdash.rb
@@ -1,8 +1,18 @@
default.gdash.tarfile = "/usr/src/gdash.tgz"
default.gdash.base = "/srv/gdash"
default.gdash.url = "https://github.com/ripienaar/gdash/tarball/master"
default.gdash.graphite_url = "http://#{fqdn}"

####
# WARN: pull in attributes from ANOTHER COOKBOOK
# TODO: put this in a databag ?
####
include_attribute "graphite::graphite"
default.gdash.graphite_url = "http://#{ipaddress}:#{graphite[:listen_port]}"
####

default.gdash.templatedir = "/srv/gdash/graph_templates"
default.gdash.owner = "www-data"
default.gdash.group = "www-data"
default.gdash.basic_auth = false
default.gdash.username = "gdash"
default.gdash.password = "gdash"
Expand All @@ -11,3 +21,4 @@
default.gdash.columns = 2
default.gdash.graphite_whisperdb = "/opt/graphite/storage/whisper"
default.gdash.port = 9292
default.gdash.categories = []
19 changes: 8 additions & 11 deletions metadata.rb
@@ -1,16 +1,13 @@
maintainer "Sean Escriva"
maintainer_email "sean.escriva@gmail.com"
maintainer "Heavy Water Software Inc."
maintainer_email "ops@hw-ops.com"
license "Apache 2.0"
description "Installs/Configures gdash"
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version "0.0.1"
version "0.0.2"

%w{debian ubuntu}.each do |os|
supports os
end
depends "build-essential"
depends "runit"
depends "graphite"
depends "unicorn"

%w{build-essential runit}.each do |dep|
depends dep
end

depends "iptables"
suggests "iptables"
18 changes: 13 additions & 5 deletions providers/dashboard.rb
Expand Up @@ -13,16 +13,24 @@ def load_current_resource

action :create do

directory @dashboard_dir do
owner node.gdash.owner
group node.gdash.group
@dashboard_dir.sub("#{node.gdash.templatedir}/", '').split('/').inject([node.gdash.templatedir]){|memo,val|
memo.push(::File.join(memo.last, val))
}.each do |dir_path|
directory dir_path do
owner node.gdash.owner
group node.gdash.group
recursive true
notifies :restart, resources(:service => 'gdash'), :delayed
end
end

file @dashboard_yaml do
owner node.gdash.owner
group node.gdash.group
content YAML.dump(:name => new_resource.name,
:description => new_resource.description)
content YAML.dump(
:name => new_resource.display_name || new_resource.name,
:description => new_resource.description
)
end

new_resource.updated_by_last_action(true)
Expand Down
61 changes: 61 additions & 0 deletions providers/dashboard_component.rb
@@ -0,0 +1,61 @@
def load_current_resource
node.include_attribute "gdash::gdash"
node.include_recipe "gdash::default"

@dashboard_dir = ::File.join(
node.gdash.templatedir,
new_resource.dashboard_category,
new_resource.dashboard_name
)
end

action :create do

@dashboard_dir.sub("#{node.gdash.templatedir}/", '').split('/').inject([node.gdash.templatedir]){|memo,val|
memo.push(::File.join(memo.last, val))
}.each do |dir_path|
directory dir_path do
owner node.gdash.owner
group node.gdash.group
recursive true
notifies :restart, resources(:service => 'gdash'), :delayed
end
end

template ::File.join(@dashboard_dir, "#{new_resource.name}.graph") do
source 'gdash.graph.erb'
cookbook 'gdash'
template_hash = ::GDASH_RESOURCE_ATTRIBS.map{ |attr|
if(new_resource.respond_to?(attr) && !new_resource.send(attr).nil?)
[attr, new_resource.send(attr)]
else
nil
end
}.compact.flatten
template_hash = Hash[*template_hash]

owner node.gdash.owner
group node.gdash.group
mode 0644
variables(
:base_variables => template_hash,
:fields => new_resource.fields || {},
:lines => new_resource.lines || [],
:forecasts => new_resource.forecasts || {}
)
action :create
end

new_resource.updated_by_last_action(true)

end

action :delete do

file ::File.join(@dashboard_dir, "#{new_resource.name}.graph") do
action :delete
end

new_resource.updated_by_last_action(true)

end
40 changes: 40 additions & 0 deletions recipes/basic_dashboard.rb
@@ -0,0 +1,40 @@
include_recipe 'gdash'

gdash_dashboard 'Base Metrics' do
category 'Basic'
description 'Simple dashboard'
end

gdash_dashboard_component 'metrics_received' do
dashboard_name 'Base Metrics'
dashboard_category 'Basic'
vtitle 'Items'
fields(
:received => {
:data => '*.*.*.metricsReceived',
:alias => 'Metrics Received'
}
)
end

gdash_dashboard_component 'cpu' do
dashboard_name 'Base Metrics'
dashboard_category 'Basic'
fields(
:cpu => {
:data => '*.*.*.cpuUsage',
:alias => 'CPU Usage'
}
)
end

gdash_dashboard_component 'memory' do
dashboard_name 'Base Metrics'
dashboard_category 'Basic'
fields(
:memory => {
:data => '*.*.*.memUsage',
:alias => 'Memory Usage'
}
)
end
34 changes: 32 additions & 2 deletions recipes/default.rb
Expand Up @@ -17,6 +17,7 @@
# limitations under the License.
#
include_recipe "build-essential"
include_recipe "unicorn"

%w[libcurl4-gnutls-dev ruby1.9.1-full].each do |pkg|
apt_package pkg
Expand All @@ -43,20 +44,39 @@
end

execute "bundle" do
command "bundle install --deployment --binstubs"
command "bundle install --binstubs #{File.join(node.gdash.base, 'bin')} --path #{File.join(node.gdash.base, 'vendor', 'bundle')}"
user "www-data"
group "www-data"
cwd node.gdash.base
creates File.join(node.gdash.base, "bin")
action :nothing
end

execute "bundle_unicorn" do
command 'echo "gem \'unicorn\'" >> Gemfile'
user 'www-data'
group 'www-data'
cwd node.gdash.base
action :nothing
notifies :run, resources(:execute => "bundle"), :immediately
not_if do
File.exists?(File.join(node.gdash.base, 'Gemfile')) &&
File.read(File.join(node.gdash.base, 'Gemfile')).include?('unicorn')
end
end

directory File.join(node.gdash.base, 'graph_templates', 'dashboards') do
action :nothing
recursive true
end

execute "gdash: untar" do
command "tar zxf #{node.gdash.tarfile} -C #{node.gdash.base} --strip-components=1"
creates File.join(node.gdash.base, "Gemfile.lock")
user "www-data"
group "www-data"
notifies :run, resources(:execute => "bundle"), :immediately
notifies :run, resources(:execute => "bundle_unicorn"), :immediately
notifies :delete, resources(:directory => File.join(node.gdash.base, 'graph_templates', 'dashboards')), :immediately
end

template File.join(node.gdash.base, "config", "gdash.yaml") do
Expand All @@ -65,5 +85,15 @@
notifies :restart, "service[gdash]"
end

unicorn_config '/etc/unicorn/gdash.app' do
listen '9292' => {:backlog => 100}
working_directory node.gdash.base
worker_timeout 60
preload_app false
worker_processes 2
owner 'root'
group 'root'
end

runit_service "gdash"

52 changes: 0 additions & 52 deletions recipes/graph_generator.rb

This file was deleted.

1 change: 1 addition & 0 deletions resources/dashboard.rb
Expand Up @@ -7,3 +7,4 @@ def initialize(*args)

attribute :category, :kind_of => String, :required => true
attribute :description, :kind_of => String, :required => true
attribute :display_name, :kind_of => String, :required => false

0 comments on commit 0331f2e

Please sign in to comment.