require 'remon/metrics/consul' defcheck :consul do def init(host: "127.0.0.1", port: 8500) @consul = Metrics::Consul.new(host: host, port: port) end def run members_status end private def members_status failed_nodes = @consul.failed_nodes state = failed_nodes.size > 0 ? "critical" : "ok" event({ service: "consul members", description: description(failed_nodes), state: state, metric: metric(state) }) end def description(failed_nodes) n = failed_nodes.size s = "#{n} failed nodes" if n > 0 d = failed_nodes.map {|k,v| "#{k}: #{v}"}.join("\n") "#{s}\n#{d}" else s end end def metric(state) state == "ok" ? 0 : 1 end end