Class: GraphsController

Inherits:
ApplicationController show all
Includes:
Helpers, Layouts::ApplicationLayoutHelper
Defined in:
app/controllers/graphs_controller.rb

Overview

Control the main Graphs GUI

Constant Summary

Constants included from Helpers

Helpers::REDIS_KEY

Constants included from Layouts::ApplicationLayoutHelper

Layouts::ApplicationLayoutHelper::UI_DEFAULTS

Instance Method Summary collapse

Methods included from Helpers

#data_sanitize, #delete_metrics_cache, #get_json, #init_lib, #init_source, #init_store, #interpolate, #is_up?, #json_metrics, #json_metrics_list, #keysplit, #mandatory_param, #optional_param, #origin_settings, #redis_conn, #top_tail_pad

Methods included from Layouts::ApplicationLayoutHelper

#add_qs, #alter_qs, #check_param, #chg_qs, #chk_qs, #dropdown, #flash_class, #get_param, #hash_query, #is_epoch, #is_nicetime, #navbar_buttons, #navbar_dropdown, #nicetime_split, #obl_qs, #que_qs, #query_hash, #refresh_errors, #rem_qs, #settings_suppress, #to_bool, #to_epoch, #ui_default, #ui_message, #version

Instance Method Details

#absolute_timeObject

Absolute time form POST submission


123
124
125
126
127
128
129
# File 'app/controllers/graphs_controller.rb', line 123

def absolute_time 
  start = Time.parse(params[:time][:start_time]).to_i
  stop = Time.parse(params[:time][:stop_time]).to_i
  p_url = chg_qs(:start, start, {url: :referer})
  url = chg_qs(:stop, stop, {url: p_url})
  redirect_to root_path + url
end

#indexObject

Main index of the system


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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'app/controllers/graphs_controller.rb', line 9

def index
  gon.metrics = []

  # Get the parameters from the UI, or use defaults.
  start = to_epoch(get_param(:start))
  stop  = to_epoch(get_param(:stop))

  step  = params[:step]  || (stop - start).to_i / UI_DEFAULTS[:points]
  gon.start, gon.stop, gon.step = start, stop, step

  gon.clock = params[:clock] || UI_DEFAULTS[:clock]

  base = obl_qs(:stop, {url: obl_qs(:start) })
  base = chg_qs(:time, "absolute", {url: base})

  gon.base = base


  # Get all the metrics, and build up a javascript blob with their useful bits
  new_metrics = que_qs(:metric)
  gon.metrics = []
  @metrics = []

  new_metrics.each_with_index do |metric,i|
    m = Metric.new(metric)
    @metrics << m

    g = {}
    g[:id]        = m.id
    g[:feed_base] = m.feed
    g[:live]      = m.live?
    g[:title]     = m.titleize
    g[:metadata]  = m.
    g[:sourceURL] = m.get_metric_url start, stop, step
    g[:removeURL] = "javascript:removechart(\"#{metric}\", \"#{rem_qs(:metric, metric)}\")"
   # g[:counter] = true if m.counter? ##TODO Incorporate vaultaire based metadata

    gon.metrics << g
  end

  @gon = gon

  # Validate the times before continuing on
  if stop < start
    flash.now[:error] = "Start time has to be before stop time"
    return
  end

  if stop - start <  UI_DEFAULTS[:points]
    flash.now[:error] = "Time range must be at least #{UI_DEFAULTS[:points]} seconds apart."
    return
  end

  # Everything should be ok from here on out
  @graph = get_param(:graph)
end

#refreshObject

Refresh the settings file and cached metrics. UI button within the settings modal


67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'app/controllers/graphs_controller.rb', line 67

def refresh
  
  # Remove all the redis data  
  delete_metrics_cache

  # Reload all settings files (rails_config)
  Settings.reload!
  errors = []

  # For all the origins, if available, confirm if they are up, and refresh their cache of metrics
  if Settings.origins.nil?
    flash[:error] = ui_message(:no_backends)
  else 
    inactive_backends = []; refresh_errors :remove
    Settings.origins.each do |o|
      begin
        origin, settings = o
        store = init_store settings.store, origin, settings
        store.refresh_metrics_cache
      rescue Store::Error => e
        inactive_backends << [o[0], e]
        errors << e
      end
    end

    # Store the information about why the store refresh failed. 
    unless errors.empty?
      flash[:error] = errors.join("<br/>").html_safe 
      refresh_errors :save, inactive_backends
    end
  end
  redirect_to root_path
end

#stop_timeObject

Relative Time form POST submission


113
114
115
116
117
118
119
120
# File 'app/controllers/graphs_controller.rb', line 113

def stop_time
  if params[:commit] == "now"
    redirect_to root_path + obl_qs(:stop, {url: :referer})
  else 
    stop = params[:time][:number] + params[:commit]
    redirect_to root_path + chg_qs(:stop, stop, {url: :referer})
  end
end

#submitObject

Metrics modal search POST submission


102
103
104
105
106
107
108
109
110
# File 'app/controllers/graphs_controller.rb', line 102

def submit
  metrics = params[:filter][:metrics_select]

  # select2 modal separator: ";", changed purposefully. Will break if metrics contain semicolon. 
  metrics = metrics.split(";") 

  metrics.reject! { |c| c.empty? or c.include?("0000")} 
  redirect_to root_path + chg_qs(:metric, metrics, {url: :referer})
end