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