linux_stat 0.1.2 → 0.1.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 835e9c5295067665b9d84eaa365e653c6134322b22cac05581dc2e1970d1879c
4
- data.tar.gz: 5c9dbda4caa34f4a608d13d4d9545b4c78c1e8fc4c2886cf199fa83679415dc6
3
+ metadata.gz: 48d667ee1df458052019071ea8b1991f34984e7e508ffd53ab5a10ecab8a9e39
4
+ data.tar.gz: 6a554e8a5a1a840e5dd5d2a34fef28f863da6ca083234b5ae6fcd2cde7258098
5
5
  SHA512:
6
- metadata.gz: f63387f4748c8fe55ec7bd2713c1a477b3755049e1fae91cc25c7312f15b83febbf0bb872d0e1aa59fafd390a3c45f74d9977ea44a56cd5a82bea8a52f45a73e
7
- data.tar.gz: f1b582654c0ea8842187f13d9f4ca42e021a3daad14e95b08955ba1a046ef6bc7f7d05e7aa9443fb96453ccb2f40b021deaa50f53bf5ef872075f1c12d33a8d4
6
+ metadata.gz: b7ae93e1d6f146c68f189dc34c53f5149d8dff3088e0fa5d71bc65465f497477cb17a535fd7e28bc717fcd4aa08c2afc924c3bb88e0933abf5a95d93086d1154
7
+ data.tar.gz: 813c7c545a771d42bf7f369d3bcfac8595a875510a3bbe652e106b42719d7f37c259b9fa037a467ebec88098859df0b389a0dec626379d85e83a7cfd3ea4ce0f
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- linux_stat (0.1.0)
4
+ linux_stat (0.1.3)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -21,26 +21,42 @@ Or install it yourself as:
21
21
  $ gem install linux_stat
22
22
 
23
23
  ## Usage
24
-
24
+ ### LinuxStat::BIOS
25
25
  ```
26
+ LinuxStat::BIOS.model
27
+ => Inspiron 5567
28
+
29
+ LinuxStat::BIOS.vendor
30
+ => Dell Inc.
31
+
26
32
  LinuxStat::BIOS.date
27
33
  => 04/10/2017
28
34
 
29
35
  LinuxStat::BIOS.version
30
36
  => 1.1.2
31
37
 
32
- LinuxStat::BIOS.model
33
- => Inspiron 5567
38
+ ```
34
39
 
35
- LinuxStat::BIOS.vendor
36
- => Dell Inc.
40
+ ### LinuxStat::Battery
41
+ ```
42
+ LinuxStat::Battery.charging?
43
+ => true
37
44
 
38
- LinuxStat::Battery.present?
45
+ LinuxStat::Battery.discharging?
46
+ => false
47
+
48
+ LinuxStat::Battery.full?
39
49
  => true
40
50
 
41
51
  LinuxStat::Battery.status
42
52
  => Full
43
53
 
54
+ LinuxStat::Battery.present?
55
+ => true
56
+
57
+ LinuxStat::Battery.stat
58
+ => {:model=>"DELL CYMGM77", :manufacturer=>"Samsung SDI", :technology=>"Li-ion", :status=>"Full", :charge=>100.0, :charging=>true, :discharging=>false, :full=>true}
59
+
44
60
  LinuxStat::Battery.model
45
61
  => DELL CYMGM77
46
62
 
@@ -53,77 +69,110 @@ LinuxStat::Battery.technology
53
69
  LinuxStat::Battery.charge
54
70
  => 100.0
55
71
 
56
- LinuxStat::Battery.charging?
57
- => true
58
-
59
- LinuxStat::Battery.discharging?
60
- => false
61
-
62
- LinuxStat::Battery.full?
63
- => true
64
-
65
- LinuxStat::Battery.stat
66
- => {:model=>"DELL CYMGM77", :manufacturer=>"Samsung SDI", :technology=>"Li-ion", :status=>"Full", :charge=>100.0, :charging=>true, :discharging=>false, :full=>true}
72
+ ```
67
73
 
