rsensors 0.2.82
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 +7 -0
- data/bin/rsensors +68 -0
- data/lib/rsensors.rb +204 -0
- metadata +92 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4bda4f2f025e38d76c150ff9f87285bd6006e628
|
4
|
+
data.tar.gz: 525a419abaeb6c922292449e62f1f2aaeb6e06db
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0c266fd6e5ed4fe33d75819698d7afe133785488d0beaac1c0395b35778cb272f7cce3ba49179eb5f64ee3459b05dfe61d9792add1f0a0cd6326a56887349ae8
|
7
|
+
data.tar.gz: 28b3fab9601c48b4e507c2aa33502b8496cc90722c3e367db40844f600b8002a34272d3fdf56bba15f09888e2c3504f3088bd18917ea23afad671ff89bfbaae8
|
data/bin/rsensors
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
|
4
|
+
require 'rsensors'
|
5
|
+
|
6
|
+
args = ARGV.dup
|
7
|
+
max_cpu = args[1].nil? ? 76 : args[1].to_f
|
8
|
+
max_hd = args[2].nil? ? 44 : args[2].to_f # get values
|
9
|
+
cron_value = args[3].nil? ? "22,44 * * * *" : args[3].to_s
|
10
|
+
|
11
|
+
case args[0]
|
12
|
+
when 'schedule', 'programar' # not use ||
|
13
|
+
Rsensors::Cronify.schedule(max_cpu, max_hd, cron_value)
|
14
|
+
when 'job' , 'test'
|
15
|
+
Rsensors::Notification.notify if (Rsensors::Sensor.temperature > max_cpu) || (Rsensors::Sensor.maxTemperatureHd > max_hd)
|
16
|
+
when 'help' ,'ayuda'
|
17
|
+
if (/es_.*/.match(ENV["LANG"])) # detecta español en consola
|
18
|
+
puts <<EOS
|
19
|
+
Rsensors versión 0.2.8 - Software LGPL-3.0
|
20
|
+
Usar con cuidado, probado pero sin ninguna garantía
|
21
|
+
Una gema Ruby para mostrar las temperaturas del sistema: CPU(s) y disco(s) duro(s)
|
22
|
+
https://github.com/jacob-mf/rsensors
|
23
|
+
|
24
|
+
Uso:
|
25
|
+
rsensors [comando] [parámetro(s)]
|
26
|
+
|
27
|
+
Por defecto, sin ningún comando se muestra notificación con las temperaturas medidas actuales
|
28
|
+
Los parámetros [CPU] y [disco duro] representan las temperaturas límite a comparar, para CPUs y discos duros. Se introducen como números naturales en escala de grados Celsius
|
29
|
+
Si no se indican límites, se toman por defecto, 76 grados Celsius para CPUs y 44°C para discos duros
|
30
|
+
|
31
|
+
El párametro [cron] especifica la cadena de configuración de fecha y tiempo para la aplicación crontab, que especifica la frecuencia en la que se chequean las temperaturas
|
32
|
+
Por defecto está establecido para lanzarse en minutos 22 y 44 de cada hora
|
33
|
+
Para más información y opciones de la cadena se puede consultar:
|
34
|
+
https://blog.desdelinux.net/cron-crontab-explicados/
|
35
|
+
https://linux.die.net/man/5/crontab (en inglés)
|
36
|
+
|
37
|
+
Comandos posibles:
|
38
|
+
programar [CPU] [disco duro] [cron] - programa la notificación de altas temperaturas cuando se supera algún límite establecido
|
39
|
+
|
40
|
+
test [CPU] [disco duro] - lanza la notificación de altas temperaturas cuando se supera algún límite establecido
|
41
|
+
|
42
|
+
ayuda - muestra éste mismo texto de ayuda. Para más información consultar en la web del proyecto
|
43
|
+
|
44
|
+
EOS
|
45
|
+
else
|
46
|
+
puts <<EOS
|
47
|
+
|
48
|
+
Rsensors 0.2.8 version - LGPL-3.0 software
|
49
|
+
Tested but no warranty, take care
|
50
|
+
A Ruby gem to help on ESMS games
|
51
|
+
More info about ESMS = Electronic Soccer Management Simulator
|
52
|
+
https://github.com/eliben/esms
|
53
|
+
|
54
|
+
Usage:
|
55
|
+
esms_tools [command] [parameter(s)]
|
56
|
+
|
57
|
+
Possible commands are:
|
58
|
+
ageCheck [file] [number] - test age limit condition on the line-up file
|
59
|
+
ageCheck273 [file] [number] - same as above for the ESMS 2.73 version
|
60
|
+
eosEffect [file] - apply end of season changes on the roster file
|
61
|
+
|
62
|
+
EOS
|
63
|
+
end
|
64
|
+
|
65
|
+
else
|
66
|
+
#puts "Nothing detected"
|
67
|
+
Rsensors::Notification.notify
|
68
|
+
end
|
data/lib/rsensors.rb
ADDED
@@ -0,0 +1,204 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#!/usr/bin/ruby
|
3
|
+
|
4
|
+
# @title Rsensors module
|
5
|
+
# A module to provide info about system temperatures, and cronify and triggers if conditions are fulfilled
|
6
|
+
# Available submodules:
|
7
|
+
# Sensor : Return all requested info from system sensors: CPU(s) and hard disk(s) temperatures
|
8
|
+
# Notification : Launch temperature notification on GUI and console text
|
9
|
+
# Cronify : Schedule notification by a crontab on selected conditions and limits
|
10
|
+
|
11
|
+
#Gem name Require statement Main class or module
|
12
|
+
#rsensors require 'libnotify' Rsensors
|
13
|
+
# more info Rsensors = Ruby Sensors https://github.com/jacob-mf/rsensors
|
14
|
+
# @version 0.2.8 @date 15-3-2018
|
15
|
+
# @author Luis Jacob Mariscal Fernández
|
16
|
+
# Currently works/tests only over Linux, on kernel above 3
|
17
|
+
|
18
|
+
require 'libnotify'
|
19
|
+
|
20
|
+
module Rsensors
|
21
|
+
# Temperature Sensor interface.
|
22
|
+
|
23
|
+
module Sensor
|
24
|
+
# == Returns:
|
25
|
+
# A float value of the system's temperature
|
26
|
+
def self.temperature1
|
27
|
+
if File.exists?('/sys/class/hwmon/hwmon0/temp1_input')
|
28
|
+
File.read('/sys/class/hwmon/hwmon0/temp1_input').to_f / 1000
|
29
|
+
else false
|
30
|
+
end
|
31
|
+
end
|
32
|
+
def self.temperature2
|
33
|
+
if File.exists?('/sys/class/hwmon/hwmon0/device/temp2_input')
|
34
|
+
File.read('/sys/class/hwmon/hwmon0/device/temp2_input').to_f / 1000
|
35
|
+
else false
|
36
|
+
end
|
37
|
+
end
|
38
|
+
def self.temperature4
|
39
|
+
if File.exists?('/sys/class/hwmon/hwmon0/device/temp4_input')
|
40
|
+
File.read('/sys/class/hwmon/hwmon0/device/temp4_input').to_f / 1000
|
41
|
+
else false
|
42
|
+
end
|
43
|
+
end
|
44
|
+
def self.temperature_hd # need superuser or privileges with apps
|
45
|
+
# 1st try hddtemp
|
46
|
+
temp = %x( hddtemp -uC /dev/?d? )
|
47
|
+
if $?.exitstatus != 0 # hddtemp not works, try hdparm
|
48
|
+
temp = %x( hdparm -Hi /dev/?d? )
|
49
|
+
temp = format_hdparm(temp) if $?.exitstatus == 0 # works fine
|
50
|
+
end #dtemp -n /dev/?d? ) # good for one line, one hard disk
|
51
|
+
return temp
|
52
|
+
end
|
53
|
+
def self.format_hdparm (text)
|
54
|
+
sol = ""
|
55
|
+
text.each_line { |line|
|
56
|
+
if /^\/dev/.match(line) # hard disk detected
|
57
|
+
sol[0] += line
|
58
|
+
elsif /^ drive temperature/.match(line) # info detected
|
59
|
+
sol += line
|
60
|
+
elsif /^ Model=(\w+),*/.match(line) # model detected
|
61
|
+
m1 = /^ Model=(\w+\s+\w+),*/.match(line)
|
62
|
+
#p m1
|
63
|
+
sol += m1[1]
|
64
|
+
end
|
65
|
+
}
|
66
|
+
return sol # return
|
67
|
+
end
|
68
|
+
def self.temperatureHd # return float of hd temperature or array if more disk(s) present
|
69
|
+
# need superuser or privileges with apps
|
70
|
+
# 1st try hddtemp, temp = -20 error temp
|
71
|
+
temp = -20
|
72
|
+
temp = %x( hddtemp -n /dev/?d? )
|
73
|
+
if $?.exitstatus != 0 # hddtemp not works, try hdparm
|
74
|
+
temp = %x( hdparm -H /dev/?d? )
|
75
|
+
temp = formatHdparm(temp) if $?.exitstatus == 0 # works fine
|
76
|
+
else # hddtemp ok
|
77
|
+
temp = formatHddtemp(temp) if temp.is_a? Array
|
78
|
+
end
|
79
|
+
return temp if temp.is_a? Array
|
80
|
+
return temp.to_f
|
81
|
+
end
|
82
|
+
def self.formatHdparm(entry)
|
83
|
+
sol = []
|
84
|
+
ok_sense = true
|
85
|
+
entry.each_line { |line|
|
86
|
+
if /^\/dev/.match(line) # hard disk detected
|
87
|
+
ok_sense = true # activate sense
|
88
|
+
elsif m1 = /^ drive temperature \(celsius\) is:\s+(d+)/.match(line) # info detected
|
89
|
+
sol << m1[1] if ok_sense
|
90
|
+
elsif /^SG_IO: bad\/missing sense data/.match(line) # sense problem detected
|
91
|
+
ok_sense = false
|
92
|
+
end
|
93
|
+
}
|
94
|
+
return sol[0].to_f if sol.size == 1
|
95
|
+
return sol
|
96
|
+
end
|
97
|
+
def self.formatHddtemp(entry)
|
98
|
+
sol = []
|
99
|
+
entry.each_line { |line|
|
100
|
+
if m1 = /\w+(\/?d?\/):(\w+) not available/.match(line) # error detected
|
101
|
+
puts "**warning** drive /dev/#{m1[1]} sensor not available"
|
102
|
+
elsif m1 = /^(d+)/.match(line) # info detected
|
103
|
+
sol << m1[1]
|
104
|
+
end
|
105
|
+
}
|
106
|
+
return sol[0].to_f if sol.size == 1
|
107
|
+
return sol
|
108
|
+
end
|
109
|
+
def self.maxTemperatureHd
|
110
|
+
temp = temperatureHd # float or array of temperatures
|
111
|
+
return temp if temp.is_a? Float
|
112
|
+
return temp.max
|
113
|
+
end
|
114
|
+
def self.temperature
|
115
|
+
if temperature1
|
116
|
+
return temperature1
|
117
|
+
elsif temperature2
|
118
|
+
return temperature2
|
119
|
+
elsif temperature4
|
120
|
+
return temperature4
|
121
|
+
else return 0 # to perform float test, give a correct answer
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
# Uses system notification to notify of current temperature.
|
127
|
+
# Currently works/tested only on Linux
|
128
|
+
module Notification
|
129
|
+
def self.notify (max_temp_cpu = 77, max_temp_hd = 46) # optional max_temperature CPU hard disk values
|
130
|
+
temp = Sensor.temperature1
|
131
|
+
temp2 = Sensor.temperature2
|
132
|
+
temp4 = Sensor.temperature4
|
133
|
+
temp_hd = Sensor.temperature_hd
|
134
|
+
# p Sensor.maxTemperatureHd
|
135
|
+
if temp2 && temp4
|
136
|
+
sentence = "Your computer's temperature is now:\n Core 2 #{temp2} °C, Core 4: #{temp4} °C\n Average temperature: #{(temp4+temp2)/2} °C\n" + temp_hd
|
137
|
+
n = Libnotify.new(
|
138
|
+
summary: 'Temperature',
|
139
|
+
body: sentence ,
|
140
|
+
timeout: 2.5,
|
141
|
+
append: true
|
142
|
+
)
|
143
|
+
n.urgency = temp2 > max_temp_cpu ? :critical : :normal
|
144
|
+
n.urgency = temp4 > max_temp_cpu ? :critical : :normal
|
145
|
+
n.urgency = Sensor.maxTemperatureHd > max_temp_hd ? :critical : :normal
|
146
|
+
elsif temp
|
147
|
+
sentence = "Your computer's temperature is now: #{temp} °C\n" + temp_hd
|
148
|
+
n = Libnotify.new(
|
149
|
+
summary: 'Temperature',
|
150
|
+
body: sentence ,
|
151
|
+
timeout: 2.5,
|
152
|
+
append: true
|
153
|
+
)
|
154
|
+
n.urgency = temp > max_temp ? :critical : :normal
|
155
|
+
n.urgency = Sensor.maxTemperatureHd > max_temp_hd ? :critical : :normal
|
156
|
+
else
|
157
|
+
sentence = "Your computer's temperature is currently unknown by this app, sorry. Wait for a brilliant update. Peace\n" + temp_hd
|
158
|
+
n = Libnotify.new(
|
159
|
+
summary: 'Temperature',
|
160
|
+
body: sentence ,
|
161
|
+
timeout: 2.5,
|
162
|
+
append: true
|
163
|
+
)
|
164
|
+
n.urgency = Sensor.maxTemperatureHd > max_temp_hd ? :critical : :normal # temp_hd[1] store number
|
165
|
+
end
|
166
|
+
puts sentence # check exit, now nothing on console
|
167
|
+
puts "URGENT!" if n.urgency
|
168
|
+
n.show!
|
169
|
+
exit(0)
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
# Module to write the cronjob
|
174
|
+
module Cronify
|
175
|
+
# Tries to write the crontab and exits with the appropiate code
|
176
|
+
# you can edit the file with command $ crontab -e
|
177
|
+
def self.schedule(max_cpu = 76, max_hd = 44, cron_value = "22,44 * * * *") # first cron_value = 0,10,20,30,40,50 * * * *
|
178
|
+
cron = <<-END.gsub(/^ {8}/, '') # Heredoc try
|
179
|
+
# Rsensors temperature notification
|
180
|
+
#{cron_value} /bin/bash -l -c 'rsensors job #{max_cpu} #{max_hd}'
|
181
|
+
# End Rsensors temperature notification
|
182
|
+
END
|
183
|
+
|
184
|
+
require 'tempfile'
|
185
|
+
file = Tempfile.new('temp_cronfile')
|
186
|
+
file.write(cron)
|
187
|
+
file.close
|
188
|
+
|
189
|
+
run(file)
|
190
|
+
end
|
191
|
+
|
192
|
+
def self.run(file)
|
193
|
+
if system("crontab #{file.path}")
|
194
|
+
puts 'INFO: Wrote rsensors on the crontab file'
|
195
|
+
file.unlink
|
196
|
+
exit(0)
|
197
|
+
else
|
198
|
+
warn 'ERROR: Failed to write rsensors on crontab'
|
199
|
+
file.unlink
|
200
|
+
exit(1)
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
metadata
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rsensors
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.82
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- L. Jacob Mariscal Fernández
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-03-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: libnotify
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.9.3
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.9.3
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: minitest
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '5.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '5.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rubocop
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.47.1
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.47.1
|
55
|
+
description: Show a notification of your computer's temperature. It can be programmed
|
56
|
+
as a cronjob, so you can be notified when the temperature is high | Muestra la temperatura
|
57
|
+
del sistema, puede igual actuar en segundo plano para alertar de alta temperatura
|
58
|
+
email: l.jacob.m.f@gmail.com
|
59
|
+
executables:
|
60
|
+
- rsensors
|
61
|
+
extensions: []
|
62
|
+
extra_rdoc_files: []
|
63
|
+
files:
|
64
|
+
- bin/rsensors
|
65
|
+
- lib/rsensors.rb
|
66
|
+
homepage: https://github.com/jacob-mf/rsensors
|
67
|
+
licenses:
|
68
|
+
- GPL-3.0
|
69
|
+
metadata: {}
|
70
|
+
post_install_message: Gracias por probar la gema rsensors | Thanks for installing
|
71
|
+
and trying rsensors gem
|
72
|
+
rdoc_options: []
|
73
|
+
require_paths:
|
74
|
+
- lib
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
requirements: []
|
86
|
+
rubyforge_project:
|
87
|
+
rubygems_version: 2.5.2
|
88
|
+
signing_key:
|
89
|
+
specification_version: 4
|
90
|
+
summary: 'A gem to display system hardware temperature | Gema para mostrar la termperatura
|
91
|
+
del sistema: microprocesador(es) y disco(s) duro(s)'
|
92
|
+
test_files: []
|