Class: Remon::Sysinfo

Inherits:
Object
  • Object
show all
Extended by:
Helper
Defined in:
lib/remon/sysinfo.rb

Class Method Summary collapse

Methods included from Helper

cmd, safe_cmd

Methods included from Logger

logger, #logger

Class Method Details

.coresObject



28
29
30
# File 'lib/remon/sysinfo.rb', line 28

def self.cores
  @cores ||= cores_linux
end

.initObject



8
9
10
11
12
13
14
15
# File 'lib/remon/sysinfo.rb', line 8

def self.init
  puts "loading sysinfo"
  nproc
  cores
  normalized_cores
  instance_type
  ips
end

.instance_typeObject



17
18
19
20
21
22
# File 'lib/remon/sysinfo.rb', line 17

def self.instance_type
 @instance_type ||= begin
    exitstatus, instance_type = safe_cmd 'curl -s -m2 169.254.169.254/latest/meta-data/instance-type', return_output: true
    exitstatus == 0 ? instance_type : "unknown"
  end
end

.ipsObject



40
41
42
43
44
45
46
47
48
# File 'lib/remon/sysinfo.rb', line 40

def self.ips
  @ips ||= begin
    addr_infos = Socket.ip_address_list.select do |i|
      i.ip_address =~ /\A([0-9]{1,3}\.){3}[0-9]{1,3}\z/
    end
    addr_infos.reject! { |i| i.ip_address == "127.0.0.1" }
    ips = addr_infos.map { |i| i.ip_address }
  end
end

.normalized_coresObject



32
33
34
35
36
37
38
# File 'lib/remon/sysinfo.rb', line 32

def self.normalized_cores
  @normalized_cores ||= begin
    cores = self.cores
    nproc = self.nproc
    (cores == nproc) ? cores : (cores + (nproc - cores)* 30.0/100)
  end
end

.nprocObject



24
25
26
# File 'lib/remon/sysinfo.rb', line 24

def self.nproc
  @nproc ||= `nproc`.chomp.strip.to_i
end