Class: Sc4ry::Notifiers::Prometheus
- Inherits:
-
Object
- Object
- Sc4ry::Notifiers::Prometheus
- Defined in:
- lib/sc4ry/notifiers/prometheus.rb
Overview
Prometheus notifier class
Constant Summary collapse
- @@registry =
::Prometheus::Client::Registry.new
- @@metric_circuit_state =
::Prometheus::Client::Gauge.new(:cuircuit_state, docstring: 'Sc4ry metric : state of a circuit', labels: [:circuit])
Class Method Summary collapse
-
.notify(options = {}) ⇒ Bool
send metrics to Prometheus PushGateway.
Class Method Details
.notify(options = {}) ⇒ Bool
send metrics to Prometheus PushGateway
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/sc4ry/notifiers/prometheus.rb', line 20 def self.notify( = {}) @config = Sc4ry::Notifiers.get(name: :prometheus)[:config] status = [:config][:status][:general] circuit = [:circuit] status_map = { open: 0, half_open: 1, closed: 2 } if Sc4ry::Helpers.verify_service url: @config[:url] @@metric_circuit_state.set(status_map[status], labels: { circuit: circuit.to_s }) Sc4ry::Helpers.log level: :debug, message: "Prometheus Notifier : notifying for circuit #{circuit}, state : #{status}." ::Prometheus::Client::Push.new(job: 'Sc4ry', instance: Socket.gethostname, gateway: @config[:url]).add(@@registry) else Sc4ry::Helpers.log level: :warn, message: "Prometheus Notifier : can't notify Push Gateway not reachable." end end |