Class: Prosperity::MetricsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Prosperity::MetricsController
- Defined in:
- app/controllers/prosperity/metrics_controller.rb
Instance Method Summary collapse
Instance Method Details
#data ⇒ Object
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 65 66 |
# File 'app/controllers/prosperity/metrics_controller.rb', line 38 def data ext_name = params.fetch(:extractor, "interval") ext_klass = Metric.extractors.fetch(ext_name) do render_json_error "Could not find extractor #{ext_name} for #{@metric}. Possible values are #{Metric.extractors.keys.join(", ")}.", 404 return end p = Prosperity::Periods::ALL.fetch(period) ext = ext_klass.new(@metric, option, start_time, end_time, p) data = begin ext.to_a rescue => e logger.error "#{e}\n#{e.backtrace.join("\n")}" render_json_error "An exception occured while retrieving data from #{@metric}. #{e}" return end json = { data: data, key: ext.key, uid: ext.uid, label: ext.label, start_time: p.actual_start_time(start_time).iso8601, end_time: p.actual_end_time(end_time).iso8601, period_milliseconds: p.duration * 1000 } render json: json end |
#index ⇒ Object
7 8 9 |
# File 'app/controllers/prosperity/metrics_controller.rb', line 7 def index @metrics = MetricFinder.all end |
#show ⇒ Object
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 |
# File 'app/controllers/prosperity/metrics_controller.rb', line 11 def show respond_to do |format| format.html format.json do render json: { id: @metric.id, title: @metric.title, options: @metric..map do |k, option| {key: k} end, extractors: @metric.extractors.map do |ext| { key: ext.key, url: data_metric_path(id: @metric.id, extractor: ext.key, option: option, period: period, start_time: start_time, end_time: end_time), } end } end end end |