74
+ ### LinuxStat::CPU
75
+ ```
68
76
  LinuxStat::CPU.count
69
77
  => 4
70
78
 
79
+ LinuxStat::CPU.stat
80
+ => {0=>3.33, 1=>0.0, 2=>0.0, 3=>0.0, 4=>12.5}
81
+
71
82
  LinuxStat::CPU.model
72
83
  => Intel(R) Core(TM) i3-6006U CPU @ 2.00GHz
73
84
 
74
- LinuxStat::CPU.stat
75
- => {0=>0.0, 1=>0.0, 2=>0.0, 3=>0.0, 4=>0.0}
76
-
77
85
  LinuxStat::CPU.cur_freq
78
- => [2000094, 2000072, 2000045, 2000119]
86
+ => [2000064, 2000098, 2000049, 2000091]
79
87
 
80
88
  LinuxStat::CPU.max_freq
81
89
  => [2000000, 2000000, 2000000, 2000000]
82
90
 
83
- LinuxStat::Kernel.version
84
- => 5.9.1-xanmod1-1
91
+ ```
85
92
 
86
- LinuxStat::Kernel.build_date
87
- => 2020-10-21 01:11:20 +0000
93
+ ### LinuxStat::Kernel
94
+ ```
95
+ LinuxStat::Kernel.compiler
96
+ => [:gcc, "10.2.0"]
88
97
 
89
98
  LinuxStat::Kernel.string
90
99
  => Linux version 5.9.1-xanmod1-1 (souravgoswami@archlinux) (gcc (GCC) 10.2.0, GNU ld (GNU Binutils) 2.35.1) #1 SMP PREEMPT Wed, 21 Oct 2020 01:11:20 +0000
91
100
 
92
- LinuxStat::Kernel.compiler
93
- => [:gcc, "10.2.0"]
101
+ LinuxStat::Kernel.build_date
102
+ => 2020-10-21 01:11:20 +0000
94
103
 
95
- LinuxStat::Memory.total
96
- => 3836256
104
+ LinuxStat::Kernel.version
105
+ => 5.9.1-xanmod1-1
106
+
107
+ ```
108
+
109
+ ### LinuxStat::Memory
110
+ ```
111
+ LinuxStat::Memory.percent_available
112
+ => 15.52
97
113
 
98
114
  LinuxStat::Memory.stat
99
- => {:total=>3836256, :used=>3331632, :available=>504624, :percent_used=>86.85, :percent_available=>13.15}
115
+ => {:total=>3836256, :used=>3240812, :available=>595444, :percent_used=>84.48, :percent_available=>15.52}
116
+
117
+ LinuxStat::Memory.total
118
+ => 3836256
100
119
 
101
120
  LinuxStat::Memory.available
102
- => 504624
121
+ => 595444
103
122
 
104
123
  LinuxStat::Memory.used
105
- => 3331632
124
+ => 3240812
106
125
 
107
126
  LinuxStat::Memory.percent_used
108
- => 86.85
127
+ => 84.48
109
128
 
110
- LinuxStat::Memory.percent_available
111
- => 13.15
129
+ ```
112
130
 
131
+ ### LinuxStat::Net
132
+ ```
113
133
  LinuxStat::Net.ipv4_private
114
134
  => 192.168.0.106
115
135
 
136
+ ```
137
+
138
+ ### LinuxStat::OS
139
+ ```
140
+ LinuxStat::OS.bits
141
+ => 64
142
+
143
+ LinuxStat::OS.uptime
144
+ => {:hour=>10, :minute=>42, :second=>33.85}
145
+
116
146
  LinuxStat::OS.os_release
117
147
  => {: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/"...
118
148
 
119
149
  LinuxStat::OS.lsb_release
120
150
  => {:LSB_VERSION=>"1.4", :DISTRIB_ID=>"Arch", :DISTRIB_RELEASE=>"rolling", :DISTRIB_DESCRIPTION=>"Arch Linux"}
121
151
 
122
- LinuxStat::OS.uptime
123
- => {:hour=>6, :minute=>57, :second=>37.16}
152
+ LinuxStat::OS.hostname
153
+ => archlinux
154
+
155
+ LinuxStat::OS.distribution
156
+ => Arch Linux
157
+
158
+ ```
124
159
 
