Class: Gremlin::MetricsController

Inherits:
ActionController::Base
  • Object
show all
Defined in:
app/controllers/gremlin/metrics_controller.rb

Instance Method Summary collapse

Instance Method Details

#indexObject



3
4
5
# File 'app/controllers/gremlin/metrics_controller.rb', line 3

def index
  render plain: marshal.join("\n")
end

#marshalObject



7
8
9
10
11
12
13
14
15
# File 'app/controllers/gremlin/metrics_controller.rb', line 7

def marshal
  registry = Gremlin.registry

  metrics = registry.metrics.map do |metric|
    metric.repr
  end

  plaintext(metrics)
end

#plaintext(metric_representations) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/controllers/gremlin/metrics_controller.rb', line 17

def plaintext(metric_representations)
  lines = []
  metric_representations.each do |repr|
    lines << repr[:type]
    lines << repr[:help]

    # Prometheus expects metric labels to be of the format <label>="<label_value>"
    repr[:values].each do |labels, value|
      l = []
      labels.each do |k,v|
        l << "#{k}=\"#{v}\""
      end
      lines << "#{repr[:name].to_s}{#{l.join(',')}} #{value}"
    end
  end
  lines
end