Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
engine
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
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
AURA
engine
Commits
7564a98b
Commit
7564a98b
authored
2 years ago
by
David Trattnig
Browse files
Options
Downloads
Patches
Plain Diff
Style(Docstring): Improve contrib src
#111
parent
23847200
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
contrib/heartbeat-monitor/PyHeartBeat.py
+8
-6
8 additions, 6 deletions
contrib/heartbeat-monitor/PyHeartBeat.py
with
8 additions
and
6 deletions
contrib/heartbeat-monitor/PyHeartBeat.py
+
8
−
6
View file @
7564a98b
...
@@ -26,7 +26,8 @@
...
@@ -26,7 +26,8 @@
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""
PyHeartBeat server: receives and tracks UDP packets from all clients.
"""
PyHeartBeat server: receives and tracks UDP packets from all clients.
While the BeatLog thread logs each UDP packet in a dictionary, the main
While the BeatLog thread logs each UDP packet in a dictionary, the main
thread periodically scans the dictionary and prints the IP addresses of the
thread periodically scans the dictionary and prints the IP addresses of the
...
@@ -62,7 +63,7 @@ DEBUG_ENABLED = os.getenv("DEBUG", "0") == "1"
...
@@ -62,7 +63,7 @@ DEBUG_ENABLED = os.getenv("DEBUG", "0") == "1"
class
BeatDict
:
class
BeatDict
:
"
Manage heartbeat dictionary
"
""
"
Manage heartbeat dictionary
.
""
"
def
__init__
(
self
):
def
__init__
(
self
):
self
.
beatDict
=
{}
self
.
beatDict
=
{}
...
@@ -82,13 +83,13 @@ class BeatDict:
...
@@ -82,13 +83,13 @@ class BeatDict:
return
result
return
result
def
update
(
self
,
entry
):
def
update
(
self
,
entry
):
"
Create or update a dictionary entry
"
""
"
Create or update a dictionary entry
.
""
"
self
.
dictLock
.
acquire
()
self
.
dictLock
.
acquire
()
self
.
beatDict
[
entry
]
=
time
()
self
.
beatDict
[
entry
]
=
time
()
self
.
dictLock
.
release
()
self
.
dictLock
.
release
()
def
extractSilent
(
self
,
howPast
):
def
extractSilent
(
self
,
howPast
):
"
Return
s
a list of entries older than howPast
"
""
"
Return a list of entries older than howPast
.
""
"
silent
=
[]
silent
=
[]
when
=
time
()
-
howPast
when
=
time
()
-
howPast
self
.
dictLock
.
acquire
()
self
.
dictLock
.
acquire
()
...
@@ -100,7 +101,7 @@ class BeatDict:
...
@@ -100,7 +101,7 @@ class BeatDict:
class
BeatRec
(
Thread
):
class
BeatRec
(
Thread
):
"
Receive UDP packets, log them in heartbeat dictionary
"
""
"
Receive UDP packets, log them in heartbeat dictionary
.
""
"
def
__init__
(
self
,
goOnEvent
,
updateDictFunc
,
port
):
def
__init__
(
self
,
goOnEvent
,
updateDictFunc
,
port
):
Thread
.
__init__
(
self
)
Thread
.
__init__
(
self
)
...
@@ -115,6 +116,7 @@ class BeatRec(Thread):
...
@@ -115,6 +116,7 @@ class BeatRec(Thread):
return
f
"
Heartbeat Server on port:
{
self
.
port
}
"
return
f
"
Heartbeat Server on port:
{
self
.
port
}
"
def
run
(
self
):
def
run
(
self
):
"""
Start the beat receiver.
"""
while
self
.
goOnEvent
.
isSet
():
while
self
.
goOnEvent
.
isSet
():
if
DEBUG_ENABLED
:
if
DEBUG_ENABLED
:
print
(
"
Waiting to receive...
"
)
print
(
"
Waiting to receive...
"
)
...
@@ -130,7 +132,7 @@ class BeatRec(Thread):
...
@@ -130,7 +132,7 @@ class BeatRec(Thread):
def
main
():
def
main
():
"
Listen to the heartbeats and detect inactive clients
"
""
"
Listen to the heartbeats and detect inactive clients
.
""
"
if
len
(
sys
.
argv
)
>
1
:
if
len
(
sys
.
argv
)
>
1
:
heartbeat_port
=
int
(
sys
.
argv
[
1
])
heartbeat_port
=
int
(
sys
.
argv
[
1
])
else
:
else
:
...
...
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