Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
temperature-daemon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
stustanet
temperature-daemon
Compare revisions
890ee77a3ebfa9aaccca23d9ddd44535fc402877 to master
Compare revisions
Changes are shown as if the
source
revision was being merged into the
target
revision.
Learn more about comparing revisions.
Source
stustanet/temperature-daemon
Select target project
No results found
master
Select Git revision
Branches
esptemper
master
maxbill
Swap
Target
007638/temperature-daemon
Select target project
stustanet/temperature-daemon
roman/temperature-daemon
007638/temperature-daemon
3 results
890ee77a3ebfa9aaccca23d9ddd44535fc402877
Select Git revision
Branches
esptemper
master
matrix
maxbill
Show changes
Only incoming changes from source
Include changes to target since source was created
Compare
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
tempermonitor/plugins/prometheus.py
+10
-15
10 additions, 15 deletions
tempermonitor/plugins/prometheus.py
tempermonitor/plugins/warnings.py
+3
-6
3 additions, 6 deletions
tempermonitor/plugins/warnings.py
tempermonitor/tempermonitor.py
+9
-26
9 additions, 26 deletions
tempermonitor/tempermonitor.py
with
22 additions
and
47 deletions
plugins/prometheus.py
→
tempermonitor/
plugins/prometheus.py
View file @
e876740c
import
re
import
asyncio
import
asyncio
from
prometheus_client
import
start_http_server
,
Gauge
from
prometheus_client
import
start_http_server
,
Gauge
from
.
import
Plugin
def
init
(
monitor
):
stats_name_re
=
re
.
compile
(
r
'
^temperature-(?P<group>\w+)-(?P<type>\w+)$
'
)
return
PluginPrometheus
(
monitor
)
class
Plugin
Prometheus
:
class
Prometheus
(
Plugin
)
:
def
__init__
(
self
,
monitor
):
def
__init__
(
self
,
monitor
):
self
.
loop
=
asyncio
.
get_event_loop
()
self
.
loop
=
asyncio
.
get_event_loop
()
self
.
config
=
monitor
.
config
self
.
config
=
monitor
.
config
...
@@ -32,20 +32,15 @@ class PluginPrometheus:
...
@@ -32,20 +32,15 @@ class PluginPrometheus:
)
)
print
(
"
started prometheus http server
"
)
print
(
"
started prometheus http server
"
)
async
def
update_sensor_values
(
self
,
sensor
):
"""
update
"""
print
(
"
updating prometheus metrics
"
)
self
.
sensor_metrics
.
labels
(
sensor
=
sensor
.
name
).
set
(
sensor
.
temperature
)
async
def
send_stats_graph
(
self
,
graph
,
stattype
,
stattime
,
statval
):
async
def
send_stats_graph
(
self
,
graph
,
stattype
,
stattime
,
statval
):
"""
"""
to be called as a plugin callback to export aggregated measurements
to be called as a plugin callback to export aggregated measurements
"""
"""
label_group
=
stattype
.
split
(
"
-
"
)[
1
]
m
=
stats_name_re
.
match
(
stattype
)
label_type
=
stattype
.
split
(
"
-
"
)[
2
]
if
not
m
:
self
.
aggregated_metrics
.
labels
(
group
=
label_group
,
type
=
label_type
).
set
(
statval
)
return
self
.
aggregated_metrics
.
labels
(
group
=
m
.
group
(
'
group
'
),
type
=
m
.
group
(
'
type
'
)).
set
(
statval
)
async
def
sensor_update
(
self
):
async
def
sensor_update
(
self
):
"""
"""
...
@@ -53,4 +48,4 @@ class PluginPrometheus:
...
@@ -53,4 +48,4 @@ class PluginPrometheus:
"""
"""
for
sensor
in
self
.
monitor
.
sensors
.
values
():
for
sensor
in
self
.
monitor
.
sensors
.
values
():
if
sensor
.
valid
:
if
sensor
.
valid
:
await
self
.
update_sensor_values
(
sensor
)
self
.
sensor_metrics
.
labels
(
sensor
=
sensor
.
name
).
set
(
sensor
.
temperature
)
This diff is collapsed.
Click to expand it.
plugins/warnings.py
→
tempermonitor/
plugins/warnings.py
View file @
e876740c
import
time
import
time
from
.
import
Plugin
def
init
(
monitor
):
"""
Plugin interface method
"""
return
PluginWarning
(
monitor
)
class
Warnings
(
Plugin
):
class
PluginWarning
:
"""
"""
Generate all kind of warnings whenever needed and observe the sensor
Generate all kind of warnings whenever needed and observe the sensor
if they see a problematic situation in the container
if they see a problematic situation in the container
...
@@ -107,7 +104,7 @@ class PluginWarning:
...
@@ -107,7 +104,7 @@ class PluginWarning:
tempdiff
=
ceil_avg
-
floor_avg
tempdiff
=
ceil_avg
-
floor_avg
await
self
.
monitor
.
call_plugin
(
await
self
.
monitor
.
call_plugin
(
"
send_stats_graph
"
,
graph
=
"
stats
"
,
"
send_stats_graph
"
,
graph
=
"
stats
"
,
stattype
=
"
temperature-floor_ceil
_
diff
"
,
stattime
=
now
,
statval
=
tempdiff
)
stattype
=
"
temperature-floor_ceil
-
diff
"
,
stattime
=
now
,
statval
=
tempdiff
)
print
(
"
floor: min {:05.2f} max {:05.2f} avg {:05.2f} var {:05.2f}
"
.
format
(
print
(
"
floor: min {:05.2f} max {:05.2f} avg {:05.2f} var {:05.2f}
"
.
format
(
floor_min
,
floor_max
,
floor_avg
,
floor_var
))
floor_min
,
floor_max
,
floor_avg
,
floor_var
))
...
...
This diff is collapsed.
Click to expand it.
tempermonitor.py
→
tempermonitor/
tempermonitor.py
View file @
e876740c
...
@@ -21,12 +21,12 @@ import asyncio
...
@@ -21,12 +21,12 @@ import asyncio
import
configparser
import
configparser
import
sys
import
sys
import
time
import
time
import
importlib
from
datetime
import
datetime
from
datetime
import
datetime
from
pathlib
import
Path
import
serial_asyncio
import
serial_asyncio
import
serial
import
serial
from
.plugins
import
PLUGINS
class
Sensor
:
class
Sensor
:
"""
"""
...
@@ -254,41 +254,27 @@ class TempMonitor:
...
@@ -254,41 +254,27 @@ class TempMonitor:
self
.
_last_store
=
time
.
time
()
self
.
_last_store
=
time
.
time
()
def
setup_plugin
(
filename
,
plugin
):
"""
Setup and fix plugins
"""
if
not
getattr
(
plugin
,
"
name
"
,
None
):
plugin
.
name
=
filename
def
main
():
def
main
():
"""
"""
Start the tempmonitor
Start the tempmonitor
"""
"""
loop
=
asyncio
.
get_event_loop
()
loop
=
asyncio
.
get_event_loop
()
configfile
=
"
/etc/temper
ature/tempermon
.ini
"
configfile
=
"
/etc/temper
monitor
.ini
"
if
len
(
sys
.
argv
)
==
2
:
if
len
(
sys
.
argv
)
==
2
:
configfile
=
sys
.
argv
[
1
]
configfile
=
sys
.
argv
[
1
]
print
(
"
Configuring temperature monitoring system from {
}.
"
.
format
(
configfile
)
)
print
(
f
"
Configuring temperature monitoring system from
{
configfile
}
.
"
)
monitor
=
TempMonitor
(
loop
,
configfile
)
monitor
=
TempMonitor
(
loop
,
configfile
)
plugin_path
=
Path
(
__file__
).
resolve
().
parent
/
"
plugins
"
print
(
"
Loading plugins from {}
"
.
format
(
plugin_path
))
active_plugins
=
monitor
.
config
[
"
general
"
][
"
plugins
"
].
split
(
"
,
"
)
active_plugins
=
monitor
.
config
[
"
general
"
][
"
plugins
"
].
split
(
"
,
"
)
print
(
f
"
Active plugins:
{
active_plugins
}
"
)
print
(
f
"
Active plugins:
{
active_plugins
}
"
)
for
filename
in
plugin_path
.
glob
(
"
*.py
"
):
for
plugin
in
active_plugins
:
if
(
plugin_path
/
filename
).
exists
()
and
filename
.
stem
in
active_plugins
:
if
plugin
in
PLUGINS
:
print
(
"
loading {}
"
.
format
(
filename
.
name
))
p
=
PLUGINS
[
plugin
](
monitor
)
modname
=
"
plugins.
"
+
filename
.
name
.
split
(
'
.
'
)[
0
]
monitor
.
plugins
.
append
(
p
)
module
=
importlib
.
import_module
(
modname
)
print
(
f
"
Loaded plugin:
{
plugin
}
"
)
plugin
=
module
.
init
(
monitor
)
setup_plugin
(
filename
,
plugin
)
monitor
.
plugins
.
append
(
plugin
)
print
(
"
Loaded: {}
"
.
format
(
plugin
.
name
))
try
:
try
:
loop
.
run_forever
()
loop
.
run_forever
()
...
@@ -297,6 +283,3 @@ def main():
...
@@ -297,6 +283,3 @@ def main():
finally
:
finally
:
loop
.
run_until_complete
(
monitor
.
teardown
())
loop
.
run_until_complete
(
monitor
.
teardown
())
if
__name__
==
"
__main__
"
:
main
()
This diff is collapsed.
Click to expand it.
Prev
1
2
Next