Sha256: 215e6b29e7a932b544ac44cb68e01930fb6df0276e6b6b5626795d0b16d9f1c4

Contents?: true

Size: 841 Bytes

Versions: 1

Compression:

Stored size: 841 Bytes

Contents

require 'remon/metrics/http'

defcheck :http do

  opts ({
    error_statuses: [502, 500, 503],
    read_timeout: 1,
    open_timeout: 1
  })

  def init(url)
    @url = url
    @http = Metrics::Http.new(url)
  end

  def run
    http_status
  end

  private

  def http_status
    time, status = @http.status(read_timeout: opts[:read_timeout], open_timeout: opts[:open_timeout])
    state = state(status)
    event({
      service: "http #{@url}",
      description: "#{status} in #{(time * 1000).round(2)} ms",
      state: state,
      metric: metric(state)
    })
  end

  def metric(state)
    case state
    when "ok"
      0
    when "warning"
      0.9
    when "critical"
      1
    end
  end

  def state(status)
    if status >= 500
      "critical"
    elsif status == 444
      "critical"
    else
      "ok"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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