linux_stat 0.3.1 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -6
- data/ext/fs_stat/fs_stat.c +12 -10
- data/ext/utsname/extconf.rb +7 -0
- data/ext/utsname/utsname.c +29 -0
- data/lib/linux_stat/filesystem.rb +6 -8
- data/lib/linux_stat/kernel.rb +2 -0
- data/lib/linux_stat/os.rb +20 -3
- data/lib/linux_stat/version.rb +1 -1
- data/lib/linux_stat.rb +4 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a392f3c04781b05bb96636a882b6e69143bef15befb094f980c7b542923e0649
|
4
|
+
data.tar.gz: 4ef67fa10ab4210090790b368852cac7deee99965560b201f136f0cd093e9a87
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 816e423f9a22797022d87a347dbcde20277d0b1d6fa8cc90001367cbdf2012e625400c2a659bbbd308fcf58363c19f2af88ec39d5bcc1fa04ccd4f61d77371b7
|
7
|
+
data.tar.gz: dfae97ea5bd4ef7c0daa4c784d7d951b915121753d8b61363624aaaa12e9559968e623638004accb8438a77b820913e726856e166bd437f1073047b936a83ba1
|
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# LinuxStat
|
2
|
-
![logo](https://raw.githubusercontent.com/Souravgoswami/linux_stat/master/
|
2
|
+
![logo](https://raw.githubusercontent.com/Souravgoswami/linux_stat/master/images/logo.jpg)
|
3
3
|
|
4
4
|
For reading the HTML version, visit [linux_stat](https://souravgoswami.github.io/linux_stat/).
|
5
5
|
|
@@ -312,18 +312,23 @@ If some error is *raised* it should be reported as a bug.
|
|
312
312
|
1. Just add `gem linux_stat`:
|
313
313
|
|
314
314
|
```
|
315
|
-
bundle add linux_stat
|
315
|
+
$ bundle add linux_stat
|
316
316
|
```
|
317
317
|
|
318
318
|
You can use LinuxStat directly in rails.
|
319
319
|
|
320
|
-
![RailsApp](https://raw.githubusercontent.com/Souravgoswami/linux_stat/master/
|
320
|
+
![RailsApp](https://raw.githubusercontent.com/Souravgoswami/linux_stat/master/images/rails.gif)
|
321
321
|
|
322
|
-
Don't need to worry about versions if you are using anything > 0.2.1.
|
323
322
|
|
324
|
-
|
323
|
+
## Android
|
325
324
|
|
326
|
-
|
325
|
+
LinuxStat does support Android OS. But it's not rigorously tested on all device like android apps.
|
326
|
+
|
327
|
+
But in Termux you can just run LinuxStat without facing issues.
|
328
|
+
|
329
|
+
![termux](https://raw.githubusercontent.com/Souravgoswami/linux_stat/master/images/termux.webp)
|
330
|
+
|
331
|
+
Issues regarding running LinuxStat on termux are also welcomed.
|
327
332
|
|
328
333
|
## Development
|
329
334
|
|
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,16 +10,16 @@ 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
|
}
|
@@ -0,0 +1,29 @@
|
|
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 getMachine(VALUE obj) {
|
14
|
+
VALUE machine = status < 0 ? rb_str_new_cstr("") : rb_str_new_cstr(buf.machine) ;
|
15
|
+
return machine ;
|
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
|
+
void Init_utsname() {
|
24
|
+
init_buf() ;
|
25
|
+
|
26
|
+
VALUE _uname = rb_define_module("Uname") ;
|
27
|
+
rb_define_module_function(_uname, "machine", getMachine, 0) ;
|
28
|
+
rb_define_module_function(_uname, "nodename", getNodename, 0) ;
|
29
|
+
}
|
@@ -1,8 +1,6 @@
|
|
1
|
-
# require 'linux_stat/fs_stat'
|
2
|
-
|
3
1
|
module LinuxStat
|
4
2
|
module Filesystem
|
5
|
-
|
3
|
+
prepend FS
|
6
4
|
|
7
5
|
class << self
|
8
6
|
# stat(fs = '/')
|
@@ -29,7 +27,7 @@ module LinuxStat
|
|
29
27
|
}
|
30
28
|
end
|
31
29
|
|
32
|
-
#
|
30
|
+
# total(fs = '/')
|
33
31
|
# Where fs is the directory of the file system (like / or /tmp/ or /run/media/thumbdrive).
|
34
32
|
# It returns the total size of a given disk in bytes.
|
35
33
|
#
|
@@ -41,7 +39,7 @@ module LinuxStat
|
|
41
39
|
s[:block_size] * s[:blocks]
|
42
40
|
end
|
43
41
|
|
44
|
-
#
|
42
|
+
# free(fs = '/')
|
45
43
|
# Where fs is the directory of the file system (like / or /tmp/ or /run/media/thumbdrive).
|
46
44
|
# It returns the total free space in a disk in bytes.
|
47
45
|
# It is to be noted that free is not same as available.
|
@@ -55,7 +53,7 @@ module LinuxStat
|
|
55
53
|
s[:block_size] * s[:block_free]
|
56
54
|
end
|
57
55
|
|
58
|
-
#
|
56
|
+
# used(fs = '/')
|
59
57
|
# Where fs is the directory of the file system (like / or /tmp/ or /run/media/thumbdrive).
|
60
58
|
# It returns the used space of a given disk in bytes.
|
61
59
|
#
|
@@ -67,7 +65,7 @@ module LinuxStat
|
|
67
65
|
s[:blocks].-(s[:block_free]) * s[:block_size]
|
68
66
|
end
|
69
67
|
|
70
|
-
#
|
68
|
+
# available(fs = '/')
|
71
69
|
# Where fs is the directory of the file system (like / or /tmp/ or /run/media/thumbdrive).
|
72
70
|
# It returns the total free space in a disk in bytes.
|
73
71
|
# It is to be noted that free is not same as available.
|
@@ -81,7 +79,7 @@ module LinuxStat
|
|
81
79
|
s[:block_size] * s[:block_avail_unpriv]
|
82
80
|
end
|
83
81
|
|
84
|
-
#
|
82
|
+
# stat_raw(fs = '/')
|
85
83
|
# Where fs is the directory of the file system (like / or /tmp/ or /run/media/thumbdrive).
|
86
84
|
#
|
87
85
|
# It returns a Hash with the following data (for example):
|
data/lib/linux_stat/kernel.rb
CHANGED
data/lib/linux_stat/os.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
module LinuxStat
|
2
2
|
module OS
|
3
|
+
prepend Uname
|
4
|
+
|
3
5
|
class << self
|
4
6
|
# Reads /etc/os-release and returns a Hash. For example:
|
5
7
|
# {:NAME=>"Arch Linux", :PRETTY_NAME=>"Arch Linux", :ID=>"arch", :BUILD_ID=>"rolling", :ANSI_COLOR=>"38;2;23;147;209", :HOME_URL=>"https://www.archlinux.org/", :DOCUMENTATION_URL=>"https://wiki.archlinux.org/", :SUPPORT_URL=>"https://bbs.archlinux.org/", :BUG_REPORT_URL=>"https://bugs.archlinux.org/", :LOGO=>"archlinux"}
|
@@ -51,6 +53,18 @@ module LinuxStat
|
|
51
53
|
end
|
52
54
|
end
|
53
55
|
|
56
|
+
# Uses utsname.h to determine the machine
|
57
|
+
# It returns a String but if the info isn't available, it will return an empty String
|
58
|
+
def machine
|
59
|
+
@@machine ||= Uname.machine
|
60
|
+
end
|
61
|
+
|
62
|
+
# Uses utsname.h to determine the system nodename
|
63
|
+
# It returns String but if the info isn't available, it will return an empty String
|
64
|
+
def nodename
|
65
|
+
@@nodename ||= Uname.nodename
|
66
|
+
end
|
67
|
+
|
54
68
|
# Reads /etc/hostname and returns the hostname.
|
55
69
|
# The return type is String.
|
56
70
|
# If the info info isn't available, it will return 'localhost'.
|
@@ -62,10 +76,13 @@ module LinuxStat
|
|
62
76
|
end
|
63
77
|
end
|
64
78
|
|
65
|
-
# Reads ruby configuration and tries to guess if the system is
|
66
|
-
#
|
79
|
+
# Reads ruby configuration and tries to guess if the system is 64 bit.
|
80
|
+
# If it fails then it runs utsname.h to guess the machine.
|
81
|
+
# It the machine is 64 bits, it will return 64, else it returns 32.
|
82
|
+
#
|
83
|
+
# The return type is strictly Integer and doesn't fail.
|
67
84
|
def bits
|
68
|
-
@@bits ||= if RbConfig::CONFIG['host_cpu'].end_with?('64') || RUBY_PLATFORM
|
85
|
+
@@bits ||= if RbConfig::CONFIG['host_cpu'].end_with?('64') || RUBY_PLATFORM.end_with?('64') || machine.end_with?('64')
|
69
86
|
64
|
70
87
|
else
|
71
88
|
32
|
data/lib/linux_stat/version.rb
CHANGED
data/lib/linux_stat.rb
CHANGED
@@ -5,9 +5,13 @@ require "linux_stat/cpu"
|
|
5
5
|
require "linux_stat/kernel"
|
6
6
|
require "linux_stat/memory"
|
7
7
|
require "linux_stat/net"
|
8
|
+
|
9
|
+
require 'linux_stat/utsname'
|
8
10
|
require "linux_stat/os"
|
11
|
+
|
9
12
|
require "linux_stat/process"
|
10
13
|
require "linux_stat/swap"
|
11
14
|
require "linux_stat/mounts"
|
15
|
+
|
12
16
|
require "linux_stat/fs_stat"
|
13
17
|
require "linux_stat/filesystem"
|
metadata
CHANGED
@@ -1,20 +1,21 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: linux_stat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sourav Goswami
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-12-
|
11
|
+
date: 2020-12-03 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Efficient linux system reporting gem. Linux Only | Efficient | Reliable
|
14
14
|
email:
|
15
15
|
- souravgoswami@protonmail.com
|
16
16
|
executables: []
|
17
17
|
extensions:
|
18
|
+
- ext/utsname/extconf.rb
|
18
19
|
- ext/fs_stat/extconf.rb
|
19
20
|
extra_rdoc_files:
|
20
21
|
- README.md
|
@@ -25,6 +26,8 @@ files:
|
|
25
26
|
- bin/setup
|
26
27
|
- ext/fs_stat/extconf.rb
|
27
28
|
- ext/fs_stat/fs_stat.c
|
29
|
+
- ext/utsname/extconf.rb
|
30
|
+
- ext/utsname/utsname.c
|
28
31
|
- lib/linux_stat.rb
|
29
32
|
- lib/linux_stat/battery.rb
|
30
33
|
- lib/linux_stat/bios.rb
|