Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
monitoring
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Deike, Benedikt
monitoring
Commits
0ebc7f43
Commit
0ebc7f43
authored
3 years ago
by
bav6096
Browse files
Options
Downloads
Patches
Plain Diff
updated message structure
parent
60b05b8c
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
msg/Metric.msg
+4
-4
4 additions, 4 deletions
msg/Metric.msg
msg/Monitoring.msg
+2
-0
2 additions, 0 deletions
msg/Monitoring.msg
scripts/monitor.py
+29
-26
29 additions, 26 deletions
scripts/monitor.py
scripts/watchdog.py
+11
-0
11 additions, 0 deletions
scripts/watchdog.py
with
46 additions
and
30 deletions
msg/Metric.msg
+
4
−
4
View file @
0ebc7f43
string key # Label of the value.
string val # Value to track.
string unit # Unit of the value.
float32 err_lvl # Error level of the value.
\ No newline at end of file
string key # Label of the metric.
string value # Value of the metric.
string unit # Unit of the metric.
float32 critical # Critical level of the metric.
\ No newline at end of file
This diff is collapsed.
Click to expand it.
msg/Monitoring.msg
0 → 100644
+
2
−
0
View file @
0ebc7f43
string origin # Origin of the monitoring message.
Metric metric # Monitored metric.
\ No newline at end of file
This diff is collapsed.
Click to expand it.
scripts/monitor.py
+
29
−
26
View file @
0ebc7f43
#!/usr/bin/env python
import
socket
import
rospy
from
monitoring.msg
import
Monitoring
from
monitoring.msg
import
Metric
...
...
@@ -8,36 +10,37 @@ class Monitor:
self
.
log
=
{}
# Logging dictionary. Is used to accomplish different publishing modes.
self
.
pub
=
rospy
.
Publisher
(
'
metric
'
,
Metric
,
queue_size
=
1
)
self
.
mode
=
mode
self
.
metric
=
Metric
()
self
.
monitoring
=
Monitoring
()
self
.
monitoring
.
origin
=
socket
.
gethostname
()
+
rospy
.
get_name
()
if
not
freq
>
0
:
rospy
.
logwarn
(
"
Frequency must be greater then 0! Using 1 as frequency!
"
)
freq
=
1
self
.
timer
=
rospy
.
Timer
(
rospy
.
Duration
(
1.0
/
freq
),
self
.
publish_m
etric
)
self
.
timer
=
rospy
.
Timer
(
rospy
.
Duration
(
1.0
/
freq
),
self
.
publish_m
onitoring
)
def
reset_metric
(
self
):
self
.
metric
=
Metric
()
# At the moment the last metric update ist published over and over.
def
publish_monitoring
(
self
):
self
.
pub
.
publish
(
self
.
monitoring
)
def
publish_metric
(
self
):
self
.
pub
.
publish
(
self
.
metric
)
self
.
reset_metric
()
def
update_metric
(
self
,
key
,
val
,
unit
,
err_lvl
):
def
update_metric
(
self
,
key
,
value
,
unit
,
critical
):
def
set_metric
():
self
.
metric
.
key
=
key
self
.
metric
.
val
=
val
self
.
metric
.
unit
=
unit
self
.
metric
.
err_lvl
=
err_lvl
metric
=
Metric
()
metric
.
key
=
key
metric
.
value
=
value
metric
.
unit
=
unit
metric
.
critical
=
critical
self
.
monitoring
.
metric
=
metric
def
rst_key
():
# Reset the value of a key in the logging dictionary.
self
.
log
[
key
]
=
{
'
num
'
:
0
,
'
val
'
:
0
,
'
sum
'
:
0
,
'
dur
'
:
rospy
.
get_rostime
()}
if
"
"
in
key
:
# A key cannot contain whitespace!
rospy
.
logwarn
(
"
Whitespaces are not allowed in metric keys!
"
)
elif
critical
>
1
or
critical
<
0
:
rospy
.
logwarn
(
"
Critical level must be between 1 and 0!
"
)
else
:
self
.
reset_metric
()
# Reset metric.
if
key
in
self
.
log
:
# Mode 1: Set the last obtained value.
if
self
.
mode
==
1
:
...
...
@@ -46,32 +49,32 @@ class Monitor:
# Mode 2: Remember and set the minimum value,
# obtained after mode selection.
elif
self
.
mode
==
2
:
if
val
<
self
.
log
[
key
][
'
val
'
]:
self
.
log
[
key
][
'
val
'
]
=
val
if
val
ue
<
self
.
log
[
key
][
'
val
'
]:
self
.
log
[
key
][
'
val
'
]
=
val
ue
else
:
val
=
self
.
log
[
key
][
'
val
'
]
val
ue
=
self
.
log
[
key
][
'
val
'
]
set_metric
()
# Mode 3: Remember and set the maximum value,
# obtained after mode selection.
elif
self
.
mode
==
3
:
if
val
>
self
.
log
[
key
][
'
val
'
]:
self
.
log
[
key
][
'
val
'
]
=
val
if
val
ue
>
self
.
log
[
key
][
'
val
'
]:
self
.
log
[
key
][
'
val
'
]
=
val
ue
else
:
val
=
self
.
log
[
key
][
'
val
'
]
val
ue
=
self
.
log
[
key
][
'
val
'
]
set_metric
()
# Mode 4: Set the average obtained value over five
# seconds.
#
or more
seconds.
elif
self
.
mode
==
4
:
dur
=
rospy
.
get_rostime
()
-
self
.
log
[
key
][
'
dur
'
]
if
dur
<
rospy
.
Duration
(
5
):
dur
ation
=
rospy
.
get_rostime
()
-
self
.
log
[
key
][
'
dur
'
]
if
dur
ation
<
rospy
.
Duration
(
5
):
self
.
log
[
key
][
'
num
'
]
+=
1
self
.
log
[
key
][
'
sum
'
]
+=
val
self
.
log
[
key
][
'
sum
'
]
+=
val
ue
else
:
val
=
self
.
log
[
key
][
'
sum
'
]
/
(
self
.
log
[
key
][
'
num
'
]
+
0.001
)
val
ue
=
self
.
log
[
key
][
'
sum
'
]
/
(
self
.
log
[
key
][
'
num
'
]
+
0.001
)
set_metric
()
rst_key
()
else
:
...
...
This diff is collapsed.
Click to expand it.
scripts/watchdog.py
+
11
−
0
View file @
0ebc7f43
...
...
@@ -2,3 +2,14 @@
import
rospy
from
monitoring.msg
import
Metric
class
Watchdog
:
def
__init__
(
self
):
self
.
state
=
0
self
.
observing
=
{}
rospy
.
init_node
(
"
watchdog
"
)
rospy
.
Subscriber
(
"
metric
"
,
Metric
,
callback
)
def
callback
(
self
,
monitoring
):
if
monitoring
.
origin
in
self
.
observing
:
self
.
observing
[
metric
]
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment