resource_monitor 0.1.2 → 1.0

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
  SHA1:
3
- metadata.gz: b9cff3d45a83f8e83d3297d05360bc74aabf34e7
4
- data.tar.gz: 61dd96132acfdf3b75fa5ffd61f11c1e1c538115
3
+ metadata.gz: eecf07c5ecfe62105544c1ea6346c03217f3c78d
4
+ data.tar.gz: 3097b646b2ea020215d3fa955d1aaf9e842a7157
5
5
  SHA512:
6
- metadata.gz: 11843bbb8f9c150e0687f78fdaa7f936d04682e45cf398e5f96cbc56dcd3651088142e1de4ed1a17d4d5b9d8fd3fd0830d261813925f3d9010502f6a3c5868c8
7
- data.tar.gz: 117e13d29e5ed610285f992c495256815881b0cce37a5fdd73d9bb2135ccab1f60739f41c9b5302d4d88442d0122a83d966024feb7ff6107eb1585e6cb99621a
6
+ metadata.gz: e8f10d66a3f4c3f397aa10c0e284a7750b2d3178e2858434450ff4c5a7878e53c02371085e7f2672fb641655971aafd9f768b8616f3f674a406b0088567cdeb0
7
+ data.tar.gz: 8d9e376abfaacbb956f48896bcd7f670b7d02f827a617d90925c0ffb3a926c08630efb201262b82564c884db71108511afa916962a619c90bdf57ca2fb003b93
data/README.md CHANGED
@@ -8,9 +8,8 @@ Creates a simple page under /resources/ that is updated with CPU/RAM usage in re
8
8
 
9
9
  Although not a major performance hog, this should only be run in production when there is evidence of resource overuse, look under the Usage section for instructions for disabling the gem.
10
10
 
11
- Latest Version: 0.1.2
12
- Last Feature Set: Engine created, no need to manually install dashboard.
13
- Recommended Installation: Uninstall dashboard, then remove Gemfile.lock and rebundle.
11
+ Latest Version: 1.0
12
+ Last Feature Set: Complete Engine and Simplified Installation. Support for ActionController and ActiveRecord benchmarks.
14
13
 
15
14
  ## Installation
16
15
 
@@ -24,16 +23,22 @@ And then execute:
24
23
 
25
24
  $ bundle install
26
25
 
27
- Add the following to the top of your application.rb file
28
- You can also only add it to the controllers you think may be causing some issues.
26
+ Add the following to the top of your application_controller.rb file
27
+ You may also add it to the controllers you think may be causing some issues.
29
28
 
30
29
  ```ruby
31
- before_action :resource_monitor_app
32
- after_action :resource_monitor_app
30
+ # This should be a single line
31
+ around_action def benchmark; ResourceMonitor.benchmark(self); yield; ResourceMonitor.benchmark(self); end
32
+ ```
33
33
 
34
- def resource_monitor_app
35
- ResourceMonitor.benchmark(self)
36
- end
34
+ You can also utilize standard callbacks and add only, except conditions
35
+
36
+ ```ruby
37
+ # This should be a single line (enables resource monitoring in the "index")
38
+ around_action def benchmark; ResourceMonitor.benchmark(self); yield; ResourceMonitor.benchmark(self); end, only: :index
39
+
40
+ # This should be a single line (enables resource monitoring for everything except 'index')
41
+ around_action def benchmark; ResourceMonitor.benchmark(self); yield; ResourceMonitor.benchmark(self); end, except: :index
37
42
  ```
38
43
  ## Usage
39
44
 
@@ -52,19 +57,22 @@ Bundle install and browse to /resources/.
52
57
  If you want to disable this, you can easily comment out the contents of resource_monitor_app or use an ENV variable such as below.
53
58
 
54
59
  ```ruby
55
- before_action :resource_monitor_app
56
- after_action :resource_monitor_app
60
+ around_action :resource_monitor_app
57
61
 
58
62
  def resource_monitor_app
59
63
  if ENV['MONITORING_ENABLED']
60
64
  ResourceMonitor.benchmark(self)
65
+ yield
66
+ ResourceMonitor.benchmark(self)
67
+ else
68
+ yield
61
69
  end
62
70
  end
63
71
  ```
