Module: Gitlab::Metrics::System

Defined in:
lib/gitlab/metrics/system.rb

Overview

Module for gathering system/process statistics such as the memory usage.

This module relies on the /proc filesystem being available. If /proc is not available the methods of this module will be stubbed.

Class Method Summary collapse

Class Method Details

.cpu_timeObject


36
37
38
# File 'lib/gitlab/metrics/system.rb', line 36

def self.cpu_time
  Process.clock_gettime(Process::CLOCK_THREAD_CPUTIME_ID, :millisecond)
end

.file_descriptor_countObject


21
22
23
# File 'lib/gitlab/metrics/system.rb', line 21

def self.file_descriptor_count
  Dir.glob('/proc/self/fd/*').length
end

.memory_usageObject

Returns the current process' memory usage in bytes.


10
11
12
13
14
15
16
17
18
19
# File 'lib/gitlab/metrics/system.rb', line 10

def self.memory_usage
  mem   = 0
  match = File.read('/proc/self/status').match(/VmRSS:\s+(\d+)/)

  if match and match[1]
    mem = match[1].to_f * 1024
  end

  mem
end