rails-server-monitor 0.1.8 → 0.1.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +115 -14
- data/app/controllers/rails_server_monitor/servers_controller.rb +10 -1
- data/app/helpers/rails_server_monitor/application_helper.rb +4 -0
- data/app/models/rails_server_monitor/server.rb +6 -0
- data/app/services/rails_server_monitor/chart_for_server.rb +10 -4
- data/app/services/rails_server_monitor/server_setup.rb +1 -1
- data/app/views/layouts/rails_server_monitor/application.html.erb +13 -8
- data/app/views/rails_server_monitor/page/_footer.html.erb +8 -0
- data/app/views/rails_server_monitor/servers/show.html.erb +10 -9
- data/app/views/rails_server_monitor/servers/show/_chart.html.erb +10 -0
- data/lib/rails_server_monitor/compile_locally.rb +26 -0
- data/lib/rails_server_monitor/configuration.rb +6 -2
- data/lib/rails_server_monitor/version.rb +1 -1
- data/lib/rubygems_plugin.rb +5 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3e47312d01c09679dc3df5b1b4d042bd7a7d7d0290d55902d7fe4ef8dd6e7a22
|
4
|
+
data.tar.gz: b30f2db395c5c25eeae2ffd1fa639aa8f277c35d25d0fd6a3fbeacdeda662dcc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e2b2ad6e4df19eb305bfe9f02e4d1d4034519acdd70d0558960e2d7bcc55e16acccb8ff12dd51639d76927e2ae16cde848f76d62031581145061a556304672cb
|
7
|
+
data.tar.gz: 446a671e8cd3918173c10f82ad5f8f63364224fb05559e860e4fdbcfc758352ef44c28f6ea2edcb8a26e60b761f22b4c9a424a8269d40e94b7678130bcb411b0
|
data/README.md
CHANGED
@@ -1,28 +1,129 @@
|
|
1
|
-
# Rails
|
2
|
-
|
1
|
+
# Rails Server Monitor
|
2
|
+
A performance dashboard for rails applications which work with one or multiple servers at once.
|
3
|
+
Stats can be collected from a Rack application or Sidekiq.
|
3
4
|
|
4
|
-
|
5
|
-
How to use my plugin.
|
5
|
+
[See it in action](https://rails-sever-monitor.herokuapp.com)
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
![demo](https://github.com/personal-social-media/rails-server-monitor/raw/master/resources/screenshot.jpg)
|
8
|
+
![demo](https://github.com/personal-social-media/rails-server-monitor/raw/master/resources/screenshot1.jpg)
|
9
9
|
|
10
|
+
## Usage
|
11
|
+
#### 1)
|
10
12
|
```ruby
|
11
|
-
gem 'rails-server-monitor'
|
13
|
+
gem 'rails-server-monitor', require: "rails_server_monitor"
|
12
14
|
```
|
13
15
|
|
14
|
-
|
16
|
+
#### 2) generate Rails Server Monitor tables
|
15
17
|
```bash
|
16
|
-
|
18
|
+
rails g rails_server_monitor:install
|
19
|
+
rails db:migrate
|
17
20
|
```
|
18
21
|
|
19
|
-
|
20
|
-
```
|
21
|
-
|
22
|
+
#### 3) hook Rails Server Monitor's rack middleware
|
23
|
+
```shell
|
24
|
+
# inside config/application.rb
|
25
|
+
config.middleware.use RailsServerMonitor::RackMiddleware
|
26
|
+
```
|
27
|
+
|
28
|
+
#### 4) compile Rails Server Monitor assets locally
|
29
|
+
if you aren't using webpacker already
|
30
|
+
```shell
|
31
|
+
# you don't need to do this in production, it's prepended to rake assets:precompile
|
32
|
+
# but you need to do it again after you after you update the gem locally
|
33
|
+
rake webpacker:compile
|
34
|
+
|
35
|
+
or if you are using
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
# inside bin/webpack-dev-server
|
39
|
+
require "rails_server_monitor/compile_locally"
|
40
|
+
RailsServerMonitor::CompileLocally.compile
|
41
|
+
|
42
|
+
# insert before this before
|
43
|
+
# Dir.chdir(APP_ROOT) do
|
44
|
+
# Webpacker::DevServerRunner.run(ARGV)
|
45
|
+
# end
|
46
|
+
```
|
47
|
+
|
48
|
+
#### 5) (Optional) configure gem
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
# inside config/initializers/rails_server_monitor
|
52
|
+
|
53
|
+
RailsServerMonitor.config do |c|
|
54
|
+
c.update_server_interval = 1.hour
|
55
|
+
c.snapshot_server_interval = 15.minutes
|
56
|
+
c.cleanup_snapshots_after = 90.days
|
57
|
+
c.ignore_workers = %w(MyIgnoredWorker)
|
58
|
+
c.ignore_urls = ["/", /ignored-url/]
|
59
|
+
|
60
|
+
c.high_cpu_usage_threshold = 95
|
61
|
+
c.low_memory_threshold = 20
|
62
|
+
c.low_free_disk_disk_threshold = 30
|
63
|
+
c.hostname = -> do
|
64
|
+
`hostname`
|
65
|
+
end # how to retrieve server hostname, heroku generates a hostname each time your app reboots
|
66
|
+
end
|
67
|
+
```
|
68
|
+
|
69
|
+
#### 6) Mount engine to routes
|
70
|
+
|
71
|
+
```ruby
|
72
|
+
# inside config/routes.rb
|
73
|
+
constraints LoggedInAsAdmin do
|
74
|
+
mount RailsServerMonitor::Engine => "/system-information"
|
75
|
+
end
|
76
|
+
```
|
77
|
+
|
78
|
+
Your should define a constraint to protect against unauthorized access
|
79
|
+
|
80
|
+
```ruby
|
81
|
+
# example LoggedInAsAdmin, this is a basic implementation
|
82
|
+
|
83
|
+
class LoggedInAsAdmin
|
84
|
+
def self.matches?(request)
|
85
|
+
AdminUser.find_by(id: request.session[:admin_id]).present?
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
|
22
90
|
```
|
23
91
|
|
92
|
+
#### 7) (Optional) Add sidekiq middleware
|
93
|
+
|
94
|
+
```ruby
|
95
|
+
# append to config/sidekiq.rb
|
96
|
+
|
97
|
+
Sidekiq.configure_server do |config|
|
98
|
+
config.server_middleware do |chain|
|
99
|
+
chain.add RailsServerMonitor::SidekiqMiddleware
|
100
|
+
end
|
101
|
+
end
|
102
|
+
```
|
103
|
+
|
104
|
+
### 8) Result
|
105
|
+
|
106
|
+
you should now go to http://localhost:3000/system-information
|
107
|
+
|
24
108
|
## Contributing
|
25
|
-
|
109
|
+
|
110
|
+
Everyone is encouraged to help improve this project. Here are a few ways you can help:
|
111
|
+
|
112
|
+
- [Report bugs](https://github.com/personal-social-media/rails-server-monitor/issues)
|
113
|
+
- Fix bugs and [submit pull requests](https://github.com/personal-social-media/rails-server-monitor/pulls)
|
114
|
+
- Write, clarify, or fix documentation
|
115
|
+
- Suggest or add new features
|
116
|
+
|
117
|
+
### Development
|
118
|
+
|
119
|
+
```shell
|
120
|
+
# fork project, clone
|
121
|
+
bundle install
|
122
|
+
yarn install
|
123
|
+
|
124
|
+
bin/start # to start local server
|
125
|
+
bin/rspec # to run specs
|
126
|
+
```
|
26
127
|
|
27
128
|
## License
|
28
|
-
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
129
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
@@ -6,11 +6,20 @@ module RailsServerMonitor
|
|
6
6
|
|
7
7
|
def show
|
8
8
|
@server = current_server
|
9
|
-
@chart = RailsServerMonitor::ChartForServer.new(@server)
|
9
|
+
@chart = RailsServerMonitor::ChartForServer.new(@server, timeline: params[:timeline])
|
10
10
|
|
11
11
|
@title = @server.display_name
|
12
12
|
end
|
13
13
|
|
14
|
+
def update
|
15
|
+
update_params = params.require(:server).permit(:custom_name, :custom_description)
|
16
|
+
current_server.update!(update_params)
|
17
|
+
redirect_to server_path(current_server)
|
18
|
+
|
19
|
+
rescue ActiveRecord::RecordInvalid => e
|
20
|
+
render json: { error: e.message }, status: 422
|
21
|
+
end
|
22
|
+
|
14
23
|
def current_server
|
15
24
|
@current_server ||= RailsServerMonitor::Server.find_by(id: params[:id])
|
16
25
|
end
|
@@ -20,8 +20,14 @@ module RailsServerMonitor
|
|
20
20
|
foreign_key: :rails_server_monitor_server_id,
|
21
21
|
dependent: :delete_all
|
22
22
|
|
23
|
+
before_save :squish_text
|
24
|
+
|
23
25
|
def display_name
|
24
26
|
@display_name ||= custom_name.present? ? custom_name : hostname
|
25
27
|
end
|
28
|
+
|
29
|
+
def squish_text
|
30
|
+
self.custom_name = self.custom_name&.squish
|
31
|
+
end
|
26
32
|
end
|
27
33
|
end
|
@@ -2,10 +2,11 @@
|
|
2
2
|
|
3
3
|
module RailsServerMonitor
|
4
4
|
class ChartForServer
|
5
|
+
AVAILABLE_TIMELINES = %w(today week month all)
|
5
6
|
attr_reader :server, :timeline
|
6
|
-
def initialize(server, timeline:
|
7
|
+
def initialize(server, timeline:)
|
7
8
|
@server = server
|
8
|
-
@timeline = timeline
|
9
|
+
@timeline = timeline.blank? ? "today" : timeline
|
9
10
|
end
|
10
11
|
|
11
12
|
def render_chart
|
@@ -23,10 +24,9 @@ module RailsServerMonitor
|
|
23
24
|
end
|
24
25
|
|
25
26
|
def today?
|
26
|
-
timeline ==
|
27
|
+
timeline == "today"
|
27
28
|
end
|
28
29
|
|
29
|
-
|
30
30
|
def last_record
|
31
31
|
@last_record = scope.last
|
32
32
|
end
|
@@ -36,6 +36,12 @@ module RailsServerMonitor
|
|
36
36
|
query = server.server_snapshots.order(id: :asc)
|
37
37
|
if today?
|
38
38
|
query = query.where("created_at > ?", 1.day.ago)
|
39
|
+
elsif timeline == "week"
|
40
|
+
query = query.where("created_at > ?", 7.day.ago)
|
41
|
+
elsif timeline == "month"
|
42
|
+
query = query.where("created_at > ?", 30.day.ago)
|
43
|
+
else
|
44
|
+
query = query.all
|
39
45
|
end
|
40
46
|
@scope = query.to_a
|
41
47
|
end
|
@@ -9,17 +9,22 @@
|
|
9
9
|
<%= safe_render_css "rails-server-application", 'data-turbolinks-track': "reload" %>
|
10
10
|
</head>
|
11
11
|
<body>
|
12
|
+
<div class="flex min-h-screen flex-col justify-between">
|
13
|
+
<div class="flex">
|
14
|
+
<div class="overflow-y-auto fixed top-0 left-0 bottom-0 bg-white w-1/5">
|
15
|
+
<%= render RailsServerMonitor::LeftbarComponent.new(ctx: self) %>
|
16
|
+
</div>
|
17
|
+
<div class="w-1/5 mr-4"></div>
|
12
18
|
|
13
|
-
<div class="flex">
|
14
|
-
|
15
|
-
|
16
|
-
</div>
|
17
|
-
<div class="w-1/5 mr-4"></div>
|
19
|
+
<div class="flex-1">
|
20
|
+
<%= yield %>
|
21
|
+
</div>
|
18
22
|
|
19
|
-
|
20
|
-
|
23
|
+
</div>
|
24
|
+
<div class="p-4 flex">
|
25
|
+
<div class="w-1/5 mr-4"></div>
|
26
|
+
<%= render "rails_server_monitor/page/footer" %>
|
21
27
|
</div>
|
22
28
|
</div>
|
23
|
-
|
24
29
|
</body>
|
25
30
|
</html>
|
@@ -0,0 +1,8 @@
|
|
1
|
+
<div class="flex-1">
|
2
|
+
<a href="https://github.com/personal-social-media/rails-server-monitor" target="_blank" class="flex items-center mx-auto w-1/4">
|
3
|
+
<i class="fab fa-github fa-3x"></i>
|
4
|
+
<span class="ml-2">
|
5
|
+
Rails Server Monitor V<%= server_version %>
|
6
|
+
</span>
|
7
|
+
</a>
|
8
|
+
</div>
|
@@ -3,11 +3,8 @@
|
|
3
3
|
<%= @server.display_name %>
|
4
4
|
</div>
|
5
5
|
|
6
|
-
|
7
6
|
<div class="flex mt-4">
|
8
|
-
<%=
|
9
|
-
<%= line_chart @chart.render_chart %>
|
10
|
-
<% end %>
|
7
|
+
<%= render(partial: "rails_server_monitor/servers/show/chart") %>
|
11
8
|
|
12
9
|
<% if @chart.today? && @chart.last_record.present? %>
|
13
10
|
<div class="w-1/2 p-2">
|
@@ -49,7 +46,7 @@
|
|
49
46
|
<% end %>
|
50
47
|
</div>
|
51
48
|
|
52
|
-
|
49
|
+
<%= form_with model: @server, html: { class: "mt-20" } do |f| %>
|
53
50
|
<div class="mb-2 text-xl">
|
54
51
|
Sever information:
|
55
52
|
</div>
|
@@ -64,13 +61,13 @@
|
|
64
61
|
Custom name:
|
65
62
|
</div>
|
66
63
|
<div class="p-1">
|
67
|
-
<%=
|
64
|
+
<%= f.text_field :custom_name, class: "border border-solid border-gray-200 p-2 focus:border-gray-300 w-full" %>
|
68
65
|
</div>
|
69
66
|
<div class="bg-blue-300 text-gray-800 p-1">
|
70
67
|
Custom description:
|
71
68
|
</div>
|
72
69
|
<div class="p-1">
|
73
|
-
<%=
|
70
|
+
<%= f.text_area :custom_description, class: "border border-solid border-gray-200 p-2 focus:border-gray-300 w-full" %>
|
74
71
|
</div>
|
75
72
|
<div class="mb-2 text-xl">
|
76
73
|
OS information
|
@@ -110,7 +107,7 @@
|
|
110
107
|
)) %>
|
111
108
|
|
112
109
|
<%= render(RailsServerMonitor::ServerTableRow.new(
|
113
|
-
title: "CPU
|
110
|
+
title: "CPU Cores",
|
114
111
|
value: @server.system_cpu_cores
|
115
112
|
)) %>
|
116
113
|
|
@@ -129,5 +126,9 @@
|
|
129
126
|
value: "#{@server.system_hdd_available_in_gb} GB"
|
130
127
|
)) %>
|
131
128
|
</div>
|
132
|
-
|
129
|
+
|
130
|
+
<div class="mt-20 w-1/2">
|
131
|
+
<%= f.submit "Save custom information", class: "p-2 w-full bg-blue-500 text-white" %>
|
132
|
+
</div>
|
133
|
+
<% end %>
|
133
134
|
</div>
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<%= content_tag :div, class: "#{@chart.today? ? "w-1/2" : "w-full"}" do %>
|
2
|
+
<%= line_chart @chart.render_chart %>
|
3
|
+
|
4
|
+
<div class="flex justify-between">
|
5
|
+
<% RailsServerMonitor::ChartForServer::AVAILABLE_TIMELINES.each do |timeline| %>
|
6
|
+
<%= link_to timeline.humanize, server_path(@server, timeline: timeline),
|
7
|
+
class: "#{@chart.timeline == timeline ? "bg-blue-500 text-white" : "bg-gray-300 text-gray-800" } p-2 rounded hover:bg-blue-400" %>
|
8
|
+
<% end %>
|
9
|
+
</div>
|
10
|
+
<% end %>
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rails"
|
4
|
+
require_relative "./engine"
|
5
|
+
module RailsServerMonitor
|
6
|
+
class CompileLocally
|
7
|
+
class << self
|
8
|
+
def compile
|
9
|
+
new.compile(skip_check: true)
|
10
|
+
end
|
11
|
+
|
12
|
+
def compile_force
|
13
|
+
new.compile(skip_check: false)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def compile(skip_check:)
|
18
|
+
unless skip_check
|
19
|
+
return unless Rails.env.development? || Rails.env.test?
|
20
|
+
end
|
21
|
+
return if Dir.exist?(RailsServerMonitor::Engine.root.join("public", "rails-server-monitor-packs"))
|
22
|
+
|
23
|
+
RailsServerMonitor.webpacker.commands.compile
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -4,7 +4,7 @@ module RailsServerMonitor
|
|
4
4
|
class Configuration
|
5
5
|
attr_writer :update_server_interval, :snapshot_server_interval, :ignore_urls,
|
6
6
|
:cleanup_snapshots_after, :ignore_workers, :high_cpu_usage_threshold,
|
7
|
-
:low_memory_threshold, :low_free_disk_disk_threshold
|
7
|
+
:low_memory_threshold, :low_free_disk_disk_threshold, :hostname
|
8
8
|
|
9
9
|
def update_server_interval
|
10
10
|
@update_server_interval || 1.hour
|
@@ -15,7 +15,7 @@ module RailsServerMonitor
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def cleanup_snapshots_after
|
18
|
-
@cleanup_snapshots_after ||
|
18
|
+
@cleanup_snapshots_after || 90.days
|
19
19
|
end
|
20
20
|
|
21
21
|
def ignore_urls
|
@@ -37,5 +37,9 @@ module RailsServerMonitor
|
|
37
37
|
def low_free_disk_disk_threshold
|
38
38
|
@low_free_disk_disk_threshold || 30
|
39
39
|
end
|
40
|
+
|
41
|
+
def hostname
|
42
|
+
-> { `hostname` }
|
43
|
+
end
|
40
44
|
end
|
41
45
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-server-monitor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Personal Social Media
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-06-
|
11
|
+
date: 2021-06-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec-rails
|
@@ -246,7 +246,9 @@ files:
|
|
246
246
|
- app/views/layouts/rails_server_monitor/application.html.erb
|
247
247
|
- app/views/layouts/rails_server_monitor/application_record.rb
|
248
248
|
- app/views/rails_server_monitor/home/index.html.erb
|
249
|
+
- app/views/rails_server_monitor/page/_footer.html.erb
|
249
250
|
- app/views/rails_server_monitor/servers/show.html.erb
|
251
|
+
- app/views/rails_server_monitor/servers/show/_chart.html.erb
|
250
252
|
- app/views/rails_server_monitor/snapshots/show.html.erb
|
251
253
|
- babel.config.js
|
252
254
|
- bin/rails
|
@@ -264,9 +266,11 @@ files:
|
|
264
266
|
- lib/generators/rails_server_monitor/templates/install.rb.tt
|
265
267
|
- lib/rails/server/monitor/engine.rb
|
266
268
|
- lib/rails_server_monitor.rb
|
269
|
+
- lib/rails_server_monitor/compile_locally.rb
|
267
270
|
- lib/rails_server_monitor/configuration.rb
|
268
271
|
- lib/rails_server_monitor/engine.rb
|
269
272
|
- lib/rails_server_monitor/version.rb
|
273
|
+
- lib/rubygems_plugin.rb
|
270
274
|
- lib/tasks/rails_server_monitor_tasks.rake
|
271
275
|
- package.json
|
272
276
|
- postcss.config.js
|