160
+ ### LinuxStat::Process
161
+ ```
125
162
  LinuxStat::Process.count
126
- => 209
163
+ => 213
164
+
165
+ LinuxStat::Process.types
166
+ => {1=>:sleeping, 2=>:sleeping, 3=>:idle, 4=>:idle, 6=>:idle, 9=>:idle, 10=>:sleeping, 11=>:sleeping, 12=>:idle, 13=>:sleeping, 14=>:sleeping, 15=>:sleeping, 16=>:sleeping, 17=>:sleeping, 18=>:sleeping, 19=>:sleeping, 20=>:sleeping, 21=>:sleeping, 23=>:i...
167
+
168
+ LinuxStat::Process.names
169
+ => {1=>"systemd", 2=>"kthreadd", 3=>"rcu_gp", 4=>"rcu_par_gp", 6=>"kworker/0:0H-kblockd", 9=>"mm_percpu_wq", 10=>"ksoftirqd/0", 11=>"rcuc/0", 12=>"rcu_preempt", 13=>"rcub/0", 14=>"migration/0", 15=>"idle_inject/0", 16=>"cpuhp/0", 17=>"cpuhp/1", 18=>"idle...
170
+
171
+ LinuxStat::Process.idle
172
+ => [3, 4, 6, 9, 12, 23, 30, 37, 39, 49, 102, 103, 104, 106, 107, 108, 109, 110, 117, 118, 119, 121, 131, 134, 140, 152, 153, 168, 170, 172, 173, 177, 181, 182, 183, 184, 185, 186, 220, 225, 271, 322, 326, 329, 333, 2914, 2915, 2916, 2917, 2918, 2919, 289...
173
+
174
+ LinuxStat::Process.list
175
+ => [1, 2, 3, 4, 6, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 23, 24, 25, 26, 27, 28, 30, 31, 32, 33, 34, 35, 37, 38, 39, 40, 41, 42, 46, 47, 48, 49, 50, 51, 52, 102, 103, 104, 106, 107, 108, 109, 110, 112, 114, 115, 117, 118, 119, 121, 131, 134,...
127
176
 
128
177
  LinuxStat::Process.sleeping
129
178
  => [1, 2, 10, 11, 13, 14, 15, 16, 17, 18, 19, 20, 21, 24, 25, 26, 27, 28, 31, 32, 33, 34, 35, 38, 40, 41, 42, 46, 47, 48, 50, 51, 52, 112, 114, 115, 167, 169, 187, 214, 229, 314, 316, 317, 318, 319, 324, 325, 327, 340, 361, 362, 363, 364, 372, 375, 378,...
@@ -132,40 +181,33 @@ LinuxStat::Process.zombie
132
181
  => []
133
182
 
134
183
  LinuxStat::Process.running
135
- => [21279]
184
+ => [32117]
136
185
 
137
- LinuxStat::Process.idle
138
- => [3, 4, 6, 9, 12, 23, 30, 37, 39, 49, 102, 103, 104, 106, 107, 108, 109, 110, 117, 118, 119, 121, 131, 134, 140, 152, 153, 168, 170, 172, 173, 177, 181, 182, 183, 184, 185, 186, 220, 225, 271, 322, 326, 329, 333, 2914, 2915, 2916, 2917, 2918, 2919, 148...
139
-
140
- LinuxStat::Process.names
141
- => {1=>"systemd", 2=>"kthreadd", 3=>"rcu_gp", 4=>"rcu_par_gp", 6=>"kworker/0:0H-kblockd", 9=>"mm_percpu_wq", 10=>"ksoftirqd/0", 11=>"rcuc/0", 12=>"rcu_preempt", 13=>"rcub/0", 14=>"migration/0", 15=>"idle_inject/0", 16=>"cpuhp/0", 17=>"cpuhp/1", 18=>"idle...
186
+ ```
142
187
 
