Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
slapos
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Justin
slapos
Commits
ea8d8dcc
Commit
ea8d8dcc
authored
Dec 09, 2022
by
Joanne Hugé
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
WIP
parent
16b27381
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
28 deletions
+39
-28
software/ors-amarisoft/buildout.hash.cfg
software/ors-amarisoft/buildout.hash.cfg
+1
-1
software/ors-amarisoft/promise/check_cpu_temperature.py
software/ors-amarisoft/promise/check_cpu_temperature.py
+38
-27
No files found.
software/ors-amarisoft/buildout.hash.cfg
View file @
ea8d8dcc
...
...
@@ -104,7 +104,7 @@ md5sum = 5bf57a9074ea5b054d999789cbbe2c87
[cpu-temperature-promise]
_update_hash_filename_ = promise/check_cpu_temperature.py
md5sum =
e8fc789eb7e7e3b054e921b0292c806f
md5sum =
107db0dc93bba6a90a0b328e625c2e5c
[interface-up-promise]
_update_hash_filename_ = promise/check_interface_up.py
...
...
software/ors-amarisoft/promise/check_cpu_temperature.py
View file @
ea8d8dcc
import
errno
import
json
import
logging
import
os
import
psutil
import
socket
import
time
from
dateutil
import
parser
from
zope.interface
import
implementer
from
slapos.grid.promise
import
interface
from
slapos.grid.promise.generic
import
GenericPromise
# Get all data in the last "interval" seconds from JSON log
def
get_data_interval
(
log
,
interval
):
class
JSONRunPromise
(
GenericPromise
):
def
__init__
(
self
,
config
):
self
.
__name
=
config
.
get
(
'name'
,
None
)
self
.
__log_folder
=
config
.
get
(
'log-folder'
,
None
)
super
(
JSONRunPromise
,
self
).
__init__
(
config
)
self
.
__title
=
os
.
path
.
splitext
(
self
.
__name
)[
0
]
self
.
log_file
=
os
.
path
.
join
(
self
.
__log_folder
,
'%s.json.log'
%
self
.
__title
)
self
.
json_logger
=
logging
.
getLogger
(
'json_logger'
)
self
.
json_logger
.
setLevel
(
logging
.
INFO
)
handler
=
logging
.
FileHandler
(
self
.
log_file
)
formatter
=
logging
.
Formatter
(
'{"time": "%(asctime)s", "log_level": '
\
'"%(levelname)s", "message": "%(message)s", "data": %(data)s}'
)
handler
.
setFormatter
(
formatter
)
self
.
json_logger
.
addHandler
(
handler
)
def
get_data_interval_json_log
(
log
,
interval
):
"""
Get all data in the last "interval" seconds from JSON log
Reads rotated logs too (XX.log, XX.log.1, XX.log.2, ...)
"""
log_number
=
0
latest_timestamp
=
0
...
...
@@ -46,28 +62,15 @@ def get_data_interval(log, interval):
log_number
+=
1
@
implementer
(
interface
.
IPromise
)
class
RunPromise
(
Generic
Promise
):
class
RunPromise
(
JSONRun
Promise
):
def
__init__
(
self
,
config
):
self
.
__name
=
config
.
get
(
'name'
,
None
)
self
.
__log_folder
=
config
.
get
(
'log-folder'
,
None
)
super
(
RunPromise
,
self
).
__init__
(
config
)
self
.
setPeriodicity
(
minute
=
2
)
self
.
setPeriodicity
(
minute
=
2
)
self
.
last_avg_computation_file
=
self
.
getConfig
(
'last-avg-computation-file'
,
''
)
self
.
__title
=
os
.
path
.
splitext
(
self
.
__name
)[
0
]
self
.
__log_file
=
os
.
path
.
join
(
self
.
__log_folder
,
'%s.json.log'
%
self
.
__title
)
self
.
json_logger
=
logging
.
getLogger
(
'json_logger'
)
self
.
json_logger
.
setLevel
(
logging
.
INFO
)
handler
=
logging
.
FileHandler
(
self
.
__log_file
)
formatter
=
logging
.
Formatter
(
'{"time": "%(asctime)s", "log_level": '
\
'"%(levelname)s", "message": "%(message)s", "data": %(data)s}'
)
handler
.
setFormatter
(
formatter
)
self
.
json_logger
.
addHandler
(
handler
)
'last-avg-computation-file'
,
'last_avg'
)
def
sense
(
self
):
...
...
@@ -75,9 +78,16 @@ class RunPromise(GenericPromise):
max_spot_temp
=
float
(
self
.
getConfig
(
'max-spot-temp'
,
90
))
max_avg_temp
=
float
(
self
.
getConfig
(
'max-avg-temp'
,
80
))
avg_temp_duration_sec
=
int
(
self
.
getConfig
(
'avg-temp-duration-sec'
,
0
))
if
avg_temp_duration_sec
:
avg_temp_duration
=
avg_temp_duration_sec
else
:
avg_temp_duration
=
60
*
int
(
self
.
getConfig
(
'avg-temp-duration'
,
5
))
testing
=
self
.
getConfig
(
'testing'
)
==
"True"
# For theia JHGD
#testing = True # JHGD
# Get current temperature
if
testing
:
from
random
import
randint
...
...
@@ -94,6 +104,7 @@ class RunPromise(GenericPromise):
data
=
json
.
dumps
({
'cpu_temperature'
:
cpu_temp
})
self
.
json_logger
.
info
(
"Temperature data"
,
extra
=
{
'data'
:
data
})
# TODO: promise should computer average only with logs between interval
# Computer average temperature
avg_computation_period
=
avg_temp_duration
/
4
try
:
...
...
@@ -102,7 +113,7 @@ class RunPromise(GenericPromise):
t
=
0
if
(
time
.
time
()
-
t
)
>
avg_computation_period
:
open
(
self
.
last_avg_computation_file
,
'w'
).
close
()
temp_list
=
get_data_interval
(
self
.
__
log_file
,
avg_temp_duration
)
temp_list
=
get_data_interval
_json_log
(
self
.
log_file
,
avg_temp_duration
)
if
temp_list
:
avg_temp
=
sum
(
map
(
lambda
x
:
x
[
'cpu_temperature'
],
temp_list
))
/
len
(
temp_list
)
if
avg_temp
>
max_avg_temp
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment