module Metrics
Nested
Definitions
def self.duration(value)
Parse a duration string into seconds. According to the linux manual page specifications.
Implementation
def self.duration(value)
if /((?<days>\d\d)\-)?((?<hours>\d\d):)?(?<minutes>\d\d):(?<seconds>\d\d)?/ =~ value
(((days&.to_i || 0) * 24 + (hours&.to_i || 0)) * 60 + (minutes&.to_i || 0)) * 60 + seconds&.to_i
end
end
FIELDS = {...}
The fields that will be extracted from the ps
command.
Implementation
FIELDS = {
pid: ->(value){value.to_i}, # Process ID
ppid: ->(value){value.to_i}, # Parent Process ID
pgid: ->(value){value.to_i}, # Process Group ID
pcpu: ->(value){value.to_f}, # Percentage CPU
time: self.method(:duration), # CPU Time
vsz: ->(value){value.to_i}, # Virtual Size
rss: ->(value){value.to_i}, # Resident Size
etime: self.method(:duration), # Elapsed Time
command: ->(value){value}, # Command (name of the process)
}