Class: GDash::SinatraApp

Inherits:
Sinatra::Base
  • Object
show all
Defined in:
lib/gdash/sinatra_app.rb

Instance Method Summary collapse

Constructor Details

#initialize(graphite_base, graph_templates, options = {}) ⇒ SinatraApp

Returns a new instance of SinatraApp.



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/gdash/sinatra_app.rb', line 3

def initialize(graphite_base, graph_templates, options = {})
  # where the whisper data is
  @whisper_dir = options.delete(:whisper_dir) || "/var/lib/carbon/whisper"

  # where graphite lives
  @graphite_base = graphite_base

  # where the graphite renderer is
  @graphite_render = [@graphite_base, "/render/"].join

  # where to find graph, dash etc templates
  @graph_templates = graph_templates

  # the dash site might have a prefix for its css etc
  @prefix = options.delete(:prefix) || ""

  # the page refresh rate
  @refresh_rate = options.delete(:refresh_rate) || 60

  # how many columns of graphs do you want on a page
  @graph_columns = options.delete(:graph_columns) || 2

  # how wide each graph should be
  @graph_width = options.delete(:graph_width)

  # how hight each graph sould be
  @graph_height = options.delete(:graph_height)

  # Dashboard title
  @dash_title = options.delete(:title) || "Graphite Dashboard"

  # Time filters in interface
  @interval_filters = options.delete(:interval_filters) || Array.new

  @intervals = options.delete(:intervals) || []

  @top_level = Hash.new
  Dir.entries(@graph_templates).each do |category|
    if File.directory?("#{@graph_templates}/#{category}")
      unless ("#{category}" =~ /^\./ )
        @top_level["#{category}"] = GDash.new(@graphite_base, "/render/", File.join(@graph_templates, "/#{category}"), {:width => @graph_width, :height => @graph_height})
      end
    end
  end

  super()
end