Permalink
Browse files

make the arguments read from a config file and turn the optional para…

…meters as options hash
  • Loading branch information...
elmer committed Oct 17, 2011
1 parent 6692a25 commit d44a61af552b92440c2df166a77693e36d18204b
Showing with 32 additions and 21 deletions.
  1. +1 −0 .gitignore
  2. +6 −8 README.md
  3. +7 −6 config.ru
  4. +11 −0 config/gdash.yaml-sample
  5. +7 −7 lib/gdash/sinatra_app.rb
View
@@ -0,0 +1 @@
+config/gdash.yaml
View
@@ -15,18 +15,16 @@ Config?
This dashboard is a Sinatra application, I suggest deploying it
in Passenger or other Sinatra application server.
-A sample _config.ru_ is included, you should adjust the url to
-your Graphite etc in there.
+A sample _gdash.yaml-sample_ is included, you should rename it to
+_gdash.yaml_ and adjust the url to your Graphite etc in there.
-
- templatedir = File.join(File.dirname(__FILE__), "graph_templates")
-
- run GDash::SinatraApp.new("http://graphite.example.net/", templatedir, "My Dashboard")
-
-The SinatraApp class can take a number of arguments:
+The SinatraApp class take two required arguments:
* Where graphite is installed
* The directory that has your _dashboards_ directory full of templates
+
+and additional options:
+
* The title to show at the top of your Graphite
* A prefix to prepend to all URLs in the dashboard
* How many columns of graphs to create, 2 by default.
View
@@ -4,11 +4,12 @@ require 'gdash'
set :run, false
-# If you want basic HTTP authentication uncomment this and set a u/p
-# use Rack::Auth::Basic do |username, password|
-# username == 'admin' && password == 'secret'
-# end
+config = YAML.load_file(File.expand_path("../config/gdash.yaml", __FILE__))
-templatedir = File.join(File.expand_path(File.dirname(__FILE__)), "graph_templates")
+# If you want basic HTTP authentication
+# include :username and :password in gdash.yaml
+use Rack::Auth::Basic do |username, password|
+ username == config[:username] && password == config[:password]
+end if config[:username] && config[:password]
-run GDash::SinatraApp.new("http://graphite.example.net/", templatedir, "My Dashboard")
+run GDash::SinatraApp.new(config[:graphite], config[:templatedir], config[:options])
View
@@ -0,0 +1,11 @@
+:graphite: http://graphite.example.net
+:templatedir: /path/to/my/graph/templates
+#:username: admin
+#:password: secret
+:options:
+ :title: My Dashboard
+ :prefix: ""
+ :graph_columns: 2
+ :graph_width: 500
+ :graph_height: 250
+ :whisper_dir: "/var/lib/carbon/whisper"
View
@@ -1,8 +1,8 @@
class GDash
class SinatraApp < ::Sinatra::Base
- def initialize(graphite_base, graph_templates, title="Graphite Dashboard", prefix="", graph_columns=2, graph_width=500, graph_height=250, whisper_dir="/var/lib/carbon/whisper")
+ def initialize(graphite_base, graph_templates, options = {})
# where the whisper data is
- @whisper_dir = whisper_dir
+ @whisper_dir = options.delete(:whisper_dir) || "/var/lib/carbon/whisper"
# where graphite lives
@graphite_base = graphite_base
@@ -14,19 +14,19 @@ def initialize(graphite_base, graph_templates, title="Graphite Dashboard", prefi
@graph_templates = graph_templates
# the dash site might have a prefix for its css etc
- @prefix = prefix
+ @prefix = options.delete(:prefix) || ""
# how many columns of graphs do you want on a page
- @graph_columns = graph_columns
+ @graph_columns = options.delete(:graph_columns) || 2
# how wide each graph should be
- @graph_width = graph_width
+ @graph_width = options.delete(:graph_width) || 500
# how hight each graph sould be
- @graph_height = graph_height
+ @graph_height = options.delete(:graph_height) || 250
# Dashboard title
- @dash_title = title
+ @dash_title = options.delete(:title) || "Graphite Dashboard"
@dash_site = GDash.new(@graphite_base, "/render/", File.join(@graph_templates, "/dashboards"), @graph_width, @graph_height)

0 comments on commit d44a61a

Please sign in to comment.