linux_stat 1.2.3 → 1.3.0

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: 4b3270fb4ddf3dd436a63233d134f5fecd2ff13d7aa0d4f91b444ac65ed29b84
4
- data.tar.gz: 8f4987b804b866eb6b0bea4a9de1a507e6529ca6188d54b0def59a7dbf74c73f
3
+ metadata.gz: 58652553450c8570d4e9d1137256e8b27155bf7f61f2bd89f423f3eb3e6fd907
4
+ data.tar.gz: d90289e14f856823d2370d7a0629769d874d8f630043c1cce0fd3c357ca12f1b
5
5
  SHA512:
6
- metadata.gz: fd9393533d03fbfe16599d972762aaa6d84aa737de9ceccd7a4b333a3e049742e2a088f29364203dfd5e65199c95ccc790a68d31e8c8cf6c5f6fd718dc655818
7
- data.tar.gz: b4fbe848f72fe1d51ed8c3d8bba37aba8a1da937c4f1639503dedbb894fc8eebe6516c7c8957e88569b73362d03dfd4a60787af1c4c585fe40b73725e2f5dabe
6
+ metadata.gz: 4ee5142e8a10b2f4171aac6901b9cb98d9ca9ef74738e39f7b4dfca15381ee6c4a40c0815bb957476250958d207d21e8759266c3c7229af510b189d4ec7d758f
7
+ data.tar.gz: 454c9d051de0a49156e421a1c866e4b690fd6d98bdcb714acabb18d6b5e13c1ae29b1bb1035b75962e1e47f9a7094b6a5bde46742e54212aac427103f56308d4
data/README.md CHANGED
@@ -854,6 +854,30 @@ LinuxStat::Sysconf.tty_name_max()
854
854
 
