Sha256: 925287feb42ad1212f335fa09f7d38a26dc22c74d95880792578d14be8dd6c57

Contents?: true

Size: 741 Bytes

Versions: 1

Compression:

Stored size: 741 Bytes

Contents

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

Version data entries

1 entries across 1 versions & 1 rubygems

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