arbi 1.0.7 → 1.0.8

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.
@@ -1,29 +0,0 @@
1
- class Ram
2
- require 'arbi/common'
3
-
4
- def get_infos
5
- mem = file_get_content('/proc/meminfo')
6
- total = mem.match(/^MemTotal:\s*?([0-9]+) kB/)[1].to_i
7
- free = mem.match(/^MemFree:\s*?([0-9]+) kB/)[1].to_i +
8
- mem.match(/^Buffers:\s*?([0-9]+) kB/)[1].to_i +
9
- mem.match(/^Cached:\s*?([0-9]+) kB/)[1].to_i
10
- perc = 100.0 / total * free
11
- {'used' => sprintf('%.1f%%', 100.0 - perc),
12
- 'free' => sprintf('%.1f%%', perc)}
13
- end
14
-
15
- def self.protocolize perc
16
- "ram:\r\n#{perc['used']}|#{perc['free']}\r\nEND\r\n"
17
- end
18
-
19
- def self.friendlize raw
20
- datas = raw.to_s.strip.split(/\r?\n/)[0].split(/\|/)
21
- "USED FREE\r\n#{datas[0].ljust(8)}#{datas[1]}"
22
- end
23
- end
24
-
25
- if __FILE__ == $0
26
- puts Ram.friendlize Ram.protocolize(Ram.new.get_infos).gsub(/^ram:\s+|END\s+$/m, '')
27
- else
28
- Arbi::add_plugin /^ram$/i, Ram.new
29
- end
@@ -1,71 +0,0 @@
1
- # encoding: utf-8
2
-
3
- class NilClass
4
- def [](*args)
5
- return self
6
- end
7
- end
8
-
9
- class Thermal
10
- require 'arbi/common'
11
-
12
- def initialize
13
- @temperatures = Hash.new
14
- @tempdirs = Dir.glob "/proc/acpi/thermal_zone/*"
15
- @tempdirs.each do |dir|
16
- trip_points = file_get_content dir + "/trip_points"
17
- name = dir.gsub(/^\/proc\/acpi\/thermal_zone\//, '')
18
- @temperatures.merge!({name => {'temperature' => file_get_content(dir + '/temperature').match(
19
- /^temperature:\s*?([0-9]{1,3}) C$/)[1],
20
- 'trip_critical' => trip_points.match(/^critical \(S5\):\s*?([0-9]{1,3}) C$/)[1],}})
21
- end
22
- end
23
-
24
- def get_infos
25
- @tempdirs.each do |dir|
26
- @temperatures[dir.gsub(/^\/proc\/acpi\/thermal_zone\//, '')]["temperature"] =
27
- file_get_content(dir + '/temperature').match(/^temperature:\s*?([0-9]{1,3}) C$/)[1]
28
- end
29
- @temperatures.merge average
30
- end
31
-
32
- def self.protocolize temperatures
33
- str = "thermal:\r\n"
34
- temperatures.each do |key, value|
35
- str += "#{key}|#{value["temperature"]}#{key == "AVERAGE" ? '' : '|' + (value["trip_critical"] || '-')}\r\n"
36
- end
37
- str += "END\r\n"
38
- end
39
-
40
- def self.friendlize raw
41
- raw = raw.to_s.strip
42
- nmax = raw.lines.map{|x|x.split(/\|/)[0].length}.max + 4
43
- tmax = [raw.lines.map{|x|x.split(/\|/)[1].length}.max + 4, 6].max
44
- str = "NAME".ljust(nmax) + "TEMP".ljust(tmax) + "CRITICAL\r\n"
45
- raw.split(/\r?\n/).each { |line|
46
- datas = line.split /\|/
47
- str << datas[0].ljust(nmax) + "#{datas[1]}°C".ljust(tmax)
48
- str << "#{datas[2]}°C" if datas[2]
49
- str << "\r\n"
50
- }
51
- str
52
- end
53
-
54
- private
55
-
56
- def average
57
- avg, n = 0, 0
58
- @temperatures.each do |value, key|
59
- avg += key["temperature"].to_i
60
- n += 1
61
- end
62
- avg = (sprintf '%.1f', (avg.to_f / n)).gsub /\.0$/, ''
63
- return ({'AVERAGE' => {'temperature' => avg, 'trip_critical' => false}})
64
- end
65
- end
66
-
67
- if __FILE__ == $0
68
- puts Thermal.friendlize Thermal.protocolize(Thermal.new.get_infos).gsub(/^thermal:\s+|END\s+$/m, '')
69
- else
70
- Arbi::add_plugin /^thermal$/i, Thermal.new
71
- end