855
855
  ```
856
856
 
857
+ ### LinuxStat::Thermal
858
+ ```
859
+ # File: thermal.rb | Line: 57
860
+ # Definition: def count_fans
861
+ LinuxStat::Thermal.count_fans()
862
+ => 1
863
+
864
+ # File: thermal.rb | Line: 49
865
+ # Definition: def count_sensors
866
+ LinuxStat::Thermal.count_sensors()
867
+ => 8
868
+
869
+ # File: thermal.rb | Line: 41
870
+ # Definition: def fans
871
+ LinuxStat::Thermal.fans()
872
+ => [{:path=>"/sys/class/hwmon/hwmon4", :name=>"dell_smm", :label=>"Processor Fan", :rpm=>0}]
873
+
874
+ # File: thermal.rb | Line: 23
875
+ # Definition: def temperatures
876
+ LinuxStat::Thermal.temperatures()
877
+ => [{:path=>"/sys/class/hwmon/hwmon4", :name=>"dell_smm", :label=>"SODIMM", :temperature=>36.0}, {:path=>"/sys/class/hwmon/hwmon4", :name=>"dell_smm", :label=>"CPU", :temperature=>46.0}, {:path=>"/sys/class/hwmon/hwmon4", :name=>"dell_smm", :label=>"Ambi...
878
+
879
+ ```
880
+
857
881
  ### LinuxStat::USB
858
882
  ```
859
883
  # File: usb.rb | Line: 135
@@ -28,6 +28,7 @@ require "linux_stat/net"
28
28
  require "linux_stat/pci"
29
29
  require "linux_stat/process"
30
30
  require "linux_stat/swap"
31
+ require "linux_stat/thermal"
31
32
  require "linux_stat/usb"
32
33
 
33
34
  # Dependent Modules
@@ -1,4 +1,6 @@
1
1
  module LinuxStat
2
+ # Shows various battery related information of the current system.
3
+
2
4
  module Battery
3
5
  PATH = "/sys/class/power_supply/BAT0".freeze
4
6
 
@@ -1,4 +1,6 @@
1
1
  module LinuxStat
2
+ # Shows various BIOS related information of the current system.
3
+
2
4
  module BIOS
3
5
  class << self
4
6
  ##
@@ -1,4 +1,6 @@
1
1
  module LinuxStat
2
+ # Shows various CPU related information of the current system.
3
+
2
4
  module CPU
3
5
  class << self
4
6
  ##
@@ -1,4 +1,6 @@
1
1
  module LinuxStat
2
+ # Shows various Filesystem related information of the current system.
3
+
2
4
  module Filesystem
3
5
  class << self
4
6
  ##
@@ -1,4 +1,6 @@
1
1
  module LinuxStat
2
+ # Shows various Kernel related information of the current system.
3
+
2
4
  module Kernel
3
5
  class << self
4
6
  ##
@@ -1,4 +1,6 @@
1
1
  module LinuxStat
2
+ # Shows various Memory related information of the current system.
3
+
2
4
  module Memory
3
5
  class << self
4
6
  ##
@@ -1,4 +1,6 @@
1
1
  module LinuxStat
2
+ # Shows various Mounted device related information of the current system.
3
+
2
4
  module Mounts
3
5
  class << self
4
6
  ##
@@ -1,4 +1,6 @@
1
1
  module LinuxStat
2
+ # Shows various Net related information of the current system.
3
+
2
4
  module Net
3
5
  class << self
4
6
  DEV = '/proc/net/dev'.freeze
@@ -1,4 +1,6 @@
1
1
  module LinuxStat
2
+ # Shows various OS related information of the current system.
3
+
2
4
  module OS
3
5
  class << self
4
6
  ##
@@ -1,4 +1,6 @@
1
1
  module LinuxStat
2
+ # Shows various PCI device related information of the current system.
3
+
2
4
  module PCI
3
5
  class << self
4
6
  ##
@@ -1,4 +1,11 @@
1
1
  module LinuxStat
2
+ # Helps you convert bytes to a unit like:
3
+ #
4
+ # 1. kilobyte, megabyte, gigabyte, terabyte, petabyte, exabyte, zettabyte, yottabyte
5
+ # 2. kibibyte, mebibyte, gibibyte, tebibyte, pebibyte, exbibyte, zebibyte, yobibyte
6
+ # 3. kB, MB, GB, TB, PB, EB, ZB, YB
7
+ # 4. kiB, MiB, GiB, TiB, PiB, EiB, ZiB, YiB
8
+
2
9
  module PrettifyBytes
3
10
  class << self
4
11
  ##
@@ -1,4 +1,7 @@
1
1
  module LinuxStat
2
+ # Shows various information about a process that is either
3
+ # running, sleeping, idle or a zombie.
4
+
2
5
  module Process
3
6
  class << self
4
7
  ##
@@ -1,4 +1,11 @@
1
1
  module LinuxStat
2
+ # Shows various information about a process that is either
3
+ # running, sleeping, idle or a zombie.
4
+ # Most methods can take a PID, but some uses polling to calculate
5
+ # something, they can accept options instead of arguments.
6
+ # Consult the documentation on the specific methods
7
+ # for more details on that.
8
+
2
9
  module ProcessInfo
3
10
  class << self
4
11
  ##
@@ -1,4 +1,6 @@
1
1
  module LinuxStat
2
+ # Shows various Swap devices related information of the current system.
3
+
2
4
  module Swap
3
5
  class << self
4
6
  ##
@@ -0,0 +1,122 @@
1
+ module LinuxStat
2
+ # Sensors are available to /sys/class/hwmon
3
+ # This module just reads the files inside them to get the sensor information.
4
+ #
5
+ # https://www.kernel.org/doc/Documentation/thermal/sysfs-api.txt
6
+
7
+ module Thermal
8
+ class << self
9
+ ##
10
+ # Get temperatures from all sensors.
11
+ #
12
+ # The return value is an Array of Hashes.
13
+ #
14
+ # It opens various files from /sys/, and it should be
15
+ # considered very slow.
16
+ #
17
+ # Each hash may contain information including:
18
+ #
19
+ # path, name, label
20
+ # temperature, temp_crit, temp_max
21
+ #
22
+ # But if the info isn't available, it will return an empty Array.
23
+ def temperatures
24
+ query_hwmon('temp'.freeze, :temperature, true)
25
+ end
26
+
27
+ ##
28
+ # Get RPM from all fans.
29
+ #
30
+ # The return value is an Array of Hashes.
31
+ #
32
+ # It opens various files from /sys/, and it should be
33
+ # considered very slow.
34
+ #
35
+ # Each hash may contain information including:
36
+ #
37
+ # path, name, label
38
+ # rpm, temp_crit, temp_max
39
+ #
40
+ # But if the info isn't available, it will return an empty Array.
41
+ def fans
42
+ query_hwmon('fan'.freeze, :rpm)
43
+ end
44
+
45
+ ##
46
+ # Counts the number of sensors (fans are not counted)
47
+ #
48
+ # The return type is an Integer.
49
+ def count_sensors
50
+ return 0 unless hwmon_readable?
51
+
52
+ Dir["/sys/class/hwmon/hwmon[0-9]*/temp[0-9]*_input".freeze].size
53
+ end
54
+
55
+ ##
56
+ # Counts the number of fans (sensors are not counted)
57
+ #
58
+ # The return type is an Integer.
59
+ def count_fans
60
+ return 0 unless hwmon_readable?
61
+
62
+ Dir["/sys/class/hwmon/hwmon[0-9]*/fan[0-9]*_input".freeze].size
63
+ end
64
+
65
+ private
66
+ def hwmon_readable?
67
+ @@hwmon_readable ||= File.readable?("/sys/class/hwmon/")
68
+ end
69
+
70
+ def query_hwmon(mon, key, div = false)
71
+ return [] unless hwmon_readable?
72
+
73
+ name = dir = ''.freeze
74
+
75
+ files = Dir["/sys/class/hwmon/hwmon[0-9]*/#{mon}[0-9]*_input".freeze]
76
+ i = -1
77
+ ret = []
78
+
79
+ while x = files[i += 1]
80
+ splitted = File.split(x)
81
+ path = File.join(splitted[0..-2])
82
+
83
+ n = splitted[-1][/.*_/]
84
+
85
+ label_f = "#{path}/#{n}label"
86
+ label = File.readable?(label_f) ? IO.read(label_f, encoding: 'ASCII-8BIT'.freeze).strip : nil
87
+
88
+ temp_crit_f = "#{path}/#{n}crit"
89
+ temp_crit = File.readable?(temp_crit_f) ? IO.read(temp_crit_f, encoding: 'ASCII-8BIT'.freeze).to_i : nil
90
+
91
+ temp_max_f = "#{path}/#{n}max"
92
+ temp_max = File.readable?(temp_max_f) ? IO.read(temp_max_f, encoding: 'ASCII-8BIT'.freeze).to_i : nil
93
+
94
+ value = File.readable?(x) ? IO.read(x).to_i : nil
95
+
96
+ if dir != path
97
+ dir = path
98
+ name_f = "#{path}/name"
99
+ name = File.readable?(name_f) ? IO.read(name_f, encoding: 'ASCII-8BIT'.freeze).tap(&:strip!) : ''.freeze
100
+ end
101
+
102
+ if div
103
+ value /= 1000.0
104
+ temp_max /= 1000.0 if temp_max
105
+ temp_crit /= 1000.0 if temp_crit
106
+ end
107
+
108
+ h = {path: path, name: name}
109
+
110
+ h.merge!(label: label) if label
111
+ h.merge!(key => value)
112
+ h.merge!(temp_crit: temp_crit) if temp_crit
113
+ h.merge!(temp_crit: temp_max) if temp_max
114
+
115
+ ret.push(h)
116
+ end
117
+
118
+ ret
119
+ end
120
+ end
121
+ end
122
+ end
@@ -1,4 +1,6 @@
1
1
  module LinuxStat
2
+ # Shows various USB device related information of the current system.
3
+
2
4
  module USB
3
5
  class << self
4
6
  ##
@@ -1,4 +1,6 @@
1
1
  module LinuxStat
2
+ # Shows various User related information of the current system.
3
+
2
4
  module User
3
5
  class << self
4
6
  ##
@@ -1,3 +1,3 @@
1
1
  module LinuxStat
2
- VERSION ||= "1.2.3"
2
+ VERSION ||= "1.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: linux_stat
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.3
4
+ version: 1.3.0
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-29 00:00:00.000000000 Z
11
+ date: 2020-12-31 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Linux only, efficient linux system utilization reporting and system monitoring
14
14
  gem
@@ -52,6 +52,7 @@ files:
52
52
  - lib/linux_stat/process.rb
53
53
  - lib/linux_stat/process_info.rb
54
54
  - lib/linux_stat/swap.rb
55
+ - lib/linux_stat/thermal.rb
55
56
  - lib/linux_stat/usb.rb
56
57
  - lib/linux_stat/user.rb
57
58
  - lib/linux_stat/version.rb