Class: Metrix::Process

Inherits:
Base
  • Object
show all
Defined in:
lib/metrix/process.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#attributes

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

ignore, #ignore_metric?, ignore_metrics, #initialize, #metrics

Constructor Details

This class inherits a constructor from Metrix::Base

Instance Attribute Details

#timeObject (readonly)

Returns the value of attribute time.



5
6
7
# File 'lib/metrix/process.rb', line 5

def time
  @time
end

Class Method Details

.allObject



8
9
10
11
12
13
14
# File 'lib/metrix/process.rb', line 8

def all
  Dir.glob("/proc/*").select do |path|
    File.directory?(path) && File.basename(path)[/^\d+$/]
  end.map do |path|
    Metrix::Process.new(File.read(path + "/stat"))
  end
end

Instance Method Details

#cast_int(str) ⇒ Object



53
54
55
# File 'lib/metrix/process.rb', line 53

def cast_int(str)
  Integer(str) rescue str
end

#chunksObject



21
22
23
# File 'lib/metrix/process.rb', line 21

def chunks
  @chunks ||= @raw.split(" ").map { |c| cast_int(c) }
end

#nameObject



17
18
19
# File 'lib/metrix/process.rb', line 17

def name
  comm.gsub(/^\(/, "").gsub(/\)$/, "")
end

#prefixObject



49
50
51
# File 'lib/metrix/process.rb', line 49

def prefix
  "system.process"
end

#tagsObject



25
26
27
28
29
30
31
# File 'lib/metrix/process.rb', line 25

def tags
  {
    name:   name,
    pid:    pid,
    ppid:   ppid,
  }
end

#unfiltered_metricsObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/metrix/process.rb', line 33

def unfiltered_metrics
  {
    minflt: minflt,
    cminflt: cminflt,
    majflt: majflt,
    cmajflt: cmajflt,
    utime: utime,
    stime: stime,
    cutime: cutime,
    sctime: sctime,
    num_threads: num_threads,
    vsize: vsize,
    rss: rss,
  }
end