Class: ClusteredRpc::Info
- Inherits:
-
Object
- Object
- ClusteredRpc::Info
- Includes:
- Methods
- Defined in:
- lib/clustered_rpc/info.rb
Class Method Summary collapse
- .get_uptime ⇒ Object
- .lookup_process_type(sc = startup_command) ⇒ Object
- .memory_used ⇒ Object
- .startup_command ⇒ Object
- .stats(detailed_memory_stats = false) ⇒ Object
Class Method Details
.get_uptime ⇒ Object
36 37 38 |
# File 'lib/clustered_rpc/info.rb', line 36 def self.get_uptime Open3.capture3("ps", "-p", Process.pid.to_s, "-o", "etime=").first.split("\n").first end |
.lookup_process_type(sc = startup_command) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/clustered_rpc/info.rb', line 40 def self.lookup_process_type(sc = startup_command) process_type = if (sc == "script/rails []") || (sc == "bin/rails []") || ( sc =~ /spring app/) "Rails Console" elsif (sc =~ /sidekiq/) "Sidekiq" elsif (sc =~ /puma/) "Web Server" elsif (sc =~ /rspec/) "Rspec" elsif sc =~ /scheduler/ "Resque Scheduler" elsif sc =~ /resque:work/ "Resque Worker" elsif sc =~ /rules:redis/ "Rules Engine" else sc end process_type end |
.memory_used ⇒ Object
32 33 34 |
# File 'lib/clustered_rpc/info.rb', line 32 def self.memory_used (((100.0 * (`ps -o rss -p #{$$}`.strip.split.last.to_f / 1024.0)).to_i) / 100.0) end |
.startup_command ⇒ Object
28 29 30 |
# File 'lib/clustered_rpc/info.rb', line 28 def self.startup_command "#{$0} #{$*}" end |
.stats(detailed_memory_stats = false) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/clustered_rpc/info.rb', line 8 def self.stats(detailed_memory_stats = false) require 'objspace' r = { instance_id: ClusteredRpc.instance_id, transport_class: ClusteredRpc.transport_class.name.to_s, options: ClusteredRpc., process_id: Process.pid, uptime: get_uptime, used_mb: memory_used, startup_command: startup_command, process_type: lookup_process_type(startup_command), count_nodes: ObjectSpace.count_nodes, } if detailed_memory_stats r[:count_objects_size] = ObjectSpace.count_objects_size r[:gc] = GC.stat end r end |