143
- LinuxStat::Process.list
144
- => [1, 2, 3, 4, 6, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 23, 24, 25, 26, 27, 28, 30, 31, 32, 33, 34, 35, 37, 38, 39, 40, 41, 42, 46, 47, 48, 49, 50, 51, 52, 102, 103, 104, 106, 107, 108, 109, 110, 112, 114, 115, 117, 118, 119, 121, 131, 134,...
188
+ ### LinuxStat::Swap
189
+ ```
190
+ LinuxStat::Swap.percent_available
191
+ => 68.07
145
192
 
146
- LinuxStat::Process.types
147
- => {1=>:sleeping, 2=>:sleeping, 3=>:idle, 4=>:idle, 6=>:idle, 9=>:idle, 10=>:sleeping, 11=>:sleeping, 12=>:idle, 13=>:sleeping, 14=>:sleeping, 15=>:sleeping, 16=>:sleeping, 17=>:sleeping, 18=>:sleeping, 19=>:sleeping, 20=>:sleeping, 21=>:sleeping, 23=>:i...
193
+ LinuxStat::Swap.stat
194
+ => {:total=>4194300, :used=>1339328, :available=>2854972, :percent_used=>31.93, :percent_available=>68.07}
148
195
 
149
196
  LinuxStat::Swap.total
150
197
  => 4194300
151
198
 
152
- LinuxStat::Swap.stat
153
- => {:total=>4194300, :used=>1236572, :available=>2957728, :percent_used=>29.48, :percent_available=>70.52}
199
+ LinuxStat::Swap.list
200
+ => {"/dev/zram0"=>[:partition, 4194300, 1339328, -2]}
154
201
 
155
202
  LinuxStat::Swap.available
156
- => 2957728
203
+ => 2854972
157
204
 
158
205
  LinuxStat::Swap.used
159
- => 1236572
206
+ => 1339328
160
207
 
161
208
  LinuxStat::Swap.percent_used
162
- => 29.48
209
+ => 31.93
163
210
 
164
- LinuxStat::Swap.list
165
- => {"/dev/zram0"=>[:partition, 4194300, 1236572, -2]}
166
-
167
- LinuxStat::Swap.percent_available
168
- => 70.52
169
211
  ```
170
212
 
171
213
 
@@ -11,6 +11,40 @@ module LinuxStat
11
11
  @@lsb_release ||= File.readable?('/etc/lsb-release') ? release('/etc/lsb-release') : {}
12
12
  end
13
13
 
14
+ def distribution
15
+ @@distribution ||= if os_release.key?(:NAME)
16
+ os_release[:NAME]
17
+ else
18
+ v = lsb_release
19
+
20
+ if v.key?(:DISTRIB_DESCRIPTION)
21
+ v[:DISTRIB_DESCRIPTION]
22
+ elsif v.key?(:DISTRIB_ID)
23
+ v[:DISTRIB_ID]
24
+ elsif File.readable?('/etc/issue')
25
+ IO.read('/etc/issue').strip
26
+ else
27
+ 'Unknown'.freeze
28
+ end
29
+ end
30
+ end
31
+
32
+ def hostname
33
+ @@hostname ||= if File.exist?('/etc/hostname')
34
+ IO.read('/etc/hostname').strip
35
+ else
36
+ 'localhost'
37
+ end
38
+ end
39
+
40
+ def bits
41
+ @@bits ||= if RbConfig::CONFIG['host_cpu'].end_with?('64') || RUBY_PLATFORM[/x86_64/]
42
+ 64
43
+ else
44
+ 32
45
+ end
46
+ end
47
+
14
48
  def uptime
15
49
  raise StatUnavailable, 'Cannot read /proc/uptime' unless uptime_readable?
16
50
 
@@ -39,8 +73,10 @@ module LinuxStat
39
73
  key = splitted[0].to_s.strip
40
74
  value = splitted[1..-1].join(?=).to_s.strip
41
75
 
42
- dumped = value[0] == ?" && value[-1] == ?"
43
- h.merge!( key.to_sym => dumped ? value.undump : value )
76
+ value[0] = '' if value[0] == ?"
77
+ value[-1] = '' if value[-1] == ?"
78
+
79
+ h.merge!( key.to_sym => value )
44
80
  }
45
81
  end
46
82
 
@@ -1,3 +1,3 @@
1
1
  module LinuxStat
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -10,12 +10,10 @@ Gem::Specification.new do |spec|
10
10
  spec.description = %q{Efficient linux system reporting gem. Linux Only | Efficient | Reliable}
11
11
  spec.homepage = "https://github.com/Souravgoswami/linux_stat/"
12
12
  spec.license = "MIT"
13
- spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
14
-
15
- # spec.metadata["allowed_push_host"] = "https://github.com/Souravgoswami/linux_stat'"
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
16
14
 
17
15
  spec.metadata["homepage_uri"] = spec.homepage
18
- spec.metadata["source_code_uri"] = "https://github.com/Souravgoswami/linux_stat/"
16
+ spec.metadata["source_code_uri"] = "https://github.com/Souravgoswami/linux_stat"
19
17
  spec.metadata["changelog_uri"] = "https://github.com/Souravgoswami/linux_stat/commits/master"
20
18
 
21
19
  # Specify which files should be added to the gem when it is released.
@@ -4,48 +4,51 @@ require 'linux_stat'
4
4
  require 'io/console'
5
5
 
6
6
  # Print time each method takes unless --no-time or -nt option is passed
