Project

mercy

0.0
No commit activity in last 3 years
No release in over 3 years
Gem for easy health check
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.16.1
~> 0.2.4
>= 12.3.1
>= 3.8
= 0.58.1
>= 4.0.2
~> 0.16.x
>= 0.9.18
>= 0.9.9

Runtime

 Project Readme

Mercy

Code Climate Test Coverage Issue Count Gem Version

mercy

This gem tries to make server monitoring easier and more reliable by adding an easly configurable report and making it avaliable in a controller

Yard Documentation

https://www.rubydoc.info/gems/mercy/1.6.0

Getting started

  1. Add Mercy to your Gemfile and bundle install:

    gem 'mercy'
  2. Include in your health check controller passing the configuration to fetch your Documents with error and render the report

class HealthCheckController < ApplicationController
  include Mercy

  status_report :failures, clazz: Document
  status_report :failures, clazz: Schedules, on: :schedules
  status_report :delays, clazz: Schedules, scope: :late, on: :schedules
  status_report :'documents.count', clazz: Document, scope: :active, type: Mercy::Range, minimum: 100
  status_report :'documents.errors', clazz: Document, scope: :'active.with_error', type: :range, maximum: 1000

  def status
    render_status
  end

  def late_status
    render_status(:schedules)
  end
end
  1. Add a route to your controller
scope path: 'health-check', controller: :health_check do
  get '/status' => :status
  get '/late-status' => :late_status
end
  1. Set the correct options on your status report to achieve a perfect report
  • clazz: Class of the object that might contain error
  • period: default search period (default: 1 day)
  • on: report bucket (default: :default)
  • type: report type (error, range or other custom report)

Remembering that each report may have its onw parameters

  • Mercy::Report::Error
    • scope: scope to be fetched when trying to find objects with error (default: :with_error)
    • external_key: column to be exposed as id for the objects with error
    • threshold: default report threshold (default: 0.02)
    • base_scope: scope to be universal sample
    • uniq: when the output ids should not be repeated
    • limit: limit of ids to be outputed
  • Mercy::Report::Range
    • scope: scope of the query to be counted
    • maximum: max value accepted in the range
    • minimum: minimum value accepted in the range
  1. Run the server and hit the health-check routes
wget http://localhost:3000/health-check/status
wget http://localhost:3000/health-check/late-status
  1. Customize your request for multiple reports
wget http://localhost:3000/health-check/status?period=3.days&threshold=0.005
wget http://localhost:3000/health-check/late-status?period=1.hours&threshold=0.1
  1. Use the status json to understand what is wrong
{
  "status": "error",
  "failures": {
    "ids": [10, 14],
    "percentage": 0.5,
    "status": "error"
  },
  "delays": {
    "ids": [12],
    "percentage": 0.001,
    "status": "ok"
  }
}