linux_stat 0.1.4 → 0.3.1
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 +208 -77
- data/bin/console +2 -12
- data/{run_all_methods.rb → bin/linuxstat.rb} +27 -10
- data/ext/fs_stat/extconf.rb +7 -0
- data/ext/fs_stat/fs_stat.c +28 -0
- data/lib/linux_stat.rb +3 -6
- data/lib/linux_stat/battery.rb +24 -1
- data/lib/linux_stat/bios.rb +12 -2
- data/lib/linux_stat/cpu.rb +42 -13
- data/lib/linux_stat/filesystem.rb +96 -0
- data/lib/linux_stat/kernel.rb +97 -14
- data/lib/linux_stat/memory.rb +23 -5
- data/lib/linux_stat/mounts.rb +64 -0
- data/lib/linux_stat/net.rb +3 -1
- data/lib/linux_stat/os.rb +33 -2
- data/lib/linux_stat/process.rb +14 -0
- data/lib/linux_stat/swap.rb +37 -4
- data/lib/linux_stat/version.rb +1 -1
- metadata +12 -15
- data/.gitignore +0 -11
- data/.rspec +0 -3
- data/.travis.yml +0 -6
- data/CODE_OF_CONDUCT.md +0 -74
- data/Gemfile +0 -7
- data/Gemfile.lock +0 -34
- data/LICENSE.txt +0 -21
- data/Rakefile +0 -6
- data/linux_stat.gemspec +0 -28
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 918383341aa375e1414e08c13b38829373caa174c64769541955180ce9d6e09c
|
4
|
+
data.tar.gz: b821c81eee9bf5c9061057ab653e336adbbeaacf51d9b4141e6a1d72073058b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 580b5af4a00f4b2078e2d7cf9e249ba9648a5ab5965fe26c15f73c0cb843eeae6470e00d28fb096100f7b5445e47fcdce354c713c3aff4139fcb8a53221d68f0
|
7
|
+
data.tar.gz: 6ebaa17fd1aaf45910a297df8b992e495e3f8c594c2b69181bdd1c9536bb2be40a8ad4fb569f4be076aac1eaf70fc0d86d7930eedde79615db6ffcfcb498dc50
|
data/README.md
CHANGED
@@ -1,9 +1,31 @@
|
|
1
1
|
# LinuxStat
|
2
|
+

