Sha256: 16a2bd5a502e0d978aa4a328659adc9845fa46b63b5d21b3bd7fba089e1ca9a3

Contents?: true

Size: 1.36 KB

Versions: 1

Compression:

Stored size: 1.36 KB

Contents

# Sc4ry module
# @note namespace
module Sc4ry

  # Sc4ry::Notifiers module
  # @note namespace
  module Notifiers

  
    # Prometheus notifier class
    class Prometheus

      @@registry = ::Prometheus::Client::Registry::new
      @@metric_circuit_state = ::Prometheus::Client::Gauge.new(:cuircuit_state, docstring: 'Sc4ry metric : state of a circuit', labels: [:circuit])

      @@registry.register(@@metric_circuit_state)

    

      # send metrics to Prometheus PushGateway
      # @return [Bool]
      def Prometheus.notify(options = {})
        @config = Sc4ry::Notifiers.get(name: :prometheus)[:config]
        status = options[:config][:status][:general]
        circuit = options[: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
    end

    
    
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sc4ry-0.2.0 lib/sc4ry/notifiers/prometheus.rb