Module: Prometheus::Controller

Defined in:
lib/volume_sweeper/metrics/controller.rb

Class Method Summary collapse

Class Method Details

.clear_metricsObject



24
25
26
27
28
29
# File 'lib/volume_sweeper/metrics/controller.rb', line 24

def self.clear_metrics
  @prometheus ||= Prometheus::Client.registry
  unregister_gauge :available_block_volume_count
  unregister_gauge :released_pv_count
  unregister_gauge :inactive_block_volume_count
end

.register_gauge(key, docstring, *labels) ⇒ Object



31
32
33
34
35
# File 'lib/volume_sweeper/metrics/controller.rb', line 31

def self.register_gauge key, docstring, *labels
  gauge = Prometheus::Client::Gauge.new key, docstring: docstring, labels: labels
  @prometheus.register(gauge)
  gauge
end

.setup_metricsObject

TODO: ..



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/volume_sweeper/metrics/controller.rb', line 5

def self.setup_metrics
  metrics_dir = Rails.root.join 'tmp', 'prometheus'
  Dir["#{metrics_dir}/*.bin"].each { |file_path| File.unlink(file_path) }
  Prometheus::Client.config.data_store = Prometheus::Client::DataStores::DirectFileStore.new(dir: metrics_dir)

  @prometheus ||= Prometheus::Client.registry

  register_gauge :available_block_volume_count,
                 'The total of unattached block volumes.',
                 :available_block_volume_count
  register_gauge :released_pv_count,
                 'The total of released persistent volumes.',
                 :released_pv_count
  register_gauge :inactive_block_volume_count,
                 'The number of block volumes count that are unused (no instance or PV bound).',
                 :inactive_block_volume_count

end

.unregister_gauge(key) ⇒ Object



37
38
39
# File 'lib/volume_sweeper/metrics/controller.rb', line 37

def self.unregister_gauge key
  @prometheus.unregister key
end