Module: LinuxSystemInfo
- Defined in:
- lib/LinuxSystemInfo.rb,
lib/LinuxSystemInfo/version.rb
Constant Summary collapse
- VERSION =
"0.0.1"
Class Method Summary collapse
- .audio ⇒ Object
- .connection ⇒ Object
- .cpu ⇒ Object
- .hostname ⇒ Object
- .memory ⇒ Object
- .network ⇒ Object
- .storage ⇒ Object
- .to_hash ⇒ Object
- .to_s ⇒ Object
- .usb ⇒ Object
- .video ⇒ Object
Class Method Details
.audio ⇒ Object
91 92 93 94 95 96 97 98 99 100 |
# File 'lib/LinuxSystemInfo.rb', line 91 def audio data = Array.new audio = `lspci` audios = audio.split("\n").grep /Audio/ audios.each do |audio| audio = audio.split(':') data.push audio[2].strip end data end |
.connection ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/LinuxSystemInfo.rb', line 5 def connection output = Hash.new network = `ifconfig` network = network.split("\n\n") network.each do |data| interface = data.scan(/^[a-z]+\d?/).first next if interface == 'lo' next if data.match(/addr:(\d+\.)+\d+/).to_s.sub('addr:', '').empty? output[interface] = { :mac => data.match(/HWaddr [a-z0-9:]+/).to_s.sub('HWaddr ', ''), :ip => data.match(/inet addr:(\d+\.)+\d+/).to_s.sub('inet addr:', ''), :mask => data.match(/Mask:(\d+\.?)+/).to_s.sub('Mask:', ''), :broadcast => data.match(/Bcast:(\d+\.?)+/).to_s.sub('Bcast:', ''), :ip6 => data.match(/inet6 addr: (([a-z]|\d)+([a-z]|\d)+(:|::)+)+(([a-z]|\d)+(\/)*([a-z]|\d)+)/).to_s.sub('inet6 addr:', '').strip } end output end |
.cpu ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/LinuxSystemInfo.rb', line 25 def cpu cpu = `lscpu` cpu = cpu.split("\n") cpu_detail = `cat /proc/cpuinfo` cpu_detail = cpu_detail.split("\n") { :model => { :name => cpu_detail.grep(/model name/).first.split(':').last, :number => cpu.grep(/Model/).first.split.last }, :address_sizes => cpu_detail.grep(/address sizes/).first.split(':').last, :architecture => cpu.grep(/Architecture/).first.split.last, :threads => cpu.grep(/Thread/).first.split.last, :cores => cpu.grep(/Core/).first.split.last, :socket => cpu.grep(/Socket/).first.split.last, :family => cpu.grep(/family/).first.split.last, :flags => cpu_detail.grep(/flags/).first.split(':').last, :L1 => { :d => cpu.grep(/L1d cache/).first.split.last, :i => cpu.grep(/L1i cache/).first.split.last }, :L2 => cpu.grep(/L2 cache/).first.split.last, :L3 => cpu.grep(/L3 cache/).first.split.last } end |
.hostname ⇒ Object
126 127 128 |
# File 'lib/LinuxSystemInfo.rb', line 126 def hostname `hostname`.strip end |
.memory ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/LinuxSystemInfo.rb', line 53 def memory ram = `free -m` ram = ram.split("\n")[1].split { :unit => 'Megabyte', :total => ram[1], :used => ram[2], :free => ram[3], :shared => ram[4], :buffers => ram[5], :cached => ram[6] } end |
.network ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/LinuxSystemInfo.rb', line 114 def network data = Array.new connection = `lspci` connection = connection.split("\n") connections = connection.grep /(Network|Ethernet)/ connections.each do |connection| connection = connection.split(':') data.push connection[2].strip end data end |
.storage ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/LinuxSystemInfo.rb', line 67 def storage output = Hash.new storage = `df -h` storage = storage.split("\n") storage.each do |file| file = file.split next if file[0][0..4] != '/dev/' output[file[0]] = { :size => file[1], :used => file[2], :available => file[3], :used_percentage => file[4], :mount => file[5] } end output end |
.to_hash ⇒ Object
130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/LinuxSystemInfo.rb', line 130 def to_hash { :hostname => hostname, :cpu => cpu, :ram => memory, :storage => storage, :network => network, :connection => connection, :video => video, :audio => audio, :usb => usb } end |
.to_s ⇒ Object
144 145 146 |
# File 'lib/LinuxSystemInfo.rb', line 144 def to_s JSON.pretty_generate to_hash end |
.usb ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/LinuxSystemInfo.rb', line 102 def usb data = Array.new usb = `lspci` usb = usb.split("\n") usbs = usb.grep /USB/ usbs.each do |usb| usb = usb.split(':') data.push usb[2].strip end data end |
.video ⇒ Object
85 86 87 88 89 |
# File 'lib/LinuxSystemInfo.rb', line 85 def video video = `lspci` video = video.split("\n").find { |e| /VGA/ =~ e } video.split(':')[2].strip end |