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