rails-server-monitor 0.1.4 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d6ee5dfbcafedea660676e5b93da7179c2fdb0b8dde4860bb9669cc027f4904f
4
- data.tar.gz: 19bb6fd06eeca9f55ae678f3f7578c8c9354c83a1c6edf756bea35fa4dc667ca
3
+ metadata.gz: 3e47312d01c09679dc3df5b1b4d042bd7a7d7d0290d55902d7fe4ef8dd6e7a22
4
+ data.tar.gz: b30f2db395c5c25eeae2ffd1fa639aa8f277c35d25d0fd6a3fbeacdeda662dcc
5
5
  SHA512:
6
- metadata.gz: 0d0b2683477314a18e8546db20889f3696c258e8f8bd6f4e1fe4eb5be320d66b3ef74ee7d4d2df470646dd029199946d3aa8c5b7c42a357767794c2009a5dc5c
7
- data.tar.gz: '09124bc1eeadbe2e30c7fe34b253f3f1457064aea4b0c9ef6cf77373d5316177fe8843b86b01c05d82be280920febd2e173ee613f4d5773c2523b93629cf1f7b'
6
+ metadata.gz: e2b2ad6e4df19eb305bfe9f02e4d1d4034519acdd70d0558960e2d7bcc55e16acccb8ff12dd51639d76927e2ae16cde848f76d62031581145061a556304672cb
7
+ data.tar.gz: 446a671e8cd3918173c10f82ad5f8f63364224fb05559e860e4fdbcfc758352ef44c28f6ea2edcb8a26e60b761f22b4c9a424a8269d40e94b7678130bcb411b0
data/README.md CHANGED
@@ -1,28 +1,129 @@
1
- # Rails::Server::Monitor
2
- Short description and motivation.
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
- ## Usage
5
- How to use my plugin.
5
+ [See it in action](https://rails-sever-monitor.herokuapp.com)
6
6
 
7
- ## Installation
8
- Add this line to your application's Gemfile:
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
- And then execute:
16
+ #### 2) generate Rails Server Monitor tables
15
17
  ```bash
16
- $ bundle
18
+ rails g rails_server_monitor:install
19
+ rails db:migrate
17
20
  ```
18
21
 
19
- Or install it yourself as:
20
- ```bash
21
- $ gem install rails-server-monitor
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
- Contribution directions go here.
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
@@ -25,5 +25,9 @@ module RailsServerMonitor
25
25
 
26
26
  stylesheet_pack_tag(name, **options)
27
27
  end
28
+
29
+ def server_version
30
+ RailsServerMonitor::VERSION
31
+ end
28
32
  end
29
33
  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: :today)
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 == :today
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
@@ -19,7 +19,7 @@ module RailsServerMonitor
19
19
 
20
20
  private
21
21
  def hostname
22
- @hostname ||= `hostname`.squish
22
+ @hostname ||= config.hostname.call.squish
23
23
  end
24
24
 
25
25
  def update_server
@@ -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
- <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>
19
+ <div class="flex-1">
20
+ <%= yield %>
21
+ </div>
18
22
 
19
- <div class="flex-1">
20
- <%= yield %>
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
- <%= content_tag :div, class: "#{@chart.today? ? "w-1/2" : "w-full"}" do %>
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
- <div class="mt-20">
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
- <%= @server.custom_name %>
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
- <%= @server.custom_description %>
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 Codes",
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
- </div>
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 %>
data/babel.config.js ADDED
@@ -0,0 +1,91 @@
1
+ module.exports = function(api) {
2
+ var validEnv = ['development', 'test', 'production']
3
+ var currentEnv = api.env()
4
+ var isDevelopmentEnv = api.env('development')
5
+ var isProductionEnv = api.env('production')
6
+ var isTestEnv = api.env('test')
7
+
8
+ if (!validEnv.includes(currentEnv)) {
9
+ throw new Error(
10
+ 'Please specify a valid `NODE_ENV` or ' +
11
+ '`BABEL_ENV` environment variables. Valid values are "development", ' +
12
+ '"test", and "production". Instead, received: ' +
13
+ JSON.stringify(currentEnv) +
14
+ '.'
15
+ )
16
+ }
17
+
18
+ return {
19
+ presets: [
20
+ isTestEnv && [
21
+ '@babel/preset-env',
22
+ {
23
+ targets: {
24
+ node: 'current'
25
+ },
26
+ modules: 'commonjs'
27
+ },
28
+ [
29
+ '@babel/preset-react',
30
+ {
31
+ development: true,
32
+ useBuiltIns: true,
33
+ runtime: "automatic",
34
+ }
35
+ ]
36
+ ],
37
+ (isProductionEnv || isDevelopmentEnv) && [
38
+ '@babel/preset-env',
39
+ {
40
+ forceAllTransforms: true,
41
+ useBuiltIns: 'entry',
42
+ corejs: 3,
43
+ modules: false,
44
+ loose: false,
45
+ exclude: ['transform-typeof-symbol']
46
+ }
47
+ ],
48
+ [
49
+ '@babel/preset-react',
50
+ {
51
+ development: isDevelopmentEnv || isTestEnv,
52
+ useBuiltIns: true,
53
+ runtime: "automatic"
54
+ }
55
+ ]
56
+ ].filter(Boolean),
57
+ plugins: [
58
+ 'babel-plugin-macros',
59
+ '@babel/plugin-syntax-dynamic-import',
60
+ isTestEnv && 'babel-plugin-dynamic-import-node',
61
+ '@babel/plugin-transform-destructuring',
62
+ '@babel/plugin-proposal-class-properties',
63
+ [
64
+ '@babel/plugin-proposal-object-rest-spread',
65
+ {
66
+ useBuiltIns: true
67
+ }
68
+ ],
69
+ [
70
+ '@babel/plugin-transform-runtime',
71
+ {
72
+ helpers: false,
73
+ regenerator: true,
74
+ corejs: false
75
+ }
76
+ ],
77
+ [
78
+ '@babel/plugin-transform-regenerator',
79
+ {
80
+ async: false
81
+ }
82
+ ],
83
+ isProductionEnv && [
84
+ 'babel-plugin-transform-react-remove-prop-types',
85
+ {
86
+ removeImport: true
87
+ }
88
+ ]
89
+ ].filter(Boolean)
90
+ }
91
+ }