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 +4 -4
- data/README.md +21 -13
- data/app/views/resource_monitor/resource/index.html.erb +5 -11
- data/lib/resource_monitor.rb +9 -8
- data/lib/resource_monitor/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eecf07c5ecfe62105544c1ea6346c03217f3c78d
|
4
|
+
data.tar.gz: 3097b646b2ea020215d3fa955d1aaf9e842a7157
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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:
|
12
|
-
Last Feature Set: Engine
|
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
|
28
|
-
You
|
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
|
-
|
32
|
-
|
30
|
+
# This should be a single line
|
31
|
+
around_action def benchmark; ResourceMonitor.benchmark(self); yield; ResourceMonitor.benchmark(self); end
|
32
|
+
```
|
33
33
|
|
34
|
-
|
35
|
-
|
36
|
-
|
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
|
-
|
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.
|
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
|
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
|
26
|
-
|
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
|
}
|
data/lib/resource_monitor.rb
CHANGED
@@ -2,16 +2,18 @@ require "resource_monitor/engine"
|
|
2
2
|
require "resource_monitor/version"
|
3
3
|
|
4
4
|
module ResourceMonitor
|
5
|
-
def self.benchmark(
|
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
|
10
|
-
|
11
|
-
|
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
|
-
|
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
|
-
|
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)
|