Created
December 14, 2019 06:52
-
-
Save julianrubisch/8e8494c08351612ddab42dd102d4b958 to your computer and use it in GitHub Desktop.
Easymon
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/lib/easymon/action_cable_connection_statistics.rb | |
module Easymon | |
class ActionCableConnectionStatistics | |
def check | |
count = ActionCable.server.open_connections_statistics.count | |
status = count < 100 | |
[status, "#{status ? "low" : "high"} - #{count}"] | |
rescue | |
[false, "Down"] | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/initializers/easymon.rb | |
Rails.application.config.after_initialize do | |
load Rails.root.join("app/lib/easymon/sidekiq_queue_size_check.rb") | |
load Rails.root.join("app/lib/easymon/sidekiq_queue_latency_check.rb") | |
load Rails.root.join("app/lib/easymon/action_cable_connection_statistics.rb") | |
end | |
Easymon::Repository.add( | |
"database", | |
Easymon::ActiveRecordCheck.new(ActiveRecord::Base), | |
:critical | |
) | |
Easymon::Repository.add("redis", | |
Easymon::RedisCheck.new( | |
YAML.load( | |
ERB.new( | |
File.read(Rails.root.join("config/cable.yml")) | |
).result | |
)[Rails.env].symbolize_keys | |
)) | |
Easymon::Repository.add( | |
"memcached", | |
Easymon::MemcachedCheck.new(Rails.cache) | |
) | |
Easymon::Repository.add( | |
"sidekiq queue size", | |
Easymon::SidekiqQueueSizeCheck.new | |
) | |
Easymon::Repository.add( | |
"sidekiq queue latency", | |
Easymon::SidekiqQueueLatencyCheck.new | |
) | |
Easymon::Repository.add( | |
"action cable connections", | |
Easymon::ActionCableConnectionStatistics.new | |
) | |
Easymon::Repository.add( | |
"metabase", | |
Easymon::HttpCheck.new("https://metabase.codefund.io") | |
) | |
Easymon::Repository.add( | |
"wordpress", | |
Easymon::HttpCheck.new("https://codefund.io") | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/controllers/health_controller.rb | |
class HealthController < ApplicationController | |
def index | |
checklist = Easymon::Repository.all | |
checklist.check | |
@results = [] | |
checklist.results.each do |key, value| | |
@results << OpenStruct.new(name: key.titleize, success: value.success, message: value.message) | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/views/health/index.html.erb | |
<%= render "/shared/index_layout", | |
title: "Health", | |
sidebar: false do %> | |
<div class="grid grid-tcolumns-200"> | |
<% @results.each do |result| %> | |
<div class="metric metric-bordered"> | |
<h2 class="metric-label"> <%= result.name %> </h2> | |
<p class="metric-value h2"> | |
<sup><%= result.success ? "✔️" : "✖️" %></sup> <span class="value"><%= result.message %></span> | |
</p> | |
</div> | |
<% end %> | |
</div> | |
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/routes.rb | |
resources :health, only: [:index] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/lib/easymon/sidekiq_queue_latency_check.rb | |
module Easymon | |
class SidekiqQueueLatencyCheck | |
def check | |
latency = Sidekiq::Queue.new.latency | |
status = latency < 30 | |
[status, "#{status ? "ok" : "not-ok"} - #{latency}"] | |
rescue | |
[false, "Down"] | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/lib/easymon/sidekiq_queue_size_check.rb | |
module Easymon | |
class SidekiqQueueSizeCheck | |
def check | |
length = Sidekiq::Queue.all.sum(&:size) | |
status = length < 25_000 | |
[status, "#{status ? "low" : "high"} - #{length}"] | |
rescue | |
[false, "Down"] | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks to @andrewmcodes 🙌