7
- PRINT_TIME = !ARGV.any? { |x| x[/^\-\-no-time$/] || x[/^\-nt$/] }
7
+ MARKDOWN = ARGV.any? { |x| x[/^\-\-markdown$/] || x[/^\-md$/] }
8
+ PRINT_TIME = MARKDOWN ? false : !ARGV.any? { |x| x[/^\-\-no-time$/] || x[/^\-nt$/] }
8
9
 
9
10
  $-v = true
10
11
 
11
- tt = Time.now
12
- wait = 3
13
- anim_delay = wait.fdiv(STDOUT.winsize[1])
14
- anim = %w(| / - \\)
12
+ LinuxStat.constants.sort.each do |c|
13
+ e = eval("LinuxStat::#{c}")
15
14
 
16
- STDOUT.winsize[1].-(20).times do |x|
17
- t = wait - Time.now.-(tt).to_i
18
- print "\e[2K#{anim.rotate![0]} Starting test in #{t.clamp(0, wait)} #{?. * x}\r"
19
- sleep anim_delay
20
- end
15
+ next if e.class != Module && e.class != Class
21
16
 
22
- print "\e[2K"
17
+ meths = e.methods(false)
23
18
 
24
- LinuxStat.constants.sort.each do |c|
25
- e = eval("LinuxStat::#{c}")
19
+ if meths.length > 0
20
+ if MARKDOWN
21
+ puts "### LinuxStat::#{c}\n```"
22
+ else
23
+ puts "\e[1;4;38;2;255;240;0mLinuxStat::#{c}\e[0m"
24
+ end
25
+ end
26
26
 
27
- next if e.class != Module && e.class != Class
27
+ meths.each do |meth|
28
+ time = Time.now
29
+ v = e.send(meth).to_s
30
+ time = Time.now.-(time).*(1000).round(3)
28
31
 
29
- meths = e.methods(false)
32
+ dis = v.length > 253 ? v[0..250].strip + '...'.freeze : v
30
33
 
31
- meths.each do |meth|
32
- time = Time.now
33
- v = e.send(meth).to_s
34
- time = Time.now.-(time).*(1000).round(3)
34
+ if MARKDOWN
35
+ puts "#{e}.#{meth}\n=> #{dis}"
36
+ else
37
+ puts "\e[1;38;2;80;80;255m#{e}.#{meth}\e[0m\n=> #{dis}"
38
+ end
35
39
 
36
- dis = v.length > 253 ? v[0..250].strip + '...'.freeze : v
37
- puts "\e[1;38;2;80;80;255m#{e}.#{meth}\e[0m", "=> #{dis}"
40
+ puts( "(" +
41
+ if time > 10
42
+ "\e[1;38;2;255;80;80m"
43
+ elsif time > 5
44
+ "\e[1;38;2;255;170;0m"
45
+ else
46
+ "\e[1;38;2;0;170;0m"
47
+ end + "Time taken: #{time}ms\e[0m)"
48
+ ) if PRINT_TIME
38
49
 
39
- puts( "(" +
40
- if time > 10
41
- "\e[1;38;2;255;80;80m"
42
- elsif time > 5
43
- "\e[1;38;2;255;170;0m"
44
- else
45
- "\e[1;38;2;0;170;0m"
46
- end + "Time taken: #{time}ms\e[0m)"
47
- ) if PRINT_TIME
50
+ puts
51
+ end
48
52
 
49
- puts
50
- end
53
+ puts "```\n\n" if MARKDOWN && meths.length > 0
51
54
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: linux_stat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sourav Goswami
@@ -46,7 +46,7 @@ licenses:
46
46
  - MIT
47
47
  metadata:
48
48
  homepage_uri: https://github.com/Souravgoswami/linux_stat/
49
- source_code_uri: https://github.com/Souravgoswami/linux_stat/
49
+ source_code_uri: https://github.com/Souravgoswami/linux_stat
50
50
  changelog_uri: https://github.com/Souravgoswami/linux_stat/commits/master
51
51
  post_install_message:
52
52
  rdoc_options: []
@@ -56,7 +56,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
56
56
  requirements:
57
57
  - - ">="
58
58
  - !ruby/object:Gem::Version
59
- version: 2.4.0
59
+ version: 2.5.0
60
60
  required_rubygems_version: !ruby/object:Gem::Requirement
61
61
  requirements:
62
62
  - - ">="