Sha256: c8ecf689fe01ce06090e8ddcfa6e75cd604edd6e0a2b5ca49d45a18fc36115cf

Contents?: true

Size: 653 Bytes

Versions: 1

Compression:

Stored size: 653 Bytes

Contents

require 'open-uri'
require 'json'

module Remon
  module Metrics
    class Consul

      def initialize(host: "127.0.0.1", port: 8500)
        @host = host
        @port = port
      end

      def failed_nodes
        nodes = {}
        failed_serf_checks = critical_checks.select { |i| i["CheckID"] == "serfHealth" }
        failed_serf_checks.each { |i| nodes[i["Node"]] = i["Output"] }
        nodes
      end

      private

      def consul_url(path)
        "http://#{@host}:#{@port}#{path}"
      end

      def critical_checks
        url = consul_url("/v1/health/state/critical")
        JSON.parse(open(url).read)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
remon-0.1.0 lib/remon/metrics/consul.rb