{"id":18513344,"url":"https://github.com/jbox-web/health_monitor","last_synced_at":"2025-04-09T06:33:11.735Z","repository":{"id":146101276,"uuid":"169171597","full_name":"jbox-web/health_monitor","owner":"jbox-web","description":" A Rails plugin which provides a health checking and monitoring API of various services and application aspects","archived":false,"fork":false,"pushed_at":"2024-09-06T16:15:31.000Z","size":425,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-09-06T19:28:50.652Z","etag":null,"topics":["monitoring","rails","ruby"],"latest_commit_sha":null,"homepage":"","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/jbox-web.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"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":"2019-02-05T00:36:56.000Z","updated_at":"2024-09-06T16:15:34.000Z","dependencies_parsed_at":"2023-12-15T02:05:00.629Z","dependency_job_id":"71f1f681-603a-4749-96ab-6133663b3807","html_url":"https://github.com/jbox-web/health_monitor","commit_stats":null,"previous_names":[],"tags_count":65,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jbox-web%2Fhealth_monitor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jbox-web%2Fhealth_monitor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jbox-web%2Fhealth_monitor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jbox-web%2Fhealth_monitor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jbox-web","download_url":"https://codeload.github.com/jbox-web/health_monitor/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223367281,"owners_count":17134070,"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":["monitoring","rails","ruby"],"created_at":"2024-11-06T15:37:45.895Z","updated_at":"2024-11-06T15:37:46.627Z","avatar_url":"https://github.com/jbox-web.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# HealthMonitor\n\n[![GitHub license](https://img.shields.io/github/license/jbox-web/health_monitor.svg)](https://github.com/jbox-web/health_monitor/blob/master/LICENSE)\n[![GitHub release](https://img.shields.io/github/release/jbox-web/health_monitor.svg)](https://github.com/jbox-web/health_monitor/releases/latest)\n[![CI](https://github.com/jbox-web/health_monitor/workflows/CI/badge.svg)](https://github.com/jbox-web/health_monitor/actions)\n[![Code Climate](https://codeclimate.com/github/jbox-web/health_monitor/badges/gpa.svg)](https://codeclimate.com/github/jbox-web/health_monitor)\n[![Test Coverage](https://codeclimate.com/github/jbox-web/health_monitor/badges/coverage.svg)](https://codeclimate.com/github/jbox-web/health_monitor/coverage)\n\nThis is a health monitoring Rails mountable plug-in, which checks various services (db, cache, sidekiq, redis, etc.).\n\nMounting this gem will add a '/check' route to your application, which can be used for health monitoring the application and its various services. The method will return an appropriate HTTP status as well as an HTML/JSON/XML response representing the state of each provider.\n\nYou can filter which checks to run by passing a parameter called ```providers```.\n\n## Examples\n\n### HTML Status Page\n\n![alt example](/docs/screenshots/example.png \"HTML Status Page\")\n\n### JSON Response\n\n```bash\n\u003e\u003e curl -s http://localhost:3000/check.json | json_pp\n```\n\n```json\n{\n   \"timestamp\" : \"2017-03-10 17:07:52 +0200\",\n   \"status\" : \"ok\",\n   \"results\" : [\n      {\n         \"name\" : \"Database\",\n         \"message\" : \"\",\n         \"status\" : \"OK\"\n      },\n      {\n         \"status\" : \"OK\",\n         \"message\" : \"\",\n         \"name\" : \"Cache\"\n      },\n      {\n         \"status\" : \"OK\",\n         \"message\" : \"\",\n         \"name\" : \"Redis\"\n      },\n      {\n         \"status\" : \"OK\",\n         \"message\" : \"\",\n         \"name\" : \"Sidekiq\"\n      }\n   ]\n}\n```\n\n### Filtered JSON Response\n\n```bash\n\u003e\u003e curl -s http://localhost:3000/check.json?providers[]=database\u0026providers[]=redis | json_pp\n```\n\n```json\n{\n   \"timestamp\" : \"2017-03-10 17:07:52 +0200\",\n   \"status\" : \"ok\",\n   \"results\" : [\n      {\n         \"name\" : \"Database\",\n         \"message\" : \"\",\n         \"status\" : \"OK\"\n      },\n      {\n         \"status\" : \"OK\",\n         \"message\" : \"\",\n         \"name\" : \"Redis\"\n      },\n   ]\n}\n```\n\n### XML Response\n\n```bash\n\u003e\u003e curl -s http://localhost:3000/check.xml\n```\n\n```xml\n\u003c?xml version=\"1.0\" encoding=\"UTF-8\"?\u003e\n\u003chash\u003e\n  \u003cresults type=\"array\"\u003e\n    \u003cresult\u003e\n      \u003cname\u003eDatabase\u003c/name\u003e\n      \u003cmessage\u003e\u003c/message\u003e\n      \u003cstatus\u003eOK\u003c/status\u003e\n    \u003c/result\u003e\n    \u003cresult\u003e\n      \u003cname\u003eCache\u003c/name\u003e\n      \u003cmessage\u003e\u003c/message\u003e\n      \u003cstatus\u003eOK\u003c/status\u003e\n    \u003c/result\u003e\n    \u003cresult\u003e\n      \u003cname\u003eRedis\u003c/name\u003e\n      \u003cmessage\u003e\u003c/message\u003e\n      \u003cstatus\u003eOK\u003c/status\u003e\n    \u003c/result\u003e\n    \u003cresult\u003e\n      \u003cname\u003eSidekiq\u003c/name\u003e\n      \u003cmessage\u003e\u003c/message\u003e\n      \u003cstatus\u003eOK\u003c/status\u003e\n    \u003c/result\u003e\n  \u003c/results\u003e\n  \u003cstatus type=\"symbol\"\u003eok\u003c/status\u003e\n  \u003ctimestamp\u003e2017-03-10 17:08:50 +0200\u003c/timestamp\u003e\n\u003c/hash\u003e\n```\n\n### Filtered XML Response\n\n```bash\n\u003e\u003e curl -s http://localhost:3000/check.xml?providers[]=database\u0026providers[]=redis\n```\n\n```xml\n\u003c?xml version=\"1.0\" encoding=\"UTF-8\"?\u003e\n\u003chash\u003e\n  \u003cresults type=\"array\"\u003e\n    \u003cresult\u003e\n      \u003cname\u003eDatabase\u003c/name\u003e\n      \u003cmessage\u003e\u003c/message\u003e\n      \u003cstatus\u003eOK\u003c/status\u003e\n    \u003c/result\u003e\n    \u003cresult\u003e\n      \u003cname\u003eRedis\u003c/name\u003e\n      \u003cmessage\u003e\u003c/message\u003e\n      \u003cstatus\u003eOK\u003c/status\u003e\n    \u003c/result\u003e\n  \u003c/results\u003e\n  \u003cstatus type=\"symbol\"\u003eok\u003c/status\u003e\n  \u003ctimestamp\u003e2017-03-10 17:08:50 +0200\u003c/timestamp\u003e\n\u003c/hash\u003e\n```\n\n## Installation\n\nPut this in your `Gemfile` :\n\n```ruby\ngit_source(:github){ |repo_name| \"https://github.com/#{repo_name}.git\" }\n\ngem 'health_monitor', github: 'jbox-web/health_monitor', tag: '8.6.0'\n```\n\nthen run `bundle install`.\n\n## Usage\nYou can mount this inside your app routes by adding this to config/routes.rb:\n\n```ruby\nmount HealthMonitor::Engine, at: '/check'\n```\n\n## Supported Service Providers\nThe following services are currently supported:\n* DB\n* Cache\n* Redis\n* Sidekiq\n* Resque\n\n## Configuration\n\n### Adding Providers\nBy default, only the database check is enabled. You can add more service providers by explicitly enabling them via an initializer:\n\n```ruby\nHealthMonitor.configure do |config|\n  config.cache\n  config.redis\n  config.sidekiq\nend\n```\n\nWe believe that having the database check enabled by default is very important, but if you still want to disable it\n(e.g., if you use a database that isn't covered by the check) - you can do that by calling the `no_database` method:\n\n```ruby\nHealthMonitor.configure do |config|\n  config.no_database\nend\n```\n\n### Provider Configuration\n\nSome of the providers can also accept additional configuration:\n\n```ruby\n# Sidekiq\nHealthMonitor.configure do |config|\n  config.sidekiq.configure do |sidekiq_config|\n    sidekiq_config.latency = 3.hours\n    sidekiq_config.queue_size = 50\n  end\nend\n\n# To configure specific queues\nHealthMonitor.configure do |config|\n  config.sidekiq.configure do |sidekiq_config|\n    sidekiq_config.add_queue_configuration(\"critical\", latency: 10.seconds, size: 20)\n  end\nend\n\n```\n\n```ruby\n# Redis\nHealthMonitor.configure do |config|\n  config.redis.configure do |redis_config|\n    redis_config.connection = Redis.current # use your custom redis connection\n    redis_config.url = 'redis://user:pass@example.redis.com:90210/' # or URL\n    redis_config.max_used_memory = 200 # Megabytes\n  end\nend\n```\n\nThe currently supported settings are:\n\n#### Sidekiq\n\n* `latency`: the latency (in seconds) of a queue (now - when the oldest job was enqueued) which is considered unhealthy (the default is 30 seconds, but larger processing queue should have a larger latency value).\n* `queue_size`: the size (maximim) of a queue which is considered unhealthy (the default is 100).\n\n#### Redis\n\n* `url`: the url used to connect to your Redis instance - note, this is an optional configuration and will use the default connection if not specified\n* `connection`: Use custom redis connection (e.g., `Redis.current`).\n* `max_used_memory`: Set maximum expected memory usage of Redis in megabytes. Prevent memory leaks and keys overstore.\n\n#### Delayed Job\n\n* `queue_size`: the size (maximim) of a queue which is considered unhealthy (the default is 100).\n\n### Adding a Custom Provider\nIt's also possible to add custom health check providers suited for your needs (of course, it's highly appreciated and encouraged if you'd contribute useful providers to the project).\n\nIn order to add a custom provider, you'd need to:\n\n* Implement the `HealthMonitor::Providers::Base` class and its `check!` method (a check is considered as failed if it raises an exception):\n\n```ruby\nclass CustomProvider \u003c HealthMonitor::Providers::Base\n  def check!\n    raise 'Oh oh!'\n  end\nend\n```\n* Add its class to the configuration:\n\n```ruby\nHealthMonitor.configure do |config|\n  config.add_custom_provider(CustomProvider)\nend\n```\n\n### Adding a Custom Error Callback\nIf you need to perform any additional error handling (for example, for additional error reporting), you can configure a custom error callback:\n\n```ruby\nHealthMonitor.configure do |config|\n  config.error_callback = proc do |e|\n    logger.error \"Health check failed with: #{e.message}\"\n\n    Raven.capture_exception(e)\n  end\nend\n```\n\n### Adding Authentication Credentials\nBy default, the `/check` endpoint is not authenticated and is available to any user. You can authenticate using HTTP Basic Auth by providing authentication credentials:\n\n```ruby\nHealthMonitor.configure do |config|\n  config.basic_auth_credentials = {\n    username: 'SECRET_NAME',\n    password: 'Shhhhh!!!'\n  }\nend\n```\n\n### Adding Environment Variables\nBy default, environment variables is `nil`, so if you'd want to include additional parameters in the results JSON, all you need is to provide a `Hash` with your custom environment variables:\n\n```ruby\nHealthMonitor.configure do |config|\n  config.environment_variables = {\n    build_number: 'BUILD_NUMBER',\n    git_sha: 'GIT_SHA'\n  }\nend\n```\n\n### Monitoring Script\n\nA Nagios/Shinken/Icinga/Icinga2 plugin is available in `extra` directory.\n\nIt takes one argument : `-u` or `--uri`\n\n```sh\nnicolas@desktop:$ ./check_rails.rb\nmissing argument: uri\n\nUsage: check_rails.rb -u uri\n    -u, --uri URI                    The URI to check (https://nagios:nagios@example.com/check.json)\n\nCommon options:\n    -v, --version                    Displays Version\n    -h, --help                       Displays Help\n```\n\nAnd it generates an output with the right status code for your monitoring system :\n\n```sh\nnicolas@desktop:$ ./check_rails.rb -u http://admin:admin@localhost:5000/check.json\nRails application : OK\n\nDatabase : OK\nCache : OK\nRedis : OK\nSidekiq : OK\n\nnicolas@desktop:$ echo $?\n0\n```\n\n```sh\nnicolas@desktop:$ ./check_rails.rb -u http://admin:admin@localhost:5000/check.json\nRails application : ERROR\n\nDatabase : OK\nCache : OK\nRedis : ERROR (Error connecting to Redis on 127.0.0.1:6379 (Errno::ECONNREFUSED))\nSidekiq : ERROR (Error connecting to Redis on 127.0.0.1:6379 (Errno::ECONNREFUSED))\n\nnicolas@desktop:$ echo $?\n2\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjbox-web%2Fhealth_monitor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjbox-web%2Fhealth_monitor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjbox-web%2Fhealth_monitor/lists"}