|
2
3
|
|
3
|
-
|
4
|
+
For reading the HTML version, visit [linux_stat](https://souravgoswami.github.io/linux_stat/).
|
5
|
+
|
6
|
+
LinuxStat lets you read status of a Linux system. It can show you cpu stats and usages, memory stats and usages, swap stats and usages, battery usage, bios info, kernel details, local ip, os details and parse os-release + lsb-release, etc.
|
4
7
|
|
5
8
|
It only works for Linux, and detecting the OS is upto the user of this gem.
|
6
9
|
|
10
|
+
## Dependencies:
|
11
|
+
+ You need to have the C compile to be able to compile the C extension.
|
12
|
+
On Arch Linux:
|
13
|
+
```
|
14
|
+
# pacman -S gcc
|
15
|
+
```
|
16
|
+
|
17
|
+
On Debian based systems:
|
18
|
+
```
|
19
|
+
# apt install gcc
|
20
|
+
```
|
21
|
+
|
22
|
+
+ You might also require ruby-dev in Debian based systems which provides support for ruby.h header file:
|
23
|
+
```
|
24
|
+
# apt install ruby-dev
|
25
|
+
```
|
26
|
+
|
27
|
+
+ Once your are done, and you can compile the C file, you can follow the installation!
|
28
|
+
|
7
29
|
## Installation
|
8
30
|
|
9
31
|
Add this line to your application's Gemfile:
|
@@ -23,22 +45,25 @@ Or install it yourself as:
|
|
23
45
|
## Usage
|
24
46
|
### LinuxStat::BIOS
|
25
47
|
```
|
48
|
+
LinuxStat::BIOS.date
|
49
|
+
=> "04/10/2017"
|
50
|
+
|
26
51
|
LinuxStat::BIOS.model
|
27
|
-
=> Inspiron 5567
|
52
|
+
=> "Inspiron 5567"
|
28
53
|
|
29
54
|
LinuxStat::BIOS.vendor
|
30
|
-
=> Dell Inc.
|
31
|
-
|
32
|
-
LinuxStat::BIOS.date
|
33
|
-
=> 04/10/2017
|
55
|
+
=> "Dell Inc."
|
34
56
|
|
35
57
|
LinuxStat::BIOS.version
|
36
|
-
=> 1.1.2
|
58
|
+
=> "1.1.2"
|
37
59
|
|
38
60
|
```
|
39
61
|
|
40
62
|
### LinuxStat::Battery
|
41
63
|
```
|
64
|
+
LinuxStat::Battery.charge
|
65
|
+
=> 100.0
|
66
|
+
|
42
67
|
LinuxStat::Battery.charging?
|
43
68
|
=> true
|
44
69
|
|
@@ -48,8 +73,11 @@ LinuxStat::Battery.discharging?
|
|
48
73
|
LinuxStat::Battery.full?
|
49
74
|
=> true
|
50
75
|
|
51
|
-
LinuxStat::Battery.
|
52
|
-
=>
|
76
|
+
LinuxStat::Battery.manufacturer
|
77
|
+
=> "Samsung SDI"
|
78
|
+
|
79
|
+
LinuxStat::Battery.model
|
80
|
+
=> "DELL CYMGM77"
|
53
81
|
|
54
82
|
LinuxStat::Battery.present?
|
55
83
|
=> true
|
@@ -57,17 +85,11 @@ LinuxStat::Battery.present?
|
|
57
85
|
LinuxStat::Battery.stat
|
58
86
|
=> {:model=>"DELL CYMGM77", :manufacturer=>"Samsung SDI", :technology=>"Li-ion", :status=>"Full", :charge=>100.0, :charging=>true, :discharging=>false, :full=>true}
|
59
87
|
|
60
|
-
LinuxStat::Battery.
|
61
|
-
=>
|
62
|
-
|
63
|
-
LinuxStat::Battery.manufacturer
|
64
|
-
=> Samsung SDI
|
88
|
+
LinuxStat::Battery.status
|
89
|
+
=> "Full"
|
65
90
|
|
66
91
|
LinuxStat::Battery.technology
|
67
|
-
=> Li-ion
|
68
|
-
|
69
|
-
LinuxStat::Battery.charge
|
70
|
-
=> 100.0
|
92
|
+
=> "Li-ion"
|
71
93
|
|
72
94
|
```
|
73
95
|
|
@@ -76,62 +98,121 @@ LinuxStat::Battery.charge
|
|
76
98
|
LinuxStat::CPU.count
|
77
99
|
=> 4
|
78
100
|
|
79
|
-
LinuxStat::CPU.stat
|
80
|
-
=> {0=>3.33, 1=>0.0, 2=>0.0, 3=>0.0, 4=>12.5}
|
81
|
-
|
82
|
-
LinuxStat::CPU.model
|
83
|
-
=> Intel(R) Core(TM) i3-6006U CPU @ 2.00GHz
|
84
|
-
|
85
101
|
LinuxStat::CPU.cur_freq
|
86
|
-
=> [
|
102
|
+
=> [1998722, 1998401, 1974377, 1875264]
|
87
103
|
|
88
104
|
LinuxStat::CPU.max_freq
|
89
105
|
=> [2000000, 2000000, 2000000, 2000000]
|
90
106
|
|
107
|
+
LinuxStat::CPU.model
|
108
|
+
=> "Intel(R) Core(TM) i3-6006U CPU @ 2.00GHz"
|
109
|
+
|
110
|
+
LinuxStat::CPU.stat
|
111
|
+
=> {0=>6.45, 1=>0.0, 2=>0.0, 3=>12.5, 4=>0.0}
|
112
|
+
|
113
|
+
LinuxStat::CPU.total_usage
|
114
|
+
=> 3.45
|
115
|
+
|
116
|
+
LinuxStat::CPU.usage
|
117
|
+
=> 6.45
|
118
|
+
|
119
|
+
LinuxStat::CPU.usages
|
120
|
+
=> {0=>9.68, 1=>11.11, 2=>12.5, 3=>14.29, 4=>12.5}
|
121
|
+
|
122
|
+
```
|
123
|
+
|
124
|
+
### LinuxStat::Filesystem
|
125
|
+
```
|
126
|
+
LinuxStat::Filesystem.available
|
127
|
+
=> 43155402752
|
128
|
+
|
129
|
+
LinuxStat::Filesystem.free
|
130
|
+
=> 43155402752
|
131
|
+
|
132
|
+
LinuxStat::Filesystem.stat
|
133
|
+
=> {:total=>119981191168, :free=>43155402752, :used=>76825788416}
|
134
|
+
|
135
|
+
LinuxStat::Filesystem.stat_raw
|
136
|
+
=> {:block_size=>4096, :fragment_size=>4096, :blocks=>29292283, :block_free=>10535987, :block_avail_unpriv=>10535987, :inodes=>58612160, :free_inodes=>56718515, :filesystem_id=>2050, :mount_flags=>1024, :max_filename_length=>255}
|
137
|
+
|
138
|
+
LinuxStat::Filesystem.total
|
139
|
+
=> 119981191168
|
140
|
+
|
141
|
+
LinuxStat::Filesystem.used
|
142
|
+
=> 76825788416
|
143
|
+
|
91
144
|
```
|
92
145
|
|
93
146
|
### LinuxStat::Kernel
|
94
147
|
```
|
148
|
+
LinuxStat::Kernel.build_date
|
149
|
+
=> 2020-10-21 01:11:20 +0000
|
150
|
+
|
151
|
+
LinuxStat::Kernel.build_date_string
|
152
|
+
=> "21 Oct 2020 01:11:20 +0000"
|
153
|
+
|
154
|
+
LinuxStat::Kernel.build_user
|
155
|
+
=> "souravgoswami@archlinux"
|
156
|
+
|
95
157
|
LinuxStat::Kernel.compiler
|
96
158
|
=> [:gcc, "10.2.0"]
|
97
159
|
|
98
|
-
LinuxStat::Kernel.
|
99
|
-
=>
|
160
|
+
LinuxStat::Kernel.compiler_version
|
161
|
+
=> "10.2.0"
|
100
162
|
|
101
|
-
LinuxStat::Kernel.
|
102
|
-
=>
|
163
|
+
LinuxStat::Kernel.string
|
164
|
+
=> "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"
|
103
165
|
|
104
166
|
LinuxStat::Kernel.version
|
105
|
-
=> 5.9.1-xanmod1-1
|
167
|
+
=> "5.9.1-xanmod1-1"
|
106
168
|
|
107
169
|
```
|
108
170
|
|
109
171
|
### LinuxStat::Memory
|
110
172
|
```
|
173
|
+
LinuxStat::Memory.available
|
174
|
+
=> 403724
|
175
|
+
|
111
176
|
LinuxStat::Memory.percent_available
|
112
|
-
=>
|
177
|
+
=> 10.52
|
178
|
+
|
179
|
+
LinuxStat::Memory.percent_used
|
180
|
+
=> 89.48
|
113
181
|
|
114
182
|
LinuxStat::Memory.stat
|
115
|
-
=> {:total=>
|
183
|
+
=> {:total=>3836264, :used=>3432540, :available=>403724, :percent_used=>89.48, :percent_available=>10.52}
|
116
184
|
|
117
185
|
LinuxStat::Memory.total
|
118
|
-
=>
|
119
|
-
|
120
|
-
LinuxStat::Memory.available
|
121
|
-
=> 595444
|
186
|
+
=> 3836264
|
122
187
|
|
123
188
|
LinuxStat::Memory.used
|
124
|
-
=>
|
189
|
+
=> 3432540
|
125
190
|
|
126
|
-
|
127
|
-
|
191
|
+
```
|
192
|
+
|
193
|
+
### LinuxStat::Mounts
|
194
|
+
```
|
195
|
+
LinuxStat::Mounts.list
|
196
|
+
=> ["proc /proc proc rw,nosuid,nodev,noexec,relatime 0 0", "sys /sys sysfs rw,nosuid,nodev,noexec,relatime 0 0", "dev /dev devtmpfs rw,nosuid,relatime,size=1891796k,nr_inodes=472949,mode=755 0 0", "run /run tmpfs rw,nosuid,nodev,relatime,mode=755 0 0", "...
|
197
|
+
|
198
|
+
LinuxStat::Mounts.root
|
199
|
+
=> "/dev/sda2"
|
200
|
+
|
201
|
+
LinuxStat::Mounts.root_fs
|
202
|
+
=> "xfs"
|
203
|
+
|
204
|
+
LinuxStat::Mounts.root_mount_options
|
205
|
+
=> "rw,noatime,attr2,inode64,logbufs=8,logbsize=32k,noquota"
|
206
|
+
|
207
|
+
LinuxStat::Mounts.tmpfs
|
208
|
+
=> {"/dev/shm"=>"tmpfs /dev/shm tmpfs rw,nosuid,nodev 0 0", "/sys/fs/cgroup"=>"tmpfs /sys/fs/cgroup tmpfs ro,nosuid,nodev,noexec,size=4096k,nr_inodes=1024,mode=755 0 0", "/ramdisk"=>"tmpfs /ramdisk tmpfs rw,nosuid,nodev,relatime,size=6291456k 0 0", "/tmp...
|
128
209
|
|
129
210
|
```
|
130
211
|
|
131
212
|
### LinuxStat::Net
|
132
213
|
```
|
133
214
|
LinuxStat::Net.ipv4_private
|
134
|
-
=> 192.168.0.106
|
215
|
+
=> "192.168.0.106"
|
135
216
|
|
136
217
|
```
|
137
218
|
|
@@ -140,91 +221,141 @@ LinuxStat::Net.ipv4_private
|
|
140
221
|
LinuxStat::OS.bits
|
141
222
|
=> 64
|
142
223
|
|
143
|
-
LinuxStat::OS.
|
144
|
-
=>
|
224
|
+
LinuxStat::OS.distribution
|
225
|
+
=> "Arch Linux"
|
145
226
|
|
146
|
-
LinuxStat::OS.
|
147
|
-
=>
|
227
|
+
LinuxStat::OS.hostname
|
228
|
+
=> "archlinux"
|
148
229
|
|
149
230
|
LinuxStat::OS.lsb_release
|
150
231
|
=> {:LSB_VERSION=>"1.4", :DISTRIB_ID=>"Arch", :DISTRIB_RELEASE=>"rolling", :DISTRIB_DESCRIPTION=>"Arch Linux"}
|
151
232
|
|
152
|
-
LinuxStat::OS.
|
153
|
-
=> archlinux
|
233
|
+
LinuxStat::OS.os_release
|
234
|
+
=> {: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/"...
|
154
235
|
|
155
|
-
LinuxStat::OS.
|
156
|
-
=>
|
236
|
+
LinuxStat::OS.uptime
|
237
|
+
=> {:hour=>10, :minute=>54, :second=>22.45}
|
157
238
|
|
158
239
|
```
|
159
240
|
|
160
241
|
### LinuxStat::Process
|
161
242
|
```
|
162
243
|
LinuxStat::Process.count
|
163
|
-
=>
|
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...
|
244
|
+
=> 210
|
170
245
|
|
171
246
|
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,
|
247
|
+
=> [3, 4, 6, 9, 12, 23, 30, 37, 39, 49, 102, 103, 104, 106, 107, 108, 109, 110, 117, 118, 119, 122, 131, 134, 140, 152, 153, 179, 181, 183, 184, 191, 192, 193, 194, 195, 196, 198, 236, 286, 314, 324, 346, 385, 3540, 3541, 3542, 3543, 3544, 3545, 30463, 3...
|
173
248
|
|
174
249
|
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,
|
250
|
+
=> [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, 122, 131, 134,...
|
251
|
+
|
252
|
+
LinuxStat::Process.names
|
253
|
+
=> {1=>"systemd", 2=>"kthreadd", 3=>"rcu_gp", 4=>"rcu_par_gp", 6=>"kworker/0:0H-events_highpri", 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...
|
254
|
+
|
255
|
+
LinuxStat::Process.running
|
256
|
+
=> [33736]
|
176
257
|
|
177
258
|
LinuxStat::Process.sleeping
|
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,
|
259
|
+
=> [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, 178, 180, 197, 225, 239, 309, 317, 329, 332, 333, 334, 338, 367, 368, 369, 370, 378, 381, 383, 384, 402,...
|
260
|
+
|
261
|
+
LinuxStat::Process.types
|
262
|
+
=> {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...
|
179
263
|
|
180
264
|
LinuxStat::Process.zombie
|
181
265
|
=> []
|
182
266
|
|
183
|
-
LinuxStat::Process.running
|
184
|
-
=> [32117]
|
185
|
-
|
186
267
|
```
|
187
268
|
|
188
269
|
### LinuxStat::Swap
|
189
270
|
```
|
271
|
+
LinuxStat::Swap.any?
|
272
|
+
=> true
|
273
|
+
|
274
|
+
LinuxStat::Swap.available
|
275
|
+
=> 1913936
|
276
|
+
|
277
|
+
LinuxStat::Swap.list
|
278
|
+
=> {"/dev/zram0"=>[:partition, 4194300, 2280364, -2]}
|
279
|
+
|
190
280
|
LinuxStat::Swap.percent_available
|
191
|
-
=>
|
281
|
+
=> 45.63
|
282
|
+
|
283
|
+
LinuxStat::Swap.percent_used
|
284
|
+
=> 54.37
|
192
285
|
|
193
286
|
LinuxStat::Swap.stat
|
194
|
-
=> {:total=>4194300, :used=>
|
287
|
+
=> {:total=>4194300, :used=>2280364, :available=>1913936, :percent_used=>54.37, :percent_available=>45.63}
|
195
288
|
|
196
289
|
LinuxStat::Swap.total
|
197
290
|
=> 4194300
|
198
291
|
|
199
|
-
LinuxStat::Swap.
|
200
|
-
=>
|
292
|
+
LinuxStat::Swap.used
|
293
|
+
=> 2280364
|
201
294
|
|
202
|
-
|
203
|
-
=> 2854972
|
295
|
+
```
|
204
296
|
|
205
|
-
|
206
|
-
|
297
|
+
## Return Types
|
298
|
+
+ In general, if a method returns either a Float or a Integer or a Time, it will return a Float or Integer or Time in all cases. But if the status isn't available, it will return nil.
|
207
299
|
|
208
|
-
|
209
|
-
|
300
|
+
+ If the method returns a Hash / Array, it will return return Hash / Array in all cases. If the status isn't available, it will return an empty Hash / Array.
|
301
|
+
|
302
|
+
+ If the method returns a String, it will return return String in all cases. If the status isn't available, it will return an empty *frozen* String.
|
303
|
+
|
304
|
+
+ It doesn't have implementation of any Error that gets raised in runtime for the ease of use.
|
305
|
+
|
306
|
+
+ If you need to check some stat that returns an integer or float, and you get nil, you know it's not available, so you can work accordingly. But if you need the integer or float value in 0 to whatever format, you can use the .to_i or .to_f method on the object, nil will get converted to number then.
|
307
|
+
|
308
|
+
If some error is *raised* it should be reported as a bug.
|
309
|
+
|
310
|
+
## Ruby on Rails
|
311
|
+
|
312
|
+
1. Just add `gem linux_stat`:
|
210
313
|
|
211
314
|
```
|
315
|
+
bundle add linux_stat
|
316
|
+
```
|
317
|
+
|
318
|
+
You can use LinuxStat directly in rails.
|
212
319
|
|
320
|
+

|
321
|
+
|
322
|
+
Don't need to worry about versions if you are using anything > 0.2.1.
|
323
|
+
|
324
|
+
Newer versions will have bug fixes, performance improvements and new features but the return types of old methods will always be the same across upgrades > 0.2.1.
|
325
|
+
|
326
|
+
Even if we remove something, there will be always a deprecation warning for some months or for even a year before we actually remove it.
|
213
327
|
|
214
328
|
## Development
|
215
329
|
|
216
|
-
After checking out the repo, run `bin/setup` to install dependencies.
|
330
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
217
331
|
|
218
332
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
219
333
|
|
334
|
+
## Testing
|
335
|
+
Like other gems, this doesn't have a test like RSpec. We suggest using the bin/linuxstat.rb file on various systems.
|
336
|
+
If you need to test a specific module, say the CPU, just run it like this:
|
337
|
+
|
338
|
+
```
|
339
|
+
$ ruby bin/linuxstat.rb CPU
|
340
|
+
```
|
341
|
+
|
342
|
+
Or:
|
343
|
+
```
|
344
|
+
$ ruby bin/linuxstat.rb cpu
|
345
|
+
```
|
346
|
+
|
347
|
+
That is, the argument passed is not case-sensitive.
|
348
|
+
But if the argument passed isn't available and outright wrong, it will run all the module methods. For example, you can't do:
|
349
|
+
|
350
|
+
```
|
351
|
+
$ ruby bin/linuxstat.rb upc
|
352
|
+
```
|
353
|
+
This is not a valid module and can't be run.
|
354
|
+
|
220
355
|
## Contributing
|
221
356
|
|
222
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
357
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/Souravgoswami/linux_stat.
|
223
358
|
|
224
359
|
## License
|
225
360
|
|
226
361
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
227
|
-
|
228
|
-
## Code of Conduct
|
229
|
-
|
230
|
-
Everyone interacting in the LinuxStat project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/linux_stat/blob/master/CODE_OF_CONDUCT.md).
|
data/bin/console
CHANGED
@@ -1,14 +1,4 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
|
4
|
-
require "linux_stat"
|
5
|
-
|
6
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
-
# with your gem easier. You can also use a different console, if you like.
|
8
|
-
|
9
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
# require "pry"
|
11
|
-
# Pry.start
|
12
|
-
|
13
|
-
require "irb"
|
2
|
+
$-v = true
|
3
|
+
%w(bundler/setup linux_stat irb).each(&method(:require))
|
14
4
|
IRB.start(__FILE__)
|
@@ -1,6 +1,10 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'linux_stat'
|
2
|
+
begin
|
3
|
+
require 'linux_stat'
|
4
|
+
rescue LoadError
|
5
|
+
require 'bundler/setup'
|
6
|
+
require 'linux_stat'
|
7
|
+
end
|
4
8
|
|
5
9
|
$-v = true
|
6
10
|
|
@@ -8,7 +12,18 @@ $-v = true
|
|
8
12
|
MARKDOWN = ARGV.any? { |x| x[/^\-\-markdown$/] || x[/^\-md$/] }
|
9
13
|
PRINT_TIME = MARKDOWN ? false : !ARGV.any? { |x| x[/^\-\-no-time$/] || x[/^\-nt$/] }
|
10
14
|
|
11
|
-
|
15
|
+
%w(--markdown -md --no-time -nt).each(&ARGV.method(:delete))
|
16
|
+
|
17
|
+
# Run only desired classes / modules
|
18
|
+
constants = LinuxStat.constants
|
19
|
+
|
20
|
+
execute = constants.map(&:downcase).map.with_index { |x, i|
|
21
|
+
constants[i] if ARGV.find { |y| y.downcase.to_sym == x }
|
22
|
+
}.compact
|
23
|
+
|
24
|
+
execute.replace(constants) if execute.empty?
|
25
|
+
|
26
|
+
execute.sort.each do |c|
|
12
27
|
e = eval("LinuxStat::#{c}")
|
13
28
|
|
14
29
|
next if e.class != Module && e.class != Class
|
@@ -25,25 +40,27 @@ LinuxStat.constants.sort.each do |c|
|
|
25
40
|
|
26
41
|
meths.each do |meth|
|
27
42
|
time = Time.now
|
28
|
-
v = e.send(meth)
|
29
|
-
|
43
|
+
v = e.send(meth)
|
44
|
+
time2 = Time.now
|
45
|
+
time = time2.-(time).*(1_000_000).round(3)
|
30
46
|
|
47
|
+
v = v.inspect
|
31
48
|
dis = v.length > 253 ? v[0..250].strip + '...'.freeze : v
|
32
49
|
|
33
50
|
if MARKDOWN
|
34
|
-
puts "#{e}.#{meth}\n=> #{dis
|
51
|
+
puts "#{e}.#{meth}\n=> #{dis}"
|
35
52
|
else
|
36
53
|
puts "\e[1;38;2;80;80;255m#{e}.#{meth}\e[0m\n=> #{dis}"
|
37
54
|
end
|
38
55
|
|
39
56
|
puts( "(" +
|
40
|
-
if time >
|
41
|
-
"\e[1;38;2;255;
|
42
|
-
elsif time >
|
57
|
+
if time > 10_000
|
58
|
+
"\e[1;38;2;255;50;50m"
|
59
|
+
elsif time > 5_000
|
43
60
|
"\e[1;38;2;255;170;0m"
|
44
61
|
else
|
45
62
|
"\e[1;38;2;0;170;0m"
|
46
|
-
end + "Time taken: #{time}
|
63
|
+
end + "Time taken: #{time}\u03BCs\e[0m)"
|
47
64
|
) if PRINT_TIME
|
48
65
|
|
49
66
|
puts
|