• Stars
    star
    379
  • Rank 113,004 (Top 3 %)
  • Language
    Ruby
  • License
    MIT License
  • Created almost 12 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Provides a health-check endpoint to your Ruby on Rails apps.

Code Climate Build Status

OK Computer

Inspired by the ease of installing and setting up fitter-happier as a Rails application's health check, but frustrated by its lack of flexibility, OK Computer was born. It provides a robust endpoint to perform server health checks with a set of built-in plugins, as well as a simple interface to add your own custom checks.

For more insight into why we built this, check out our blog post introducing OK Computer.

OkComputer currently supports the following Rails versions:

  • 6.1
  • 6.0
  • 5.2
  • 5.1
  • 4.2

Not using Rails?

If you use Grape instead of Rails, check out okcomputer-grape.

Installation

Add this line to your application's Gemfile:

gem 'okcomputer'

And then execute:

$ bundle

Or install it yourself as:

$ gem install okcomputer

Usage

To perform the default checks (application running and ActiveRecord database connection), do nothing other than adding to your application's Gemfile.

If Not Using ActiveRecord

We also include a MongoidCheck, but do not register it. If you use Mongoid, replace the default ActiveRecord check like so:

OkComputer::Registry.register "database", OkComputer::MongoidCheck.new

If you use another database adapter, see Registering Custom Checks below to build your own database check and register it with the name "database" to replace the built-in check, or use OkComputer::Registry.deregister "database" to stop checking your database altogether.

Requiring Authentication

Optionally require HTTP Basic authentication to view the results of checks in an initializer, like so:

# config/initializers/okcomputer.rb
OkComputer.require_authentication("username", "password")

To allow access to specific checks without a password, optionally specify the names of the checks:

# config/initializers/okcomputer.rb
OkComputer.require_authentication("username", "password", except: %w(default nonsecret))

Changing the OkComputer Route

By default, OkComputer routes are mounted at /okcomputer. If you'd like to use an alternate route, you can configure it with:

# config/initializers/okcomputer.rb
OkComputer.mount_at = 'health_checks'    # mounts at /health_checks

For more control of adding OkComputer to your routes, set OkComputer.mount_at = false to disable automatic mounting, and you can manually mount the engine in your routes.rb.

# config/initializers/okcomputer.rb
OkComputer.mount_at = false

# config/routes.rb, at any priority that suits you
mount OkComputer::Engine, at: "/custom_path"

Logging check results

Log check results by setting OkComputer.logger. Note: results will be logged at the info level.

OkComputer.logger = Rails.logger
[okcomputer] mycheck: PASSED mymessage (0s)

Registering Additional Checks

Register additional checks in an initializer, like so:

# config/initializers/okcomputer.rb
OkComputer::Registry.register "resque_down", OkComputer::ResqueDownCheck.new
OkComputer::Registry.register "resque_backed_up", OkComputer::ResqueBackedUpCheck.new("critical", 100)

# This check works on 2.4.0 and above versions of resque-scheduler
OkComputer::Registry.register "resque_scheduler_down", OkComputer::ResqueSchedulerCheck.new

Registering Custom Checks

The simplest way to register a check unique to your application is to subclass OkComputer::Check and implement your own #check method, which sets the display message with mark_message, and calls mark_failure if anything is wrong.

# config/initializers/okcomputer.rb
class MyCustomCheck < OkComputer::Check
  def check
    if rand(10).even?
      mark_message "Even is great!"
    else
      mark_failure
      mark_message "We don't like odd numbers"
    end
  end
end

OkComputer::Registry.register "check_for_odds", MyCustomCheck.new

Registering Optional Checks

Register an optional check like so:

# ...
OkComputer::Registry.register "some_optional_check", OkComputer::ResqueBackedUpCheck.new("critical", 100)
# ...

OkComputer.make_optional %w(some_optional_check another_optional_check)

This check will run and report its status, but will not affect the HTTP status code returned.

Customizing plain-text output

