Class: Sc4ry::Notifiers::Prometheus
- Inherits:
-
Object
- Object
- Sc4ry::Notifiers::Prometheus
- Defined in:
- lib/sc4ry/notifiers/prometheus.rb
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
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/sc4ry/notifiers/prometheus.rb', line 16 def Prometheus.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] then @@metric_circuit_state.set(status_map[status], labels: {circuit: circuit.to_s }) Sc4ry::Helpers.log level: :debug, message: "Prometheus Notifier : notifying for circuit #{circuit.to_s}, state : #{status.to_s}." return ::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 |