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
9b9bb34ec87b4b428b61f785e106375cdf6329f9 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
9b9bb34ec87b4b428b61f785e106375cdf6329f9
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
+12
-15
12 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
24 additions
and
47 deletions
plugins/prometheus.py
→
tempermonitor/
plugins/prometheus.py
View file @
e876740c
import
re
import
asyncio
from
prometheus_client
import
start_http_server
,
Gauge
from
.
import
Plugin
def
init
(
monitor
):
return
PluginPrometheus
(
monitor
)
stats_name_re
=
re
.
compile
(
r
'
^temperature-(?P<group>\w+)-(?P<type>\w+)$
'
)
class
Plugin
Prometheus
:
class
Prometheus
(
Plugin
)
:
def
__init__
(
self
,
monitor
):
self
.
loop
=
asyncio
.
get_event_loop
()
self
.
config
=
monitor
.
config
...
...
@@ -28,22 +28,19 @@ class PluginPrometheus:
start_http_server
(
addr
=
self
.
config
[
"
prometheus
"
].
get
(
'
address
'
,
'
localhost
'
),
port
=
self
.
config
[
"
prometheus
"
][
"
port
"
]
port
=
int
(
self
.
config
[
"
prometheus
"
][
"
port
"
]
)
)
async
def
update_sensor_values
(
self
,
sensor
):
"""
update
"""
self
.
sensor_metrics
.
labels
(
sensor
=
sensor
.
name
).
set
(
sensor
.
temperature
)
print
(
"
started prometheus http server
"
)
async
def
send_stats_graph
(
self
,
graph
,
stattype
,
stattime
,
statval
):
"""
to be called as a plugin callback to export aggregated measurements
"""
label_group
=
stattype
.
split
(
"
-
"
)[
1
]
label_type
=
stattype
.
split
(
"
-
"
)[
2
]
self
.
aggregated_metrics
.
labels
(
group
=
label_group
,
type
=
label_type
).
set
(
statval
)
m
=
stats_name_re
.
match
(
stattype
)
if
not
m
:
return
self
.
aggregated_metrics
.
labels
(
group
=
m
.
group
(
'
group
'
),
type
=
m
.
group
(
'
type
'
)).
set
(
statval
)
async
def
sensor_update
(
self
):
"""
...
...
@@ -51,4 +48,4 @@ class PluginPrometheus:
"""
for
sensor
in
self
.
monitor
.
sensors
.
values
():
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
from
.
import
Plugin
def
init
(
monitor
):
"""
Plugin interface method
"""
return
PluginWarning
(
monitor
)
class
PluginWarning
:
class
Warnings
(
Plugin
):
"""
Generate all kind of warnings whenever needed and observe the sensor
if they see a problematic situation in the container
...
...
@@ -107,7 +104,7 @@ class PluginWarning:
tempdiff
=
ceil_avg
-
floor_avg
await
self
.
monitor
.
call_plugin
(
"
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
(
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
import
configparser
import
sys
import
time
import
importlib
from
datetime
import
datetime
from
pathlib
import
Path
import
serial_asyncio
import
serial
from
.plugins
import
PLUGINS
class
Sensor
:
"""
...
...
@@ -254,41 +254,27 @@ class TempMonitor:
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
():
"""
Start the tempmonitor
"""
loop
=
asyncio
.
get_event_loop
()
configfile
=
"
/etc/temper
ature/tempermon
.ini
"
configfile
=
"
/etc/temper
monitor
.ini
"
if
len
(
sys
.
argv
)
==
2
:
configfile
=
sys
.
argv
[
1
]
print
(
"
Configuring temperature monitoring system from {
}.
"
.
format
(
configfile
)
)
print
(
f
"
Configuring temperature monitoring system from
{
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
(
"
,
"
)
print
(
f
"
Active plugins:
{
active_plugins
}
"
)
for
filename
in
plugin_path
.
glob
(
"
*.py
"
):
if
(
plugin_path
/
filename
).
exists
()
and
filename
.
name
in
active_plugins
:
print
(
"
loading {}
"
.
format
(
filename
.
name
))
modname
=
"
plugins.
"
+
filename
.
name
.
split
(
'
.
'
)[
0
]
module
=
importlib
.
import_module
(
modname
)
plugin
=
module
.
init
(
monitor
)
setup_plugin
(
filename
,
plugin
)
monitor
.
plugins
.
append
(
plugin
)
print
(
"
Loaded: {}
"
.
format
(
plugin
.
name
))
for
plugin
in
active_plugins
:
if
plugin
in
PLUGINS
:
p
=
PLUGINS
[
plugin
](
monitor
)
monitor
.
plugins
.
append
(
p
)
print
(
f
"
Loaded plugin:
{
plugin
}
"
)
try
:
loop
.
run_forever
()
...
...
@@ -297,6 +283,3 @@ def main():
finally
:
loop
.
run_until_complete
(
monitor
.
teardown
())
if
__name__
==
"
__main__
"
:
main
()
This diff is collapsed.
Click to expand it.
Prev
1
2
Next