rails-server-monitor 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +28 -0
- data/Rakefile +7 -0
- data/app/components/rails_server_monitor/leftbar_component.html.erb +20 -0
- data/app/components/rails_server_monitor/leftbar_component.rb +18 -0
- data/app/components/rails_server_monitor/server_table_row.html.erb +6 -0
- data/app/components/rails_server_monitor/server_table_row.rb +11 -0
- data/app/components/rails_server_monitor/warnings/high_cpu_usage_component.html.erb +18 -0
- data/app/components/rails_server_monitor/warnings/high_cpu_usage_component.rb +24 -0
- data/app/components/rails_server_monitor/warnings/low_disk_space_component.html.erb +17 -0
- data/app/components/rails_server_monitor/warnings/low_disk_space_component.rb +28 -0
- data/app/components/rails_server_monitor/warnings/low_memory_component.html.erb +17 -0
- data/app/components/rails_server_monitor/warnings/low_memory_component.rb +28 -0
- data/app/components/rails_server_monitor/warnings/warning_component.html.erb +13 -0
- data/app/components/rails_server_monitor/warnings/warning_component.rb +14 -0
- data/app/controllers/rails_server_monitor/application_controller.rb +6 -0
- data/app/controllers/rails_server_monitor/home_controller.rb +9 -0
- data/app/controllers/rails_server_monitor/servers_controller.rb +22 -0
- data/app/controllers/rails_server_monitor/snapshots_controller.rb +21 -0
- data/app/helpers/rails_server_monitor/application_helper.rb +29 -0
- data/app/javascript/controllers/index.js +9 -0
- data/app/javascript/packs/rails-server-application.js +17 -0
- data/app/javascript/stylesheets/main.scss +1 -0
- data/app/javascript/stylesheets/tailwind.scss +3 -0
- data/app/middlewares/rails_server_monitor/rack_middleware.rb +44 -0
- data/app/middlewares/rails_server_monitor/sidekiq_middleware.rb +29 -0
- data/app/models/rails_server_monitor/application_record.rb +7 -0
- data/app/models/rails_server_monitor/server.rb +27 -0
- data/app/models/rails_server_monitor/server_group.rb +10 -0
- data/app/models/rails_server_monitor/server_snapshot.rb +12 -0
- data/app/services/rails_server_monitor/chart_for_server.rb +51 -0
- data/app/services/rails_server_monitor/cleanup.rb +14 -0
- data/app/services/rails_server_monitor/server_setup.rb +90 -0
- data/app/services/rails_server_monitor/take_snapshot.rb +85 -0
- data/app/views/layouts/rails_server_monitor/application.html.erb +25 -0
- data/app/views/layouts/rails_server_monitor/application_record.rb +7 -0
- data/app/views/rails_server_monitor/home/index.html.erb +18 -0
- data/app/views/rails_server_monitor/servers/show.html.erb +133 -0
- data/app/views/rails_server_monitor/snapshots/show.html.erb +18 -0
- data/config/routes.rb +8 -0
- data/config/webpack/base.js +3 -0
- data/config/webpack/development.js +23 -0
- data/config/webpack/production.js +5 -0
- data/config/webpack/test.js +5 -0
- data/config/webpacker.yml +92 -0
- data/lib/generators/rails_server_monitor/install_generator.rb +20 -0
- data/lib/generators/rails_server_monitor/templates/install.rb.tt +29 -0
- data/lib/rails/server/monitor/engine.rb +3 -0
- data/lib/rails_server_monitor.rb +35 -0
- data/lib/rails_server_monitor/configuration.rb +41 -0
- data/lib/rails_server_monitor/engine.rb +12 -0
- data/lib/rails_server_monitor/version.rb +5 -0
- data/lib/tasks/rails_server_monitor_tasks.rake +24 -0
- metadata +292 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d6ee5dfbcafedea660676e5b93da7179c2fdb0b8dde4860bb9669cc027f4904f
|
4
|
+
data.tar.gz: 19bb6fd06eeca9f55ae678f3f7578c8c9354c83a1c6edf756bea35fa4dc667ca
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0d0b2683477314a18e8546db20889f3696c258e8f8bd6f4e1fe4eb5be320d66b3ef74ee7d4d2df470646dd029199946d3aa8c5b7c42a357767794c2009a5dc5c
|
7
|
+
data.tar.gz: '09124bc1eeadbe2e30c7fe34b253f3f1457064aea4b0c9ef6cf77373d5316177fe8843b86b01c05d82be280920febd2e173ee613f4d5773c2523b93629cf1f7b'
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2021 Personal Social Media
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# Rails::Server::Monitor
|
2
|
+
Short description and motivation.
|
3
|
+
|
4
|
+
## Usage
|
5
|
+
How to use my plugin.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'rails-server-monitor'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
```bash
|
16
|
+
$ bundle
|
17
|
+
```
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
```bash
|
21
|
+
$ gem install rails-server-monitor
|
22
|
+
```
|
23
|
+
|
24
|
+
## Contributing
|
25
|
+
Contribution directions go here.
|
26
|
+
|
27
|
+
## License
|
28
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
<div>
|
2
|
+
<div class="h-4">
|
3
|
+
|
4
|
+
</div>
|
5
|
+
<div class="sticky top-0 ">
|
6
|
+
<%= link_to "Rails Server Monitor", ctx.root_path,
|
7
|
+
class: "bg-blue-500 text-xl text-white p-2 w-full inline-block font-bold shadow-b text-center" %>
|
8
|
+
</div>
|
9
|
+
|
10
|
+
<div>
|
11
|
+
<% if groups.present? %>
|
12
|
+
<% else %>
|
13
|
+
<% servers.each do |server| %>
|
14
|
+
<div class="bg-grey-200 hover:bg-gray-100 my-2 p-1">
|
15
|
+
<%= link_to server.display_name, ctx.server_path(server), class: "w-full inline-block" %>
|
16
|
+
</div>
|
17
|
+
<% end %>
|
18
|
+
<% end %>
|
19
|
+
</div>
|
20
|
+
</div>
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RailsServerMonitor
|
4
|
+
class LeftbarComponent < ViewComponent::Base
|
5
|
+
attr_reader :ctx
|
6
|
+
def initialize(ctx:)
|
7
|
+
@ctx = ctx
|
8
|
+
end
|
9
|
+
|
10
|
+
def groups
|
11
|
+
@groups ||= RailsServerMonitor::ServerGroup.order(name: :asc).all
|
12
|
+
end
|
13
|
+
|
14
|
+
def servers
|
15
|
+
@servers ||= RailsServerMonitor::Server.all.sort_by(&:display_name)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
<div class="bg-gray-200 p-4">
|
2
|
+
<span class="mb-4 text-lg">High CPU Usage</span>
|
3
|
+
|
4
|
+
<div>
|
5
|
+
<% if scope.size == 0 %>
|
6
|
+
<div class="bg-green-500 text-white text-3xl p-4">
|
7
|
+
Everything is ok
|
8
|
+
</div>
|
9
|
+
<% else %>
|
10
|
+
<div class="grid grid-cols-6 gap-4">
|
11
|
+
<% scope.each do |snapshot| %>
|
12
|
+
<%= render(RailsServerMonitor::Warnings::WarningComponent.new(ctx: ctx, snapshot: snapshot,
|
13
|
+
warning: "#{snapshot.cpu_usage_percentage} % CPU USAGE"))%>
|
14
|
+
<% end %>
|
15
|
+
</div>
|
16
|
+
<% end %>
|
17
|
+
</div>
|
18
|
+
</div>
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RailsServerMonitor
|
4
|
+
module Warnings
|
5
|
+
class HighCpuUsageComponent < ViewComponent::Base
|
6
|
+
attr_reader :ctx
|
7
|
+
def initialize(ctx:)
|
8
|
+
@ctx = ctx
|
9
|
+
end
|
10
|
+
|
11
|
+
def scope
|
12
|
+
@scope ||= RailsServerMonitor::ServerSnapshot
|
13
|
+
.includes(:rails_server_monitor_server)
|
14
|
+
.where("cpu_usage_percentage >= ?", config.high_cpu_usage_threshold)
|
15
|
+
.where("created_at > ?", 3.days.ago)
|
16
|
+
.limit(100)
|
17
|
+
end
|
18
|
+
|
19
|
+
def config
|
20
|
+
RailsServerMonitor.config
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
<div class="bg-gray-200 p-4">
|
2
|
+
<span class="mb-4 text-lg">Low disk space</span>
|
3
|
+
|
4
|
+
<div>
|
5
|
+
<% if scope.size == 0 %>
|
6
|
+
<div class="bg-green-500 text-white text-3xl p-4">
|
7
|
+
Everything is ok
|
8
|
+
</div>
|
9
|
+
<% else %>
|
10
|
+
<div class="grid grid-cols-6 gap-4">
|
11
|
+
<% scope.each do |snapshot| %>
|
12
|
+
<%= render(RailsServerMonitor::Warnings::WarningComponent.new(ctx: ctx, snapshot: snapshot, warning: "#{snapshot.hdd_usage_percentage} % STORAGE USED"))%>
|
13
|
+
<% end %>
|
14
|
+
</div>
|
15
|
+
<% end %>
|
16
|
+
</div>
|
17
|
+
</div>
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RailsServerMonitor
|
4
|
+
module Warnings
|
5
|
+
class LowDiskSpaceComponent < ViewComponent::Base
|
6
|
+
attr_reader :ctx
|
7
|
+
def initialize(ctx:)
|
8
|
+
@ctx = ctx
|
9
|
+
end
|
10
|
+
|
11
|
+
def scope
|
12
|
+
@scope ||= RailsServerMonitor::ServerSnapshot
|
13
|
+
.includes(:rails_server_monitor_server)
|
14
|
+
.where("hdd_usage_percentage >= ?", max_space_usage)
|
15
|
+
.where("created_at > ?", 3.days.ago)
|
16
|
+
.limit(100)
|
17
|
+
end
|
18
|
+
|
19
|
+
def config
|
20
|
+
RailsServerMonitor.config
|
21
|
+
end
|
22
|
+
|
23
|
+
def max_space_usage
|
24
|
+
100 - config.low_free_disk_disk_threshold
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
<div class="bg-gray-200 p-4">
|
2
|
+
<span class="mb-4 text-lg">Low memory</span>
|
3
|
+
|
4
|
+
<div>
|
5
|
+
<% if scope.size == 0 %>
|
6
|
+
<div class="bg-green-500 text-white text-3xl p-4">
|
7
|
+
Everything is ok
|
8
|
+
</div>
|
9
|
+
<% else %>
|
10
|
+
<div class="grid grid-cols-6 gap-4">
|
11
|
+
<% scope.each do |snapshot| %>
|
12
|
+
<%= render(RailsServerMonitor::Warnings::WarningComponent.new(ctx: ctx, snapshot: snapshot, warning: "#{snapshot.ram_usage_percentage} % RAM USED"))%>
|
13
|
+
<% end %>
|
14
|
+
</div>
|
15
|
+
<% end %>
|
16
|
+
</div>
|
17
|
+
</div>
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RailsServerMonitor
|
4
|
+
module Warnings
|
5
|
+
class LowMemoryComponent < ViewComponent::Base
|
6
|
+
attr_reader :ctx
|
7
|
+
def initialize(ctx:)
|
8
|
+
@ctx = ctx
|
9
|
+
end
|
10
|
+
|
11
|
+
def scope
|
12
|
+
@scope ||= RailsServerMonitor::ServerSnapshot
|
13
|
+
.includes(:rails_server_monitor_server)
|
14
|
+
.where("ram_usage_percentage >= ?", max_memory_usage)
|
15
|
+
.where("created_at > ?", 3.days.ago)
|
16
|
+
.limit(100)
|
17
|
+
end
|
18
|
+
|
19
|
+
def config
|
20
|
+
RailsServerMonitor.config
|
21
|
+
end
|
22
|
+
|
23
|
+
def max_memory_usage
|
24
|
+
100 - config.low_memory_threshold
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
<%= link_to ctx.snapshot_path(snapshot), class: "bg-red-300 p-1" do %>
|
2
|
+
<div class="text-center text-lg font-bold">
|
3
|
+
<%= snapshot.rails_server_monitor_server.display_name %>
|
4
|
+
</div>
|
5
|
+
|
6
|
+
<div>
|
7
|
+
<%= snapshot.created_at %>
|
8
|
+
</div>
|
9
|
+
|
10
|
+
<div>
|
11
|
+
<%= warning %>
|
12
|
+
</div>
|
13
|
+
<% end %>
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RailsServerMonitor
|
4
|
+
module Warnings
|
5
|
+
class WarningComponent < ViewComponent::Base
|
6
|
+
attr_reader :ctx, :snapshot, :warning
|
7
|
+
def initialize(ctx:, snapshot:, warning:)
|
8
|
+
@ctx = ctx
|
9
|
+
@snapshot = snapshot
|
10
|
+
@warning = warning
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RailsServerMonitor
|
4
|
+
class ServersController < ApplicationController
|
5
|
+
before_action :require_current_server, only: %i(show update)
|
6
|
+
|
7
|
+
def show
|
8
|
+
@server = current_server
|
9
|
+
@chart = RailsServerMonitor::ChartForServer.new(@server)
|
10
|
+
|
11
|
+
@title = @server.display_name
|
12
|
+
end
|
13
|
+
|
14
|
+
def current_server
|
15
|
+
@current_server ||= RailsServerMonitor::Server.find_by(id: params[:id])
|
16
|
+
end
|
17
|
+
|
18
|
+
def require_current_server
|
19
|
+
redirect_to root_path, notice: "Server not found" if current_server.blank?
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RailsServerMonitor
|
4
|
+
class SnapshotsController < ApplicationController
|
5
|
+
before_action :require_current_snapshot, only: :show
|
6
|
+
|
7
|
+
def show
|
8
|
+
@snapshot = current_snapshot
|
9
|
+
|
10
|
+
@title = "Snapshot - #{@snapshot.id}"
|
11
|
+
end
|
12
|
+
|
13
|
+
def current_snapshot
|
14
|
+
@current_snapshot ||= RailsServerMonitor::ServerSnapshot.find_by(id: params[:id])
|
15
|
+
end
|
16
|
+
|
17
|
+
def require_current_snapshot
|
18
|
+
redirect_to root_path, notice: "Server not found" if current_snapshot.blank?
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "webpacker"
|
4
|
+
|
5
|
+
module RailsServerMonitor
|
6
|
+
module ApplicationHelper
|
7
|
+
include ::Webpacker::Helper
|
8
|
+
|
9
|
+
def current_webpacker_instance
|
10
|
+
RailsServerMonitor.webpacker
|
11
|
+
end
|
12
|
+
|
13
|
+
def safe_render_js(name, **options)
|
14
|
+
if respond_to?(:javascript_packs_with_chunks_tag)
|
15
|
+
return javascript_packs_with_chunks_tag(name, **options)
|
16
|
+
end
|
17
|
+
|
18
|
+
javascript_pack_tag(name, **options)
|
19
|
+
end
|
20
|
+
|
21
|
+
def safe_render_css(name, **options)
|
22
|
+
if respond_to?(:javascript_packs_with_chunks_tag)
|
23
|
+
return stylesheet_packs_with_chunks_tag(name, **options)
|
24
|
+
end
|
25
|
+
|
26
|
+
stylesheet_pack_tag(name, **options)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
// Load all the controllers within this directory and all subdirectories.
|
2
|
+
// Controller files must be named *_controller.js.
|
3
|
+
|
4
|
+
import {Application} from 'stimulus';
|
5
|
+
import {definitionsFromContext} from 'stimulus/webpack-helpers';
|
6
|
+
|
7
|
+
const application = Application.start();
|
8
|
+
const context = require.context('controllers', true, /-controller\.js$/);
|
9
|
+
application.load(definitionsFromContext(context));
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import '../stylesheets/main.scss';
|
2
|
+
require('typeface-roboto');
|
3
|
+
import '@fortawesome/fontawesome-free/css/all.css';
|
4
|
+
|
5
|
+
import 'chartkick/chart.js';
|
6
|
+
import Rails from '@rails/ujs';
|
7
|
+
import Turbolinks from 'turbolinks';
|
8
|
+
|
9
|
+
Rails.start();
|
10
|
+
Turbolinks.start();
|
11
|
+
|
12
|
+
import 'controllers';
|
13
|
+
|
14
|
+
// const componentRequireContext = require.context('components', true);
|
15
|
+
// const ReactRailsUJS = require('react_ujs');
|
16
|
+
// ReactRailsUJS.useContext(componentRequireContext); // eslint-disable-line react-hooks/rules-of-hooks
|
17
|
+
// ReactRailsUJS.handleEvent('turbolinks:load', ReactRailsUJS.handleMount);
|
@@ -0,0 +1 @@
|
|
1
|
+
@import "./tailwind";
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RailsServerMonitor
|
4
|
+
class RackMiddleware
|
5
|
+
def initialize(app)
|
6
|
+
@app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
request = ActionDispatch::Request.new(env)
|
11
|
+
return @app.call(request.env) if ignore_request?(request)
|
12
|
+
|
13
|
+
server = RailsServerMonitor::ServerSetup.new.call
|
14
|
+
snapshot = RailsServerMonitor::TakeSnapshot.new(server)
|
15
|
+
|
16
|
+
if snapshot.can_take_snapshot?
|
17
|
+
snapshot.call
|
18
|
+
|
19
|
+
RailsServerMonitor::Cleanup.new.call
|
20
|
+
end
|
21
|
+
|
22
|
+
@app.call(request.env)
|
23
|
+
end
|
24
|
+
|
25
|
+
def ignore_request?(request)
|
26
|
+
return false if config.ignore_urls.blank?
|
27
|
+
|
28
|
+
path = request.path
|
29
|
+
return true if config.ignore_urls.detect do |url|
|
30
|
+
if url.is_a?(String)
|
31
|
+
next path == url
|
32
|
+
elsif url.is_a?(Regexp)
|
33
|
+
next url.match?(path)
|
34
|
+
end
|
35
|
+
end.present?
|
36
|
+
|
37
|
+
false
|
38
|
+
end
|
39
|
+
|
40
|
+
def config
|
41
|
+
RailsServerMonitor.config
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|