64
72
 
65
73
  ## Development
66
74
 
67
- After checking out the repo, run `bin/setup` to install dependencies. You can also run `rake resource_monitor:console` for an interactive prompt that will allow you to experiment.
75
+ After checking out the repo, run `bin/setup` to install dependencies.
68
76
 
69
77
  To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
70
78
 
@@ -14,21 +14,17 @@
14
14
  var cpu_percentage = json['cpu_percentage']
15
15
  var ram_percentage = json['ram_percentage']
16
16
  var ram_usage = json['ram_usage']
17
- var last_executed_controller = json['last_executed_controller']
18
- var last_executed_action = json['last_executed_action']
17
+ var details = json['details']
19
18
 
20
19
 
21
20
  var execution_details_td = jQuery('<td/>', {
22
21
  text: ""
23
22
  });
24
23
 
25
- var controller_details = jQuery('<p>',{
26
- text: "Controller: " +last_executed_controller
27
- })
28
-
29
- var action_details = jQuery('<p>',{
30
- text: "Action: " + last_executed_action
31
- })
24
+ var details = details.split("\n")
25
+ $.each(details, function(i, v) {
26
+ $($("<p>").text(details[i])).appendTo(execution_details_td);
27
+ });
32
28
 
33
29
  var ram_usage_td = jQuery('<td/>', {
34
30
  text: ram_usage + " MB"
@@ -52,8 +48,6 @@
52
48
  cpu_percentage_td.appendTo(main_tr)
53
49
  ram_percentage_td.appendTo(main_tr)
54
50
  ram_usage_td.appendTo(main_tr)
55
- controller_details.appendTo(execution_details_td)
56
- action_details.appendTo(execution_details_td)
57
51
  execution_details_td.appendTo(main_tr)
58
52
  main_tr.prependTo(table_body)
59
53
  }
@@ -2,16 +2,18 @@ require "resource_monitor/engine"
2
2
  require "resource_monitor/version"
3
3
 
4
4
  module ResourceMonitor
5
- def self.benchmark(controller=nil)
5
+ def self.benchmark(input=nil)
6
6
  # Recover the process id and memory usage in KB (http://stackoverflow.com/questions/7220896/get-current-ruby-process-memory-usage)
7
7
  pid, size, cpu_per, mem_per = `ps ax -o pid,rss,%cpu,%mem | grep -E "^[[:space:]]*#{$$}"`.strip.split.map(&:to_i)
8
8
 
9
- if controller
10
- last_executed_controller = controller.controller_name || 'NoController'
11
- last_executed_action = controller.action_name || 'NoAction'
9
+ if input
10
+ if input.kind_of?(ActionController::Base)
11
+ details = "Controller: #{input.controller_name}\nAction: #{input.action_name}"
12
+ elsif input.kind_of?(ActiveRecord::Base)
13
+ details = "Model: #{input.model_name.human}"
14
+ end
12
15
  else
13
- last_executed_controller = 'NoController'
14
- last_executed_action = 'NoAction'
16
+ details = "No details available"
15
17
  end
16
18
 
17
19
  data = {
@@ -19,8 +21,7 @@ module ResourceMonitor
19
21
  cpu_percentage: cpu_per,
20
22
  ram_percentage: mem_per,
21
23
  ram_usage: (size / 1024).to_i,
22
- last_executed_controller: last_executed_controller,
23
- last_executed_action: last_executed_action
24
+ details: details
24
25
  }
25
26
 
26
27
  ActionCable.server.broadcast 'resources', data.to_json if defined?(ActionCable)
@@ -1,3 +1,3 @@
1
1
  module ResourceMonitor
2
- VERSION = '0.1.2'
2
+ VERSION = '1.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resource_monitor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: '1.0'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lazaro Herrera