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
edd80a9d
Commit
edd80a9d
authored
3 years ago
by
bav6096
Browse files
Options
Downloads
Patches
Plain Diff
added monitor class
parent
9d871d08
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
msg/Metric.msg
+4
-0
4 additions, 0 deletions
msg/Metric.msg
msg/Monitoring.msg
+3
-0
3 additions, 0 deletions
msg/Monitoring.msg
scripts/monitor.py
+98
-0
98 additions, 0 deletions
scripts/monitor.py
with
105 additions
and
0 deletions
msg/Metric.msg
0 → 100644
+
4
−
0
View file @
edd80a9d
string key # Label of the value.
string val # Value to track.
string unit # Unit of the value.
float32 err # Error level of the value.
\ No newline at end of file
This diff is collapsed.
Click to expand it.
msg/Monitoring.msg
+
3
−
0
View file @
edd80a9d
string name # Name and origin of the monitor message.
string desc # Text describing the monitor message.
Metric metric # Values to monitor.
\ No newline at end of file
This diff is collapsed.
Click to expand it.
scripts/monitor.py
+
98
−
0
View file @
edd80a9d
#!/usr/bin/env python
import
socket
import
rospy
from
monitoring.msg
import
Monitoring
from
monitoring.msg
import
Metic
class
Monitor
:
def
__init__
(
self
,
desc
,
freq
=
1
,
auto
=
True
):
self
.
host
=
socket
.
gethostname
()
self
.
node
=
rospy
.
get_name
()
self
.
name
=
self
.
host
+
self
.
node
self
.
desc
=
desc
if
not
freq
>
0
:
print
(
"
Frequency must be greater than 0!
"
)
quit
()
if
auto
:
self
.
timer
=
rospy
.
Timer
(
rospy
.
Duration
(
1.0
/
freq
),
self
.
pub_monitoring
)
self
.
log
=
{}
self
.
pub
=
rospy
.
Publisher
(
'
monitoring
'
,
Monitoring
,
queue_size
=
1
)
self
.
pub_times
=
0
self
.
monitoring
=
Monitoring
()
self
.
monitoring
.
name
=
self
.
name
self
.
monitoring
.
desc
=
self
.
desc
def
rst_log_key
(
self
,
key
):
self
.
log
[
key
]
=
{
'
num
'
:
0
,
'
val
'
:
0
,
'
sum
'
:
0
,
'
dur
'
:
rospy
.
get_rostime
()}
def
add_log_val
(
self
,
key
,
val
,
unit
,
err
,
mode
=
2
):
if
"
"
in
key
:
# A key cannot contain whitespace!
rospy
.
logwarn
(
"
[%s] whitespaces are not allowed in monitoring keys!
"
,
self
.
node
)
else
:
if
key
in
self
.
log
:
# Mode 1: Write the first obtained value into the
# published message.
if
mode
==
1
and
self
.
pub_times
==
0
:
self
.
set_metric
(
key
,
val
,
unit
,
err
)
self
.
pub_times
=
1
# Mode 2: Write the last obtained value into the
# published message.
elif
mode
==
2
:
self
.
set_metric
(
key
,
val
,
unit
,
err
)
# Mode 3: Remember and write the minimum obtained
# value, after mode selection, into the
# published message.
elif
mode
==
3
:
if
val
<
self
.
log
[
key
][
'
val
'
]:
self
.
log
[
key
][
'
val
'
]
=
val
self
.
set_metric
(
key
,
self
.
log
[
key
][
'
val
'
],
unit
,
err
)
# Mode 4: Remember and write the maximum obtained
# value, after mode selection, into the
# published message.
elif
mode
==
4
:
if
val
>
self
.
log
[
key
][
'
val
'
]:
self
.
log
[
key
][
'
val
'
]
=
val
self
.
set_metric
(
key
,
self
.
log
[
key
][
'
val
'
],
unit
,
err
)
# Mode 5: Write the average value over five seconds
# into the published message.
elif
mode
==
5
:
dur
=
rospy
.
get_rostime
()
-
self
.
log
[
key
][
'
dur
'
]
if
dur
<
rospy
.
Duration
(
5
):
self
.
log
[
self
.
name
][
key
][
'
num
'
]
+=
1
self
.
log
[
self
.
name
][
key
][
'
sum
'
]
+=
val
else
:
quotient
=
self
.
log
[
key
][
'
sum
'
]
/
(
self
.
log
[
key
][
'
num
'
]
+
0.001
)
self
.
set_metric
(
key
,
quotient
,
unit
,
err
)
self
.
rst_log_key
(
key
)
else
:
self
.
rst_log_key
(
key
)
# Add key to the logging dictionary.
self
.
set_metric
(
key
,
val
,
unit
,
err
)
def
set_metric
(
self
,
key
,
val
,
unit
,
err
):
metric
=
Metic
()
metric
.
key
=
str
(
key
)
metric
.
val
=
str
(
val
)
metric
.
unit
=
str
(
unit
)
metric
.
err
=
err
self
.
monitoring
.
metric
=
metric
def
rst_monitoring
(
self
):
self
.
monitoring
=
Monitoring
()
self
.
monitoring
.
name
=
self
.
name
self
.
monitoring
.
desc
=
self
.
desc
def
pub_monitoring
(
self
):
self
.
pub
.
publish
(
self
.
monitoring
)
self
.
rst_monitoring
()
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