The plain-text output flows through Rails' internationalization framework. Adjust the output as necessary by defining okcomputer.check.passed and okcomputer.check.failed keys in your setup. The default values are available in okcomputer.en.yml.

Running checks in parallel

By default, OkComputer runs checks in sequence. If you'd like to run them in parallel, you can configure it with:

# config/initializers/okcomputer.rb
OkComputer.check_in_parallel = true

Performing Checks

Checks are available as plain text (by default) or JSON by appending .json, e.g.:

OkComputer NewRelic Ignore

If NewRelic is installed, OkComputer automatically disables NewRelic monitoring for uptime checks, as it will start to artificially bring your request time down.

If you'd like to intentionally count OkComputer requests in your NewRelic analytics, set:

# config/initializers/okcomputer.rb
OkComputer.analytics_ignore = false

Development

Setup

$ bundle install

Running the test suite

OkComputer tests are written with RSpec.

To run the full test suite:

$ rake spec

You may also use the environment variable RAILS_VERSION with one of the supported versions of Rails (found at the top of this file) to bundle and run the tests with a specific version of Rails.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

More Repositories

1

hubstats

Gamification of Github
Ruby
44
star
2

rds-pgbadger

An automation tool for generating pgBadger reports from Amazon RDS PostgreSQL database instances.
Ruby
38
star
3

objective-ci

Continuous integration metrics for iOS
C
32
star
4

active_zuora

An ActiveModel-based API for Zuora that is auto-generated from your zuora.wsdl.
Ruby
20
star
5

opsicle

A gem bringing the glory of OpsWorks to your command line.
Ruby
20
star
6

find_as_hashes

Provides ActiveRecord methods to return results as attribute hashes rather than instantiated ActiveRecord objects. Useful when working with very large sets of results to improve performance.
Ruby
19
star
7

hasoffers

Ruby gem implementation of the HasOffers API for affiliate advertising.
Ruby
17
star
8

styleguide

Sport Ngin's opinions on how best to write high-quality code.
Ruby
15
star
9

octopolo

A GitHub workflow for the command line.
Ruby
15
star
10

kyck_EpicDB

Elixir Event Store Implementation
Elixir
7
star
11

linkshare

Ruby gem for LinkShare API
Ruby
6
star
12

active_mongoid

Ruby
5
star
13

enumerated_field

EnumeratedField is a library that provides some nice methods when a string column is used like an enumeration.
Ruby
5
star
14

typhoid

A lightweight ORM-like wrapper around Typhoeus
Ruby
4
star
15

aws-security-czar

Rule manager for EC2 Security Groups
Ruby
3
star
16

nokomis

JavaScript
3
star
17

ngin_client_node

JavaScript
3
star
18

pepperjam

A ruby gem for accessing the Pepperjam API
Ruby
3
star
19

soyuz

The old trusty deployment toolkit
Ruby
3
star
20

queuel

Ruby
3
star
21

simple_benchmark

A simple benchmark comparing rails 3 performance vs. rails 2
HTML
2
star
22

ical_importer

Ruby
2
star
23

good-json-console

Json Console reporting for Good process monitor
JavaScript
2
star
24

rolypoly

Ruby
2
star
25

kyck-ruby-consul

Ruby client gem for consul
Ruby
1
star
26

homebrew-homebrew

Sportngin's Homebrew Formulas
Ruby
1
star
27

octopolo-plugin-example

An example octopolo plugin
Ruby
1
star
28

newrelic_postgresql_agent

New Relic PostgreSQL plugin compatible with AWS RDS.
Ruby
1
star
29

grunt-browserifyAliases

Grunt task for aliasing your directories for browserify.
JavaScript
1
star
30

commission_junction

Ruby
1
star
31

api_mailer

Ruby
1
star
32

kyck_consul_cookbook

Chef cookbook for consul (consul.io)
Ruby
1
star
33

newrelic_passenger_stats_plugin

Ruby
1
star
34

resque_sliding_window

Ruby
1
star
35

mail_male_mail

Ruby
1
star
36

sport-ng

JavaScript
1
star