Class: Grafana::Dashboard

Inherits:
Object
  • Object
show all
Defined in:
lib/grafana/dashboard.rb

Overview

Representation of one specific dashboard in a Grafana instance.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, grafana) ⇒ Dashboard

Returns a new instance of Dashboard.

Parameters:

  • model (Hash)

    converted JSON Hash of the grafana dashboard

  • grafana (Grafana)

    parent Grafana object



12
13
14
15
16
17
18
# File 'lib/grafana/dashboard.rb', line 12

def initialize(model, grafana)
  @grafana = grafana
  @model = model

  init_panels
  init_variables
end

Instance Attribute Details

#grafanaGrafana (readonly)

Returns parent Grafana object.

Returns:



7
8
9
# File 'lib/grafana/dashboard.rb', line 7

def grafana
  @grafana
end

#panelsObject (readonly)

Returns the value of attribute panels.



8
9
10
# File 'lib/grafana/dashboard.rb', line 8

def panels
  @panels
end

#variablesObject (readonly)

Returns the value of attribute variables.



8
9
10
# File 'lib/grafana/dashboard.rb', line 8

def variables
  @variables
end

Instance Method Details

#from_timeString

Returns from time configured in the dashboard.

Returns:

  • (String)

    from time configured in the dashboard.



21
22
23
24
25
# File 'lib/grafana/dashboard.rb', line 21

def from_time
  return @model['time']['from'] if @model['time']

  nil
end

#idString

Returns dashboard UID.

Returns:

  • (String)

    dashboard UID



34
35
36
# File 'lib/grafana/dashboard.rb', line 34

def id
  @model['uid']
end

#panel(id) ⇒ Panel

Returns panel for the specified ID.

Returns:

  • (Panel)

    panel for the specified ID

Raises:



44
45
46
47
48
49
# File 'lib/grafana/dashboard.rb', line 44

def panel(id)
  panels = @panels.select { |item| item.field('id') == id.to_i }
  raise PanelDoesNotExistError.new(id, self) if panels.empty?

  panels.first
end

#titleString

Returns dashboard title.

Returns:

  • (String)

    dashboard title



39
40
41
# File 'lib/grafana/dashboard.rb', line 39

def title
  @model['title']
end

#to_timeString

Returns to time configured in the dashboard.

Returns:

  • (String)

    to time configured in the dashboard.



28
29
30
31
# File 'lib/grafana/dashboard.rb', line 28

def to_time
  @model['time']['to'] if @model['time']
  nil
end