Class: Remon::Sysinfo
- Inherits:
-
Object
- Object
- Remon::Sysinfo
- Extended by:
- Helper
- Defined in:
- lib/remon/sysinfo.rb
Class Method Summary collapse
- .cores ⇒ Object
- .init ⇒ Object
- .instance_type ⇒ Object
- .ips ⇒ Object
- .normalized_cores ⇒ Object
- .nproc ⇒ Object
Methods included from Helper
Methods included from Logger
Class Method Details
.cores ⇒ Object
28 29 30 |
# File 'lib/remon/sysinfo.rb', line 28 def self.cores @cores ||= cores_linux end |
.init ⇒ Object
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_type ⇒ Object
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 |
.ips ⇒ Object
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_cores ⇒ Object
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 |
.nproc ⇒ Object
24 25 26 |
# File 'lib/remon/sysinfo.rb', line 24 def self.nproc @nproc ||= `nproc`.chomp.strip.to_i end |