linux_stat 0.3.0 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +277 -40
- data/bin/linuxstat.rb +44 -6
- data/ext/fs_stat/extconf.rb +5 -2
- data/ext/fs_stat/fs_stat.c +14 -11
- data/ext/sysconf/extconf.rb +7 -0
- data/ext/sysconf/sysconf.c +53 -0
- data/ext/utsname/extconf.rb +7 -0
- data/ext/utsname/utsname.c +49 -0
- data/lib/linux_stat.rb +8 -1
- data/lib/linux_stat/battery.rb +2 -2
- data/lib/linux_stat/bios.rb +10 -6
- data/lib/linux_stat/cpu.rb +31 -6
- data/lib/linux_stat/filesystem.rb +10 -15
- data/lib/linux_stat/kernel.rb +17 -6
- data/lib/linux_stat/memory.rb +8 -2
- data/lib/linux_stat/os.rb +27 -8
- data/lib/linux_stat/process_info.rb +310 -0
- data/lib/linux_stat/swap.rb +6 -1
- data/lib/linux_stat/version.rb +1 -1
- metadata +11 -7
data/bin/linuxstat.rb
CHANGED
@@ -2,17 +2,45 @@
|
|
2
2
|
begin
|
3
3
|
require 'linux_stat'
|
4
4
|
rescue LoadError
|
5
|
-
|
6
|
-
require 'linux_stat'
|
5
|
+
puts "The Gem needs to be installed before this test can be run!"
|
7
6
|
end
|
8
7
|
|
9
8
|
$-v = true
|
10
9
|
|
11
10
|
# Print time each method takes unless --no-time or -nt option is passed
|
12
|
-
|
13
|
-
|
11
|
+
markdown = ARGV.any? { |x| x[/^\-(\-markdown|md)$/] }
|
12
|
+
html = ARGV.any? { |x| x[/^\-(\-html|html)$/] }
|
13
|
+
|
14
|
+
# Check which conflicting argument (e.g., `-md -html` together) is passed last
|
15
|
+
# Always use the last argument
|
16
|
+
conflicting, hash = [
|
17
|
+
"markdown|html", /^\-(\-markdown|md)$/, /^\-(\-html|html)$/
|
18
|
+
].each_slice(3).to_a, {}
|
19
|
+
|
20
|
+
conflicting.each do |x, y, z|
|
21
|
+
o1, o2 = *x.split(?|.freeze).map(&:to_sym)
|
22
|
+
m1, m2 = ARGV.any? { |_x| _x[y] }, ARGV.any? { |_x| _x[z] }
|
23
|
+
|
24
|
+
if m1 && m2
|
25
|
+
rev = ARGV.reverse
|
26
|
+
|
27
|
+
if rev.index { |_x| _x[y] } < rev.index { |_x| _x[z] }
|
28
|
+
hash.merge!(o1 => true)
|
29
|
+
else
|
30
|
+
hash.merge!(o2 => true)
|
31
|
+
end
|
32
|
+
elsif m1
|
33
|
+
hash.merge!(o1 => true)
|
34
|
+
elsif m2
|
35
|
+
hash.merge!(o2 => true)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
MARKDOWN, HTML = hash[:markdown], hash[:html]
|
40
|
+
|
41
|
+
PRINT_TIME = (MARKDOWN || HTML) ? false : !ARGV.any? { |x| x[/^\-\-no-time$/] || x[/^\-nt$/] }
|
14
42
|
|
15
|
-
%w(--markdown -md --no-time -nt).each(&ARGV.method(:delete))
|
43
|
+
%w(--markdown -md --no-time -nt --html -html).each(&ARGV.method(:delete))
|
16
44
|
|
17
45
|
# Run only desired classes / modules
|
18
46
|
constants = LinuxStat.constants
|
@@ -29,10 +57,13 @@ execute.sort.each do |c|
|
|
29
57
|
next if e.class != Module && e.class != Class
|
30
58
|
|
31
59
|
meths = e.methods(false).sort
|
60
|
+
next if meths.any? { |a| e.method(a).arity > 0 }
|
32
61
|
|
33
62
|
if meths.length > 0
|
34
63
|
if MARKDOWN
|
35
64
|
puts "### LinuxStat::#{c}\n```"
|
65
|
+
elsif HTML
|
66
|
+
puts "<h3>LinuxStat::#{c}</h3>\n<pre>"
|
36
67
|
else
|
37
68
|
puts "\e[1;4;38;2;255;240;0mLinuxStat::#{c}\e[0m"
|
38
69
|
end
|
@@ -49,6 +80,8 @@ execute.sort.each do |c|
|
|
49
80
|
|
50
81
|
if MARKDOWN
|
51
82
|
puts "#{e}.#{meth}\n=> #{dis}"
|
83
|
+
elsif HTML
|
84
|
+
puts "#{e}.#{meth}\n=> #{dis}"
|
52
85
|
else
|
53
86
|
puts "\e[1;38;2;80;80;255m#{e}.#{meth}\e[0m\n=> #{dis}"
|
54
87
|
end
|
@@ -66,5 +99,10 @@ execute.sort.each do |c|
|
|
66
99
|
puts
|
67
100
|
end
|
68
101
|
|
69
|
-
|
102
|
+
meths.length > 0
|
103
|
+
if MARKDOWN
|
104
|
+
puts "```\n\n"
|
105
|
+
elsif HTML
|
106
|
+
puts "</pre>"
|
107
|
+
end
|
70
108
|
end
|
data/ext/fs_stat/extconf.rb
CHANGED
data/ext/fs_stat/fs_stat.c
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
#include <sys/statvfs.h>
|
2
2
|
#include "ruby.h"
|
3
|
+
#pragma GCC optimize ("O3")
|
4
|
+
#pragma clang optimize on
|
3
5
|
|
4
6
|
static VALUE statfs(VALUE obj, VALUE dir) {
|
5
7
|
struct statvfs buf ;
|
@@ -8,21 +10,22 @@ static VALUE statfs(VALUE obj, VALUE dir) {
|
|
8
10
|
|
9
11
|
if(statvfs(d, &buf) < 0) return hash ;
|
10
12
|
|
11
|
-
rb_hash_aset(hash, ID2SYM(rb_intern("block_size")),
|
12
|
-
rb_hash_aset(hash, ID2SYM(rb_intern("fragment_size")),
|
13
|
-
rb_hash_aset(hash, ID2SYM(rb_intern("blocks")),
|
14
|
-
rb_hash_aset(hash, ID2SYM(rb_intern("block_free")),
|
15
|
-
rb_hash_aset(hash, ID2SYM(rb_intern("block_avail_unpriv")),
|
16
|
-
rb_hash_aset(hash, ID2SYM(rb_intern("inodes")),
|
17
|
-
rb_hash_aset(hash, ID2SYM(rb_intern("free_inodes")),
|
18
|
-
rb_hash_aset(hash, ID2SYM(rb_intern("filesystem_id")),
|
19
|
-
rb_hash_aset(hash, ID2SYM(rb_intern("mount_flags")),
|
20
|
-
rb_hash_aset(hash, ID2SYM(rb_intern("max_filename_length")),
|
13
|
+
rb_hash_aset(hash, ID2SYM(rb_intern("block_size")), INT2FIX(buf.f_bsize)) ;
|
14
|
+
rb_hash_aset(hash, ID2SYM(rb_intern("fragment_size")), INT2FIX(buf.f_frsize)) ;
|
15
|
+
rb_hash_aset(hash, ID2SYM(rb_intern("blocks")), INT2FIX(buf.f_blocks)) ;
|
16
|
+
rb_hash_aset(hash, ID2SYM(rb_intern("block_free")), INT2FIX(buf.f_bfree)) ;
|
17
|
+
rb_hash_aset(hash, ID2SYM(rb_intern("block_avail_unpriv")), INT2FIX(buf.f_bavail)) ;
|
18
|
+
rb_hash_aset(hash, ID2SYM(rb_intern("inodes")), INT2FIX(buf.f_files)) ;
|
19
|
+
rb_hash_aset(hash, ID2SYM(rb_intern("free_inodes")), INT2FIX(buf.f_ffree)) ;
|
20
|
+
rb_hash_aset(hash, ID2SYM(rb_intern("filesystem_id")), INT2FIX(buf.f_fsid)) ;
|
21
|
+
rb_hash_aset(hash, ID2SYM(rb_intern("mount_flags")), INT2FIX(buf.f_flag)) ;
|
22
|
+
rb_hash_aset(hash, ID2SYM(rb_intern("max_filename_length")), INT2FIX(buf.f_namemax)) ;
|
21
23
|
|
22
24
|
return hash ;
|
23
25
|
}
|
24
26
|
|
25
27
|
void Init_fs_stat() {
|
26
|
-
VALUE
|
28
|
+
VALUE _linux_stat = rb_define_module("LinuxStat") ;
|
29
|
+
VALUE fs = rb_define_module_under(_linux_stat, "FS") ;
|
27
30
|
rb_define_module_function(fs, "stat", statfs, 1) ;
|
28
31
|
}
|
@@ -0,0 +1,53 @@
|
|
1
|
+
#include <unistd.h>
|
2
|
+
#include "ruby.h"
|
3
|
+
|
4
|
+
static VALUE getTick(VALUE obj) {
|
5
|
+
return INT2FIX(sysconf(_SC_CLK_TCK)) ;
|
6
|
+
}
|
7
|
+
|
8
|
+
static VALUE getChildMax(VALUE obj) {
|
9
|
+
return INT2FIX(sysconf(_SC_CHILD_MAX)) ;
|
10
|
+
}
|
11
|
+
|
12
|
+
static VALUE getHostnameMax(VALUE obj) {
|
13
|
+
return INT2FIX(sysconf(_SC_HOST_NAME_MAX)) ;
|
14
|
+
}
|
15
|
+
|
16
|
+
static VALUE getLoginNameMax(VALUE obj) {
|
17
|
+
return INT2FIX(sysconf(_SC_LOGIN_NAME_MAX)) ;
|
18
|
+
}
|
19
|
+
|
20
|
+
static VALUE getOpenMax(VALUE obj) {
|
21
|
+
return INT2FIX(sysconf(_SC_OPEN_MAX)) ;
|
22
|
+
}
|
23
|
+
|
24
|
+
static VALUE getPageSizeMax(VALUE obj) {
|
25
|
+
return INT2FIX(sysconf(_SC_PAGESIZE)) ;
|
26
|
+
}
|
27
|
+
|
28
|
+
static VALUE getStreamMax(VALUE obj) {
|
29
|
+
return INT2FIX(sysconf(_SC_STREAM_MAX)) ;
|
30
|
+
}
|
31
|
+
|
32
|
+
static VALUE getTTYNameMax(VALUE obj) {
|
33
|
+
return INT2FIX(sysconf(_SC_TTY_NAME_MAX)) ;
|
34
|
+
}
|
35
|
+
|
36
|
+
static VALUE getPosixVersion(VALUE obj) {
|
37
|
+
return INT2FIX(sysconf(_SC_VERSION)) ;
|
38
|
+
}
|
39
|
+
|
40
|
+
void Init_sysconf() {
|
41
|
+
VALUE _linux_stat = rb_define_module("LinuxStat") ;
|
42
|
+
VALUE _sysconf = rb_define_module_under(_linux_stat, "Sysconf") ;
|
43
|
+
|
44
|
+
rb_define_module_function(_sysconf, "sc_clk_tck", getTick, 0) ;
|
45
|
+
rb_define_module_function(_sysconf, "child_max", getChildMax, 0) ;
|
46
|
+
rb_define_module_function(_sysconf, "hostname_max", getHostnameMax, 0) ;
|
47
|
+
rb_define_module_function(_sysconf, "login_name_max", getLoginNameMax, 0) ;
|
48
|
+
rb_define_module_function(_sysconf, "open_max", getOpenMax, 0) ;
|
49
|
+
rb_define_module_function(_sysconf, "page_size_max", getPageSizeMax, 0) ;
|
50
|
+
rb_define_module_function(_sysconf, "stream_max", getStreamMax, 0) ;
|
51
|
+
rb_define_module_function(_sysconf, "tty_name_max", getTTYNameMax, 0) ;
|
52
|
+
rb_define_module_function(_sysconf, "posix_version", getPosixVersion, 0) ;
|
53
|
+
}
|
@@ -0,0 +1,49 @@
|
|
1
|
+
#include <sys/utsname.h>
|
2
|
+
#include "ruby.h"
|
3
|
+
#pragma GCC optimize ("O3")
|
4
|
+
#pragma clang optimize on
|
5
|
+
|
6
|
+
static struct utsname buf ;
|
7
|
+
static short status ;
|
8
|
+
|
9
|
+
void init_buf() {
|
10
|
+
status = uname(&buf) ;
|
11
|
+
}
|
12
|
+
|
13
|
+
static VALUE getSysname(VALUE obj) {
|
14
|
+
VALUE sysname = status < 0 ? rb_str_new_cstr("") : rb_str_new_cstr(buf.sysname) ;
|
15
|
+
return sysname ;
|
16
|
+
}
|
17
|
+
|
18
|
+
static VALUE getNodename(VALUE obj) {
|
19
|
+
VALUE nodename = status < 0 ? rb_str_new_cstr("") : rb_str_new_cstr(buf.nodename) ;
|
20
|
+
return nodename ;
|
21
|
+
}
|
22
|
+
|
23
|
+
static VALUE getRelease(VALUE obj) {
|
24
|
+
VALUE release = status < 0 ? rb_str_new_cstr("") : rb_str_new_cstr(buf.release) ;
|
25
|
+
return release ;
|
26
|
+
}
|
27
|
+
|
28
|
+
static VALUE getVersion(VALUE obj) {
|
29
|
+
VALUE version = status < 0 ? rb_str_new_cstr("") : rb_str_new_cstr(buf.version) ;
|
30
|
+
return version ;
|
31
|
+
}
|
32
|
+
|
33
|
+
static VALUE getMachine(VALUE obj) {
|
34
|
+
VALUE machine = status < 0 ? rb_str_new_cstr("") : rb_str_new_cstr(buf.machine) ;
|
35
|
+
return machine ;
|
36
|
+
}
|
37
|
+
|
38
|
+
void Init_utsname() {
|
39
|
+
init_buf() ;
|
40
|
+
|
41
|
+
VALUE _linux_stat = rb_define_module("LinuxStat") ;
|
42
|
+
VALUE _uname = rb_define_module_under(_linux_stat, "Uname") ;
|
43
|
+
|
44
|
+
rb_define_module_function(_uname, "sysname", getSysname, 0) ;
|
45
|
+
rb_define_module_function(_uname, "nodename", getNodename, 0) ;
|
46
|
+
rb_define_module_function(_uname, "release", getRelease, 0) ;
|
47
|
+
rb_define_module_function(_uname, "version", getVersion, 0) ;
|
48
|
+
rb_define_module_function(_uname, "machine", getMachine, 0) ;
|
49
|
+
}
|
data/lib/linux_stat.rb
CHANGED
@@ -2,12 +2,19 @@ require "linux_stat/version"
|
|
2
2
|
require "linux_stat/battery"
|
3
3
|
require "linux_stat/bios"
|
4
4
|
require "linux_stat/cpu"
|
5
|
-
require "linux_stat/kernel"
|
6
5
|
require "linux_stat/memory"
|
7
6
|
require "linux_stat/net"
|
7
|
+
|
8
|
+
require 'linux_stat/utsname'
|
8
9
|
require "linux_stat/os"
|
10
|
+
|
9
11
|
require "linux_stat/process"
|
10
12
|
require "linux_stat/swap"
|
11
13
|
require "linux_stat/mounts"
|
14
|
+
|
12
15
|
require "linux_stat/fs_stat"
|
13
16
|
require "linux_stat/filesystem"
|
17
|
+
|
18
|
+
require "linux_stat/sysconf"
|
19
|
+
require "linux_stat/kernel"
|
20
|
+
require "linux_stat/process_info"
|
data/lib/linux_stat/battery.rb
CHANGED
@@ -9,7 +9,7 @@ module LinuxStat
|
|
9
9
|
end
|
10
10
|
|
11
11
|
# Returns the details of the battery.
|
12
|
-
#If the battery is not present it will return an empty Hash.
|
12
|
+
# If the battery is not present it will return an empty Hash.
|
13
13
|
def stat
|
14
14
|
st = status.downcase
|
15
15
|
return {} unless present?
|
@@ -27,7 +27,7 @@ module LinuxStat
|
|
27
27
|
end
|
28
28
|
|
29
29
|
# Returns the model of the battery.
|
30
|
-
#If the battery is not present or the information isn't available it will return an empty String.
|
30
|
+
# If the battery is not present or the information isn't available it will return an empty String.
|
31
31
|
def model
|
32
32
|
return ''.freeze unless model_readable?
|
33
33
|
IO.read(File.join(PATH, 'model_name')).tap(&:strip!)
|
data/lib/linux_stat/bios.rb
CHANGED
@@ -3,9 +3,10 @@ module LinuxStat
|
|
3
3
|
class << self
|
4
4
|
# Returns the model of the BIOS.
|
5
5
|
# If the information is not available it will return a frozen empty string.
|
6
|
-
#
|
6
|
+
#
|
7
|
+
# The output is also cached (memoized) ; as changing the value in runtime is unexpected.
|
7
8
|
def model
|
8
|
-
#
|
9
|
+
# cached (memoized) ; as changing the value in runtime is unexpected
|
9
10
|
@@model ||= if File.readable?('/sys/devices/virtual/dmi/id/product_name')
|
10
11
|
IO.read('/sys/devices/virtual/dmi/id/product_name').tap(&:strip!)
|
11
12
|
elsif File.readable?('/sys/firmware/devicetree/base/model')
|
@@ -17,9 +18,10 @@ module LinuxStat
|
|
17
18
|
|
18
19
|
# Returns the vendor of the BIOS.
|
19
20
|
# If the information is not available it will return a frozen empty string.
|
20
|
-
#
|
21
|
+
#
|
22
|
+
# The output is also cached (memoized) ; as changing the value in runtime is unexpected.
|
21
23
|
def vendor
|
22
|
-
#
|
24
|
+
# cached (memoized) ; as changing the value in runtime is unexpected
|
23
25
|
@@vendor ||= if File.readable?('/sys/devices/virtual/dmi/id/bios_vendor')
|
24
26
|
IO.read('/sys/devices/virtual/dmi/id/bios_vendor').tap(&:strip!)
|
25
27
|
else
|
@@ -29,7 +31,8 @@ module LinuxStat
|
|
29
31
|
|
30
32
|
# Returns the version of the BIOS.
|
31
33
|
# If the information is not available it will return a frozen empty string.
|
32
|
-
#
|
34
|
+
#
|
35
|
+
# The output is also cached (memoized) ; as changing the value in runtime is unexpected.
|
33
36
|
def version
|
34
37
|
@@version ||= if File.readable?('/sys/devices/virtual/dmi/id/bios_version')
|
35
38
|
IO.read('/sys/devices/virtual/dmi/id/bios_version').tap(&:strip!)
|
@@ -40,7 +43,8 @@ module LinuxStat
|
|
40
43
|
|
41
44
|
# Returns the date of the BIOS.
|
42
45
|
# If the information is not available it will return a frozen empty string.
|
43
|
-
#
|
46
|
+
#
|
47
|
+
# The output is also cached (memoized) ; as changing the value in runtime is unexpected.
|
44
48
|
def date
|
45
49
|
@@date ||= if File.readable?('/sys/devices/virtual/dmi/id/bios_date')
|
46
50
|
IO.read('/sys/devices/virtual/dmi/id/bios_date').tap(&:strip!)
|
data/lib/linux_stat/cpu.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
module LinuxStat
|
2
2
|
module CPU
|
3
3
|
class << self
|
4
|
-
#
|
4
|
+
# stat(sleep = 0.075)
|
5
|
+
# Where sleep is the delay to gather the data.
|
6
|
+
# This method returns the cpu usage of all threads.
|
5
7
|
#
|
6
8
|
# The first one is aggregated CPU usage reported by the Linux kernel.
|
7
9
|
# And the consecutive ones are the real core usages.
|
@@ -17,7 +19,14 @@ module LinuxStat
|
|
17
19
|
sleep(sleep)
|
18
20
|
data2 = IO.readlines('/proc/stat').select! { |x| x[/^cpu\d*/] }.map! { |x| x.split.map!(&:to_f) }
|
19
21
|
|
20
|
-
|
22
|
+
# On devices like android, the core count can change anytime.
|
23
|
+
# I had crashes on Termux.
|
24
|
+
# So better just count the min number of CPU and iterate over that
|
25
|
+
# If data.length is smaller than data2.length, we don't have enough data to compare.
|
26
|
+
dl, d2l = data.length, data2.length
|
27
|
+
min = dl > d2l ? d2l : dl
|
28
|
+
|
29
|
+
min.times.reduce({}) do |h, x|
|
21
30
|
user, nice, sys, idle, iowait, irq, softirq, steal = *data[x].drop(1)
|
22
31
|
user2, nice2, sys2, idle2, iowait2, irq2, softirq2, steal2 = *data2[x].drop(1)
|
23
32
|
|
@@ -30,7 +39,10 @@ module LinuxStat
|
|
30
39
|
end
|
31
40
|
end
|
32
41
|
|
33
|
-
#
|
42
|
+
# total_usage(sleep = 0.075)
|
43
|
+
# Where sleep is the delay to gather the data.
|
44
|
+
# This method returns the cpu usage of all threads.
|
45
|
+
#
|
34
46
|
# It's like running LinuxStat::CPU.stat[0] but it's much more efficient and calculates just the aggregated usage which is available at the top of the /proc/stat file.
|
35
47
|
#
|
36
48
|
# If the information is not available, it will return nil.
|
@@ -58,7 +70,8 @@ module LinuxStat
|
|
58
70
|
|
59
71
|
# Returns the model of processor.
|
60
72
|
# If the information isn't available, it will return en empty string.
|
61
|
-
#
|
73
|
+
#
|
74
|
+
# The output is also cached (memoized) ; as changing the value in runtime is unexpected.
|
62
75
|
def model
|
63
76
|
@@name ||= cpuinfo.find { |x| x.start_with?('model name') }.to_s.split(?:)[-1].to_s.strip
|
64
77
|
end
|
@@ -67,14 +80,26 @@ module LinuxStat
|
|
67
80
|
# If the information isn't available, it will return an empty array.
|
68
81
|
def cur_freq
|
69
82
|
@@cpu_freqs ||= Dir["/sys/devices/system/cpu/cpu[0-9]*/cpufreq/scaling_cur_freq"]
|
70
|
-
@@
|
83
|
+
@@cur_freqs_readable ||= @@cpu_freqs.all?(&File.method(:readable?))
|
84
|
+
|
85
|
+
if @@cur_freqs_readable
|
86
|
+
@@cpu_freqs.map { |x| IO.read(x).to_i }
|
87
|
+
else
|
88
|
+
[]
|
89
|
+
end
|
71
90
|
end
|
72
91
|
|
73
92
|
# Returns an array with max core frequencies corresponding to the usages.
|
74
93
|
# If the information isn't available, it will return an empty array.
|
75
94
|
def max_freq
|
76
95
|
@@max_freqs ||= Dir["/sys/devices/system/cpu/cpu[0-9]*/cpufreq/scaling_max_freq"]
|
77
|
-
@@
|
96
|
+
@@max_freqs_readable ||= @@max_freqs.all?(&File.method(:readable?))
|
97
|
+
|
98
|
+
if @@max_freqs_readable
|
99
|
+
@@max_freqs.map { |x| IO.read(x).to_i }
|
100
|
+
else
|
101
|
+
[]
|
102
|
+
end
|
78
103
|
end
|
79
104
|
|
80
105
|
alias usages stat
|
@@ -1,9 +1,5 @@
|
|
1
|
-
# require 'linux_stat/fs_stat'
|
2
|
-
|
3
1
|
module LinuxStat
|
4
2
|
module Filesystem
|
5
|
-
extend FS
|
6
|
-
|
7
3
|
class << self
|
8
4
|
# stat(fs = '/')
|
9
5
|
# Where fs is the directory of the file system (like / or /tmp/ or /run/media/thumbdrive).
|
@@ -14,10 +10,9 @@ module LinuxStat
|
|
14
10
|
# 3. used space (in kilobytes)
|
15
11
|
#
|
16
12
|
# In a hash format:
|
17
|
-
#
|
13
|
+
# {:total=>119981191168, :free=>43155574784, :used=>76825616384, :available=>43155574784}
|
18
14
|
#
|
19
15
|
# If the stat can't be acquired, this method will return an empty Hash.
|
20
|
-
|
21
16
|
def stat(fs = ?/.freeze)
|
22
17
|
s = stat_raw(fs)
|
23
18
|
return {} if s.empty?
|
@@ -26,11 +21,11 @@ module LinuxStat
|
|
26
21
|
{
|
27
22
|
total: s[:block_size] * s[:blocks],
|
28
23
|
free: s[:block_size] * s[:block_free],
|
29
|
-
used: s[:blocks].-(s[:block_free]) * s[:block_size]
|
24
|
+
used: s[:blocks].-(s[:block_free]) * s[:block_size]
|
30
25
|
}
|
31
26
|
end
|
32
27
|
|
33
|
-
#
|
28
|
+
# total(fs = '/')
|
34
29
|
# Where fs is the directory of the file system (like / or /tmp/ or /run/media/thumbdrive).
|
35
30
|
# It returns the total size of a given disk in bytes.
|
36
31
|
#
|
@@ -42,7 +37,7 @@ module LinuxStat
|
|
42
37
|
s[:block_size] * s[:blocks]
|
43
38
|
end
|
44
39
|
|
45
|
-
#
|
40
|
+
# free(fs = '/')
|
46
41
|
# Where fs is the directory of the file system (like / or /tmp/ or /run/media/thumbdrive).
|
47
42
|
# It returns the total free space in a disk in bytes.
|
48
43
|
# It is to be noted that free is not same as available.
|
@@ -56,7 +51,7 @@ module LinuxStat
|
|
56
51
|
s[:block_size] * s[:block_free]
|
57
52
|
end
|
58
53
|
|
59
|
-
#
|
54
|
+
# used(fs = '/')
|
60
55
|
# Where fs is the directory of the file system (like / or /tmp/ or /run/media/thumbdrive).
|
61
56
|
# It returns the used space of a given disk in bytes.
|
62
57
|
#
|
@@ -68,7 +63,7 @@ module LinuxStat
|
|
68
63
|
s[:blocks].-(s[:block_free]) * s[:block_size]
|
69
64
|
end
|
70
65
|
|
71
|
-
#
|
66
|
+
# available(fs = '/')
|
72
67
|
# Where fs is the directory of the file system (like / or /tmp/ or /run/media/thumbdrive).
|
73
68
|
# It returns the total free space in a disk in bytes.
|
74
69
|
# It is to be noted that free is not same as available.
|
@@ -82,15 +77,15 @@ module LinuxStat
|
|
82
77
|
s[:block_size] * s[:block_avail_unpriv]
|
83
78
|
end
|
84
79
|
|
85
|
-
#
|
80
|
+
# stat_raw(fs = '/')
|
86
81
|
# Where fs is the directory of the file system (like / or /tmp/ or /run/media/thumbdrive).
|
87
82
|
#
|
88
83
|
# It returns a Hash with the following data (for example):
|
89
|
-
#
|
84
|
+
# {:block_size=>4096, :fragment_size=>4096, :blocks=>29292283, :block_free=>10535967, :block_avail_unpriv=>10535967, :inodes=>58612160, :free_inodes=>56718550, :filesystem_id=>2050, :mount_flags=>1024, :max_filename_length=>255}
|
90
85
|
#
|
91
86
|
# If the stat can't be acquired, this method will return an empty Hash.
|
92
|
-
def stat_raw(fs =
|
93
|
-
FS.stat(fs)
|
87
|
+
def stat_raw(fs = ?/.freeze)
|
88
|
+
LinuxStat::FS.stat(fs)
|
94
89
|
end
|
95
90
|
end
|
96
91
|
end
|