Skip to content
Snippets Groups Projects
Commit 35c878f6 authored by Gabriel Mazetto's avatar Gabriel Mazetto
Browse files

Added load average to system sampling.

parent cf5f6039
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -43,6 +43,7 @@ def sample
sample_file_descriptors
sample_objects
sample_gc
sample_load_average
 
flush
ensure
Loading
Loading
@@ -98,6 +99,11 @@ def sample_gc
add_metric('gc_statistics', stats)
end
 
def sample_load_average
loadavg = System.load_average
add_metric('sys_loadavg', {:'1min' => loadavg[0], :'5min' => loadavg[1], :'15min' => loadavg[2]})
end
def add_metric(series, values, tags = {})
prefix = sidekiq? ? 'sidekiq_' : 'rails_'
 
Loading
Loading
Loading
Loading
@@ -8,7 +8,7 @@ module System
if File.exist?('/proc')
# Returns the current process' memory usage in bytes.
def self.memory_usage
mem = 0
mem = 0
match = File.read('/proc/self/status').match(/VmRSS:\s+(\d+)/)
 
if match and match[1]
Loading
Loading
@@ -21,6 +21,15 @@ def self.memory_usage
def self.file_descriptor_count
Dir.glob('/proc/self/fd/*').length
end
def self.load_average
loadavg = File.read('/proc/loadavg').scan(/\d+.\d+/)
if loadavg && loadavg[0] && loadavg[1] && loadavg[2]
loadavg[0..2].map { |value| value.to_f }
else
[0.0, 0.0, 0.0]
end
end
else
def self.memory_usage
0.0
Loading
Loading
@@ -29,6 +38,10 @@ def self.memory_usage
def self.file_descriptor_count
0
end
def self.load_average
[0.0, 0.0, 0.0]
end
end
 
# THREAD_CPUTIME is not supported on OS X
Loading
Loading
Loading
Loading
@@ -27,6 +27,14 @@
end
end
 
describe '.load_average' do
it 'returns the amount of load as 3 values array' do
expect(described_class.load_average[0]).to be >= 0.0
expect(described_class.load_average[1]).to be >= 0.0
expect(described_class.load_average[2]).to be >= 0.0
end
end
describe '.cpu_time' do
it 'returns a Fixnum' do
expect(described_class.cpu_time).to be_an_instance_of(Fixnum)
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment