{"id":13880163,"url":"https://github.com/envato/rack-ecg","last_synced_at":"2025-08-19T22:32:15.572Z","repository":{"id":30024459,"uuid":"33573340","full_name":"envato/rack-ecg","owner":"envato","description":"Health check page as Rack middleware","archived":false,"fork":false,"pushed_at":"2024-02-05T21:12:51.000Z","size":176,"stargazers_count":38,"open_issues_count":0,"forks_count":9,"subscribers_count":71,"default_branch":"main","last_synced_at":"2024-12-07T12:02:46.152Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/envato.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-04-07T23:18:57.000Z","updated_at":"2024-10-09T15:48:37.000Z","dependencies_parsed_at":"2023-11-17T07:51:08.049Z","dependency_job_id":"14a9cb4c-d0b8-417c-ab9c-670d666e3b0d","html_url":"https://github.com/envato/rack-ecg","commit_stats":{"total_commits":145,"total_committers":11,"mean_commits":"13.181818181818182","dds":0.6482758620689655,"last_synced_commit":"dcba6dd806f197e2f1a9a82eab18121f1a2ad7d2"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/envato%2Frack-ecg","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/envato%2Frack-ecg/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/envato%2Frack-ecg/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/envato%2Frack-ecg/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/envato","download_url":"https://codeload.github.com/envato/rack-ecg/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230374118,"owners_count":18216041,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-06T08:02:49.668Z","updated_at":"2024-12-19T04:06:58.674Z","avatar_url":"https://github.com/envato.png","language":"Ruby","funding_links":[],"categories":["Ruby"],"sub_categories":[],"readme":"# Rack::ECG\n\n[![Gem version](https://img.shields.io/gem/v/rack-ecg)][gem-page] [![Rubydoc](https://img.shields.io/badge/docs-rubydoc-success)][rubydoc]\n\nRack middleware for Ruby web apps, providing a simple and extensible health\ncheck endpoint, with minimal configuration.\n\n\u003e Electrocardiogram (ECG): A recording of the electrical activity of the heart.\n\n## Features\n\n- Start with a single line in your `config.ru` or `config/application.rb` file.\n- reports git revision status\n- reports ActiveRecord migration schema version\n- reports errors if any check can't be executed for whatever reason\n- JSON output\n\n## Development Status\n\n[![Build Status](https://github.com/envato/rack-ecg/workflows/test/badge.svg?branch=main)](https://github.com/envato/rack-ecg/actions?query=branch%3Amain)\n\n`Rack::ECG` is extracted from production code in use at\n[Envato](http://envato.com). However, it is undergoing early development, and\nAPIs and features are almost certain to be in flux.\n\n## Getting Started\n\nAdd this to your application's `Gemfile`:\n\n```ruby\ngem 'rack-ecg', '~\u003e 0.3.0`\n```\n\nThen run `bundle install`.\n\nIn Rails you can add `Rack::ECG` to your `config/application.rb` as a middleware:\n\n```ruby\n# config/application.rb\n# ...\nconfig.middleware.use Rack::ECG\n# ...\n```\n\nIn Rack apps, you can add `Rack::ECG` to your `config.ru`:\n\n```ruby\n# config.ru\nrequire 'rack/ecg'\n\nuse Rack::ECG\n\nrun MyRackApp\n```\n\n## Usage\n\nYou can now hit your app and get a basic health check response from `Rack::ECG`\n\n```\n$ curl http://localhost:9292/_ecg\n{\n  \"http\": {\n    \"status\": \"ok\",\n    \"value\": \"online\"\n  }\n}\n```\n\n`/_ecg` will return a `200` HTTP status if all the checks are OK, or `500`\nstatus if any of the checks fail.\n\n\n## Configuration\n\nThere are options that can be passed to `use Rack::ECG` to customise how it works.\n\n### Checks\n\nBy default, `Rack::ECG` indicates that the service is reponsive via a `http` check. Additional checks are included in this gem, and can be enabled by passing their configuration to the `checks` parameter. To enable a check, add its name, and optionally configuration, to the `checks` array:\n\n```ruby\nuse Rack::ECG, checks: [\n  # no configuration required, or allowed\n  :http,\n  # passing configuration options\n  [:static, { name: \"app\", value: \"my-cool-app\" }],\n  # some checks can be used multiple times\n  [:static, { name: \"env\", value: Rails.env }],\n]\n```\n\n#### `active_record`\n\nRequires a configured ActiveRecord connection. Does not support configuration. Indicates whether the connection to the default database is currently open. On success, returns something in the following format:\n\n```json\n{\n  \"active_record\": {\n    \"status\": \"ok\",\n    \"value\": true\n  }\n}\n```\n\n#### `error`\n\nDoes not support configuration. Always returns the following:\n\n```json\n{\n  \"error\": {\n    \"status\": \"error\",\n    \"value\": \"PC LOAD ERROR\"\n  }\n}\n```\n\n#### `git_revision`\n\n**Deprecated**: will be removed in version 1.0.0. [See the GitRevision Check Replacement example](./examples/git_revision_check_replacement.ru), which uses the `static` check to memoize the value.\n\nRequires the `git` executable on path, and that the application's working directory is within a Git repository. Does not support configuration. On success, returns something in the following format:\n\n```json\n{\n  \"git_revision\": {\n    \"status\": \"ok\",\n    \"value\": \"dc840f9d5563e6e5a8b34da29c298764e3046039\"\n  }\n}\n```\n\n#### `http`\n\nAutomatically included, and does not support configuration. Always returns the following:\n\n```json\n{\n  \"http\": {\n    \"status\": \"ok\",\n    \"value\": \"online\"\n  }\n}\n```\n\n#### `migration_version`\n\nRequires a configured ActiveRecord connection, and that ActiveRecord migrations are in use. Does not support configuration. Queries the `schema_versions` table on the default database to report the current migration version. On success, returns something in the following format:\n\n```json\n{\n  \"migration_version\": {\n    \"status\": \"ok\",\n    \"value\": \"20210506024055\"\n  }\n}\n```\n\n#### `redis`\n\nRequires the Redis gem. Requires configuration, an instance of a Redis client. Indicates whether the Redis client passed in is currently connected to the Redis database. On success, returns something in the following format:\n\n```json\n{\n  \"redis\": {\n    \"status\": \"ok\",\n    \"value\": true\n  }\n}\n```\n\n#### `sequel`\n\nRequires the Sequel gem. Requires configuration, and can be configured multiple times. Indicates whether a (new) connection can be established to the configured Sequel database.\n\nGiven the following configuration:\n\n```ruby\n{\n  connection: \"sqlite://events.db\",\n  name: \"events\", # must be unique per sequel check\n}\n```\n\nReturns the something in the following format on success:\n\n```json\n{\n  \"sequel_events\": {\n    \"status\": \"ok\",\n    \"value\": true\n  }\n}\n```\n\n#### `static`\n\nReturns the same value every time. Requires configuration, and can be configured multiple times.\n\nGiven the following configuration:\n\n```ruby\n{\n  name: \"image_build_url\",               # must be unique per static check\n  success: true,                         # default value\n  status: Rack::ECG::Check::Status::OK,  # optional, overrides `success`\n  value: ENV[\"IMAGE_BUILD_URL\"], \n}\n```\n\nReturns the something in the following format:\n\n```json\n{\n  \"image_build_url\": {\n    \"status\": \"ok\",\n    \"value\": \"https://example.com/pipelines/my-cool-app/builds/1234\"\n  }\n}\n```\n\n### `at`\n\nBy default `Rack::ECG` is mapped to a URL of `/_ecg`, you can set this to\na different path by setting the `at` option. e.g.\n\n```ruby\nuse Rack::ECG, at: \"/health_check\"\n```\n\n### `hook`\n\nThe `hook` option takes a `Proc` or equivalent, and calls it after the checks\nhave run, but before the response is complete.\n\n```ruby\nuse Rack::ECG, hook: Proc.new { |success, _checks| puts \"Is healthy? #{success}\" }\n```\n\n- `success`: whether the response will indicate success\n- `checks`: an array of the check names and values\n\n### `failure_status`\n\nBy default, check failures result in a HTTP status code `500` (Internal Server\nError). You can change this code by setting the `failure_status` option. e.g.\n\n```ruby\nuse Rack::ECG, checks: [:error], failure_status: 503\n```\n\n## Requirements\n\n- Ruby \u003e= 2.6\n- Rack\n- To use optional `git_revision` check, your deployed code needs to be in a git repo, and\n`git` command must be accessible on the server\n- To use optional `migration_version` check, you must be using ActiveRecord and\nmigrations stored in `schema_versions` table\n\n## Examples\n\nSome configuration examples are provided in [/examples](https://github.com/envato/rack-ecg/tree/main/examples).\n\n## Contact\n\n- [github project](https://github.com/envato/rack-ecg)\n- [gitter chat room ![Join the chat at\n  https://gitter.im/envato/rack-ecg](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/envato/rack-ecg)\n- Bug reports and feature requests are via [github issues](https://github.com/envato/rack-ecg/issues)\n\n## Maintainers\n\n- [Liam Dawson](https://github.com/liamdawson)\n- [Andrew Davis](https://github.com/andyjdavis)\n\n## Contributors\n\n- [Tao Guo](https://github.com/taoza)\n- [Julian Doherty](https://github.com/madlep)\n- [Warren Seen](https://github.com/warrenseen)\n\n## License\n\n`Rack::ECG` uses MIT license. See\n[`LICENSE.txt`](https://github.com/envato/rack-ecg/blob/main/LICENSE.txt) for\ndetails.\n\n## Code of conduct\n\nWe welcome contribution from everyone. Read more about it in\n[`CODE_OF_CONDUCT.md`](https://github.com/envato/rack-ecg/blob/main/CODE_OF_CONDUCT.md)\n\n## Contributing\n\nFor bug fixes, documentation changes, and small features:\n\n1. Fork it ( https://github.com/[my-github-username]/rack-ecg/fork )\n2. Create your feature branch (git checkout -b my-new-feature)\n3. Commit your changes (git commit -am 'Add some feature')\n4. Push to the branch (git push origin my-new-feature)\n5. Create a new Pull Request\n\nFor larger new features: Do everything as above, but first also make contact with the project maintainers to be sure your change fits with the project direction and you won't be wasting effort going in the wrong direction.\n\n## About\n\nThis project is maintained by the [Envato engineering team][webuild] and funded by [Envato][envato].\n\n[\u003cimg src=\"http://opensource.envato.com/images/envato-oss-readme-logo.png\" alt=\"Envato logo\"\u003e][envato]\n\nEncouraging the use and creation of open source software is one of the ways we serve our community. See [our other projects][oss] or [come work with us][careers] where you'll find an incredibly diverse, intelligent and capable group of people who help make our company succeed and make our workplace fun, friendly and happy.\n\n  [webuild]: http://webuild.envato.com?utm_source=github\n  [envato]: https://envato.com?utm_source=github\n  [oss]: http://opensource.envato.com//?utm_source=github\n  [careers]: http://careers.envato.com/?utm_source=github\n  [gem-page]: https://rubygems.org/gems/rack-ecg\n  [rubydoc]: https://www.rubydoc.info/gems/rack-ecg/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fenvato%2Frack-ecg","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fenvato%2Frack-ecg","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fenvato%2Frack-ecg/lists"}