rails-internals 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0242671698617c76f2cdf76c266130b59531f4c2
4
+ data.tar.gz: 2e9a5df17a67c4cc9abbd3bc010526c57ff8095f
5
+ SHA512:
6
+ metadata.gz: 519228021ea416febefd0a04f346fc6075bb5f5228d348f5a2c87b6b1a2a572dd0b20100ede8db6840c5fde72bc444cd423cc81471bb1f997e2647230ec9021a
7
+ data.tar.gz: aec29b6db36b09f140afb93650b19398bec943de1405933e73e82e9d4dfa6ca91a75fcd67d3bfde6d7dc75afdee1bc23ee2cf0bc140e4bfa6e4c41b6c48a1033
@@ -0,0 +1,20 @@
1
+ Copyright 2017 Godfrey Chan
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.
@@ -0,0 +1,34 @@
1
+ # Rails::Internals
2
+
3
+ Like [chrome://net-internals](chrome://net-internals), but for Rails.
4
+
5
+ ## Usage
6
+
7
+ ## Installation
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'rails-internals'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ ```bash
17
+ $ bundle
18
+ ```
19
+
20
+ Then mount it at the desirable location inside your app's `config/routes.rb`.
21
+
22
+ For example, to mount the dashboard at `/rails-internals`, you would do:
23
+
24
+ ```ruby
25
+ Rails.application.routes.draw do
26
+ mount Rails::Internals::Engine => "/rails-internals"
27
+ end
28
+ ```
29
+
30
+ ## Contributing
31
+ Contribution directions go here.
32
+
33
+ ## License
34
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,37 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Rails::Internals'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+ load 'rails/tasks/statistics.rake'
22
+
23
+
24
+
25
+ require 'bundler/gem_tasks'
26
+
27
+ require 'rake/testtask'
28
+
29
+ Rake::TestTask.new(:test) do |t|
30
+ t.libs << 'lib'
31
+ t.libs << 'test'
32
+ t.pattern = 'test/**/*_test.rb'
33
+ t.verbose = false
34
+ end
35
+
36
+
37
+ task default: :test
@@ -0,0 +1,2 @@
1
+ //= link_directory ../javascripts/rails/internals .js
2
+ //= link_directory ../stylesheets/rails/internals .css
@@ -0,0 +1,27 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10
+ * files in this directory. Styles in this file should be added after the last require_* statement.
11
+ * It is generally better to create a new file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
16
+
17
+ .stacked-bar {
18
+ position: relative;
19
+ min-width: 500px;
20
+ height: 100px;
21
+
22
+ > div {
23
+ float: left;
24
+ text-align: center;
25
+ }
26
+ }
27
+
@@ -0,0 +1,7 @@
1
+ module Rails
2
+ module Internals
3
+ class ApplicationController < ActionController::Base
4
+ protect_from_forgery with: :exception
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,19 @@
1
+ require_dependency "rails/internals/application_controller"
2
+
3
+ module Rails
4
+ module Internals
5
+ class DashboardController < ApplicationController
6
+ def index
7
+ redirect_to :process_info
8
+ end
9
+
10
+ def process_info
11
+ @process = ProcessInfo.new
12
+ end
13
+
14
+ def object_space
15
+ @object_space_hash = ObjectSpaceInfo.new
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,6 @@
1
+ module Rails
2
+ module Internals
3
+ module ApplicationHelper
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ module Rails
2
+ module Internals
3
+ class ApplicationJob < ActiveJob::Base
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,8 @@
1
+ module Rails
2
+ module Internals
3
+ class ApplicationMailer < ActionMailer::Base
4
+ default from: 'from@example.com'
5
+ layout 'mailer'
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ module Rails
2
+ module Internals
3
+ class ApplicationRecord < ActiveRecord::Base
4
+ self.abstract_class = true
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,21 @@
1
+ module Rails
2
+ module Internals
3
+ class ObjectSpaceInfo
4
+ attr_reader :counts
5
+
6
+ def initialize
7
+ @counts = ObjectSpace.count_objects
8
+ end
9
+
10
+ def total
11
+ @counts[:TOTAL]
12
+ end
13
+
14
+ def ratios
15
+ @rations ||= @counts.except(:TOTAL, :FREE).each_with_object({}) do |(key, value), hash|
16
+ hash[key] = value / total.to_f
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,24 @@
1
+ require 'socket'
2
+ require 'get_process_mem'
3
+
4
+ module Rails
5
+ module Internals
6
+ class ProcessInfo
7
+ def initialize(memory_usage: GetProcessMem.new.bytes)
8
+ @memory_usage = memory_usage
9
+ end
10
+
11
+ def hostname
12
+ Socket.gethostname
13
+ end
14
+
15
+ def pid
16
+ Process.pid
17
+ end
18
+
19
+ def memory_usage
20
+ @memory_usage.to_s(:human_size)
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Rails internals</title>
5
+ <%= stylesheet_link_tag "rails/internals/application", media: "all" %>
6
+ <%= javascript_include_tag "rails/internals/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,17 @@
1
+ <h1>Object Space</h1>
2
+
3
+ <dl class="object-space">
4
+ <%@object_space_hash.counts.each do |key, value|%>
5
+ <dt class="pid"><%= key %></dt>
6
+ <dd class="pid"><%= value %></dd>
7
+ <%end%>
8
+ </dl>
9
+
10
+
11
+ <div class="stacked-bar">
12
+ <%@object_space_hash.ratios.each do |key, ratio|%>
13
+ <div style="background-color: red; color: white; width: <%=number_to_percentage(ratio * 100)%>">
14
+ <%=key%>
15
+ </div>
16
+ <%end%>
17
+ </div>
@@ -0,0 +1,12 @@
1
+ <h1>Process Information</h1>
2
+
3
+ <dl class="process-information">
4
+ <dt class="hostname">Hostname</dt>
5
+ <dd class="hostname"><%= @process.hostname %></dd>
6
+
7
+ <dt class="pid">PID</dt>
8
+ <dd class="pid"><%= @process.pid %></dd>
9
+
10
+ <dt class="memory-usage">Memory Usage</dt>
11
+ <dd class="memory-usage"><%= @process.memory_usage %></dd>
12
+ </dl>
@@ -0,0 +1,6 @@
1
+ Rails::Internals::Engine.routes.draw do
2
+ root 'dashboard#index'
3
+
4
+ get 'process_info', to: 'dashboard#process_info'
5
+ get 'object_space', to: 'dashboard#object_space'
6
+ end
@@ -0,0 +1,7 @@
1
+ require "rails/internals/engine"
2
+
3
+ module Rails
4
+ module Internals
5
+ # Your code goes here...
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Rails
2
+ module Internals
3
+ class Engine < ::Rails::Engine
4
+ isolate_namespace Rails::Internals
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ module Rails
2
+ module Internals
3
+ VERSION = '0.1.0'
4
+ end
5
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :rails_internals do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails-internals
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Godfrey Chan
8
+ - Vaidehi Joshi
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2017-02-15 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: 5.0.1
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: 5.0.1
28
+ - !ruby/object:Gem::Dependency
29
+ name: get_process_mem
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ description:
43
+ email:
44
+ - godfreykfc@gmail.com
45
+ - vaidehi.sj@gmail.com
46
+ executables: []
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - MIT-LICENSE
51
+ - README.md
52
+ - Rakefile
53
+ - app/assets/config/rails_internals_manifest.js
54
+ - app/assets/stylesheets/rails/internals/application.scss
55
+ - app/controllers/rails/internals/application_controller.rb
56
+ - app/controllers/rails/internals/dashboard_controller.rb
57
+ - app/helpers/rails/internals/application_helper.rb
58
+ - app/jobs/rails/internals/application_job.rb
59
+ - app/mailers/rails/internals/application_mailer.rb
60
+ - app/models/rails/internals/application_record.rb
61
+ - app/models/rails/internals/object_space_info.rb
62
+ - app/models/rails/internals/process_info.rb
63
+ - app/views/layouts/rails/internals/application.html.erb
64
+ - app/views/rails/internals/dashboard/object_space.html.erb
65
+ - app/views/rails/internals/dashboard/process_info.html.erb
66
+ - config/routes.rb
67
+ - lib/rails/internals.rb
68
+ - lib/rails/internals/engine.rb
69
+ - lib/rails/internals/version.rb
70
+ - lib/tasks/rails/internals_tasks.rake
71
+ homepage: https://github.com/chancancode/rails-internals
72
+ licenses:
73
+ - MIT
74
+ metadata: {}
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubyforge_project:
91
+ rubygems_version: 2.4.8
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: Like chrome://net-internals, but for Rails.
95
+ test_files: []