TODO.
Add this line to your application's Gemfile:
gem 'ez-status'
And then execute:
$ bundle install
Run rails generator for easy config setup:
$ rails generate ez:status:install
You can mount this inside your app routes by adding this to config/routes.rb
:
mount Ez::Status::Engine, at: '/status'
Configuration interface allows you to change default behavior
# config/initializers/ez_status.rb
require 'ez/status/providers/database'
require 'ez/status/providers/cache'
# require 'ez/status/providers/delayed_job'
# require 'ez/status/providers/redis'
# require 'ez/status/providers/sidekiq'
# class MyCustomProvider
# def check
# uri = URI.parse('http://www.google.com/')
# request = Net::HTTP::Get.new(uri)
# req_options = {
# use_ssl: uri.scheme == 'https',
# }
#
# response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
# http.request(request)
# end
# [response.code == '200', response.message, response.code]
# rescue StandardError => e
# [false, e.message]
# end
# end
Ez::Status.configure do |config|
# Define your base controller and routes
config.status_base_controller = 'ApplicationController'
config.status_base_routes = '/status'
# config.layout = 'layouts/application'
# config.ui_header = 'MyStatus'
# config.basic_auth_credentials = {
# username: 'MyUsername',
# password: 'MyPassword'
# }
config.monitors = [
Ez::Status::Providers::Database,
Ez::Status::Providers::Cache,
# Ez::Status::Providers::DelayedJob,
# Ez::Status::Providers::Redis,
# Ez::Status::Providers::Sidekiq,
# MyCustomProvider
]
end
Ez::Status.configure do |config|
config.basic_auth_credentials = {
username: 'MyUsername',
password: 'MyPassword'
}
end
Ez::Status.configure do |config|
config.ui_header = 'My Header'
end
class MyCustomProvider
def check
uri = URI.parse('http://www.google.com/')
request = Net::HTTP::Get.new(uri)
req_options = {
use_ssl: uri.scheme == 'https',
}
response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
http.request(request)
end
[response.code == '200', response.message, response.code]
rescue StandardError => e
[false, e.message]
end
end
Ez::Status.configure do |config|
config.monitors = [
MyCustomProvider
]
end
### HTML version
TODO: HTML page screenshot here
## JSON version
```json
{
"todo": "todo"
}
Custom provider, it's just a simple ruby PORO. You don't need to use any custom inheritance or include modules.
Just create your own class with 1 public method run!
and raise an exception in case of failure or return anything else as success message.
class MyCustomProvider
def check
raise 'Oops!' if false
'OK'
end
end
Volodya Sveredyuk, Telegram Channel: SveredyukCast
Vasyl Shevchenko, GitHub: VasylShevchenko
The gem is available as open source under the terms of the MIT License.