Class: GDash

Inherits:
Object
  • Object
show all
Defined in:
lib/gdash.rb,
lib/gdash/dashboard.rb,
lib/gdash/sinatra_app.rb

Defined Under Namespace

Classes: Dashboard, SinatraApp

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(graphite_base, render_url, dash_templates, options = {}) ⇒ GDash

Returns a new instance of GDash.



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/gdash.rb', line 15

def initialize(graphite_base, render_url, dash_templates, options={})
  @graphite_base = graphite_base
  @graphite_render = [@graphite_base, "/render/"].join
  @dash_templates = dash_templates
  @height = options.delete(:height)
  @width = options.delete(:width)
  @from = options.delete(:from)
  @until = options.delete(:until)

  raise "Dashboard templates directory #{@dash_templates} does not exist" unless File.directory?(@dash_templates)
end

Instance Attribute Details

#dash_templatesObject (readonly)

Returns the value of attribute dash_templates.



13
14
15
# File 'lib/gdash.rb', line 13

def dash_templates
  @dash_templates
end

#fromObject (readonly)

Returns the value of attribute from.



13
14
15
# File 'lib/gdash.rb', line 13

def from
  @from
end

#graphite_baseObject (readonly)

Returns the value of attribute graphite_base.



13
14
15
# File 'lib/gdash.rb', line 13

def graphite_base
  @graphite_base
end

#graphite_renderObject (readonly)

Returns the value of attribute graphite_render.



13
14
15
# File 'lib/gdash.rb', line 13

def graphite_render
  @graphite_render
end

#heightObject (readonly)

Returns the value of attribute height.



13
14
15
# File 'lib/gdash.rb', line 13

def height
  @height
end

#untilObject (readonly)

Returns the value of attribute until.



13
14
15
# File 'lib/gdash.rb', line 13

def until
  @until
end

#widthObject (readonly)

Returns the value of attribute width.



13
14
15
# File 'lib/gdash.rb', line 13

def width
  @width
end

Instance Method Details

#dashboard(name, options = {}) ⇒ Object



27
28
29
30
31
32
33
34
# File 'lib/gdash.rb', line 27

def dashboard(name, options={})
  options[:width] ||= @width
  options[:height] ||= @height
  options[:from] ||= @from
  options[:until] ||= @until

  Dashboard.new(name, dash_templates, options)
end

#dashboardsObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/gdash.rb', line 40

def dashboards
  dashboards = []

  Dir.entries(dash_templates).each do |dash|
    begin
      yaml_file = File.join(dash_templates, dash, "dash.yaml")
      if File.exist?(yaml_file)
        dashboards << YAML.load_file(yaml_file).merge({:link => dash})
      end
    rescue Exception => e
      p e
    end
  end

  dashboards.sort_by{|d| d[:name].to_s}
end

#listObject



36
37
38
# File 'lib/gdash.rb', line 36

def list
  dashboards.map {|dash| dash[:link]}
end