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
3a76b610
Commit
3a76b610
authored
4 years ago
by
David Trattnig
Browse files
Options
Downloads
Patches
Plain Diff
Store health info. #29
parent
eaa59b7b
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
modules/core/events.py
+11
-8
11 additions, 8 deletions
modules/core/events.py
modules/plugins/monitor.py
+44
-0
44 additions, 0 deletions
modules/plugins/monitor.py
with
55 additions
and
8 deletions
modules/core/events.py
+
11
−
8
View file @
3a76b610
...
@@ -27,7 +27,7 @@ from modules.plugins.monitor import AuraMonitor
...
@@ -27,7 +27,7 @@ from modules.plugins.monitor import AuraMonitor
from
modules.core.state
import
PlayerStateService
from
modules.core.state
import
PlayerStateService
from
modules.plugins.trackservice
import
Track
s
erviceHandler
from
modules.plugins.trackservice
import
Track
S
erviceHandler
class
EventBinding
():
class
EventBinding
():
...
@@ -57,7 +57,7 @@ class EventBinding():
...
@@ -57,7 +57,7 @@ class EventBinding():
return
self
return
self
def
get_instance
s
(
self
):
def
get_instance
(
self
):
"""
"""
Returns the object within that binding.
Returns the object within that binding.
"""
"""
...
@@ -77,7 +77,7 @@ class EngineEventDispatcher():
...
@@ -77,7 +77,7 @@ class EngineEventDispatcher():
soundsystem
=
None
soundsystem
=
None
player_state
=
None
player_state
=
None
scheduler
=
None
scheduler
=
None
api_handle
r
=
None
monito
r
=
None
def
__init__
(
self
,
soundsystem
,
scheduler
):
def
__init__
(
self
,
soundsystem
,
scheduler
):
...
@@ -94,7 +94,10 @@ class EngineEventDispatcher():
...
@@ -94,7 +94,10 @@ class EngineEventDispatcher():
binding
=
self
.
attach
(
AuraMonitor
)
binding
=
self
.
attach
(
AuraMonitor
)
binding
.
subscribe
(
"
on_boot
"
)
binding
.
subscribe
(
"
on_boot
"
)
binding
=
self
.
attach
(
TrackserviceHandler
)
binding
.
subscribe
(
"
on_sick
"
)
binding
.
subscribe
(
"
on_resurrect
"
)
binding
=
self
.
attach
(
TrackServiceHandler
)
binding
.
subscribe
(
"
on_play
"
)
binding
.
subscribe
(
"
on_play
"
)
...
@@ -223,20 +226,20 @@ class EngineEventDispatcher():
...
@@ -223,20 +226,20 @@ class EngineEventDispatcher():
self
.
call_event
(
"
on_queue
"
,
entries
)
self
.
call_event
(
"
on_queue
"
,
entries
)
def
on_sick
(
self
):
def
on_sick
(
self
,
data
):
"""
"""
Called when the engine is in some unhealthy state.
Called when the engine is in some unhealthy state.
"""
"""
self
.
logger
.
debug
(
"
on_sick(..)
"
)
self
.
logger
.
debug
(
"
on_sick(..)
"
)
self
.
call_event
(
"
on_sick
"
,
None
)
self
.
call_event
(
"
on_sick
"
,
data
)
def
on_resurrect
(
self
):
def
on_resurrect
(
self
,
data
):
"""
"""
Called when the engine turned healthy again after being sick.
Called when the engine turned healthy again after being sick.
"""
"""
self
.
logger
.
debug
(
"
on_resurrect(..)
"
)
self
.
logger
.
debug
(
"
on_resurrect(..)
"
)
self
.
call_event
(
"
on_resurrect
"
,
None
)
self
.
call_event
(
"
on_resurrect
"
,
data
)
def
on_critical
(
self
,
subject
,
message
,
data
=
None
):
def
on_critical
(
self
,
subject
,
message
,
data
=
None
):
...
...
This diff is collapsed.
Click to expand it.
modules/plugins/monitor.py
+
44
−
0
View file @
3a76b610
...
@@ -18,9 +18,11 @@
...
@@ -18,9 +18,11 @@
import
os
import
os
import
datetime
import
urllib
import
urllib
import
logging
import
logging
import
json
import
json
import
requests
import
threading
import
threading
import
platform
import
platform
...
@@ -115,9 +117,26 @@ class AuraMonitor:
...
@@ -115,9 +117,26 @@ class AuraMonitor:
self
.
logger
.
info
(
"
Status Monitor:
\n
%s
"
%
json
.
dumps
(
status
,
indent
=
4
))
self
.
logger
.
info
(
"
Status Monitor:
\n
%s
"
%
json
.
dumps
(
status
,
indent
=
4
))
if
not
is_valid
:
if
not
is_valid
:
self
.
logger
.
info
(
"
Engine Status:
"
+
SU
.
red
(
status
[
"
engine
"
][
"
status
"
]))
self
.
logger
.
info
(
"
Engine Status:
"
+
SU
.
red
(
status
[
"
engine
"
][
"
status
"
]))
self
.
post_health
(
status
,
False
)
raise
EngineMalfunctionException
raise
EngineMalfunctionException
else
:
else
:
self
.
logger
.
info
(
"
Engine Status:
"
+
SU
.
green
(
"
[OK]
"
))
self
.
logger
.
info
(
"
Engine Status:
"
+
SU
.
green
(
"
[OK]
"
))
self
.
post_health
(
status
,
True
)
def
on_sick
(
self
,
data
):
"""
Called when the engine is in some unhealthy state.
"""
self
.
post_health
(
data
,
False
)
def
on_resurrect
(
self
,
data
):
"""
Called when the engine turned healthy again after being sick.
"""
self
.
post_health
(
data
,
True
)
#
#
...
@@ -172,6 +191,27 @@ class AuraMonitor:
...
@@ -172,6 +191,27 @@ class AuraMonitor:
#
#
def
post_health
(
self
,
data
,
is_healthy
):
"""
Post unhealthy state info to Engine API.
"""
body
=
dict
()
body
[
"
log_time
"
]
=
datetime
.
datetime
.
now
()
body
[
"
is_healthy
"
]
=
is_healthy
body
[
"
details
"
]
=
json
.
dumps
(
data
,
default
=
str
)
json_data
=
json
.
dumps
(
body
,
default
=
str
)
url
=
self
.
config
.
get
(
"
api_engine_store_health
"
)
url
=
url
.
replace
(
"
${ENGINE_NUMBER}
"
,
str
(
self
.
config
.
get
(
"
api_engine_number
"
)))
headers
=
{
'
content-type
'
:
'
application/json
'
}
r
=
requests
.
post
(
url
,
data
=
json_data
,
headers
=
headers
)
if
r
.
status_code
==
204
:
self
.
logger
.
info
(
"
Successfully posted healthy=%s state to Engine API!
"
%
is_healthy
)
else
:
self
.
logger
.
error
(
"
HTTP %s | Error while pushing health state to Engine API: %s
"
%
(
r
.
status_code
,
str
(
r
.
json
())))
def
update_status
(
self
):
def
update_status
(
self
):
"""
"""
Requests the current status of all components
Requests the current status of all components
...
@@ -233,6 +273,8 @@ class AuraMonitor:
...
@@ -233,6 +273,8 @@ class AuraMonitor:
self
.
mailer
.
send_admin_mail
(
\
self
.
mailer
.
send_admin_mail
(
\
"
OK - Engine turned back into some HEALTHY STATE!
"
,
\
"
OK - Engine turned back into some HEALTHY STATE!
"
,
\
"
Things seem fine again at
'
%s
'
:
\n\n
%s
"
%
(
self
.
engine_id
,
status
))
"
Things seem fine again at
'
%s
'
:
\n\n
%s
"
%
(
self
.
engine_id
,
status
))
# Route call of event via event dispatcher to provide ability for additional hooks
self
.
soundsystem
.
event_dispatcher
.
on_resurrect
(
status
)
else
:
else
:
# Engine turned into invalid state
# Engine turned into invalid state
if
not
self
.
already_invalid
:
if
not
self
.
already_invalid
:
...
@@ -242,6 +284,8 @@ class AuraMonitor:
...
@@ -242,6 +284,8 @@ class AuraMonitor:
self
.
mailer
.
send_admin_mail
(
\
self
.
mailer
.
send_admin_mail
(
\
"
ERROR - Engine turned into some INVALID STATE!
"
,
\
"
ERROR - Engine turned into some INVALID STATE!
"
,
\
"
There
'
s an issue with Aura Engine
'
%s
'
:
\n\n
%s
"
%
(
self
.
engine_id
,
status
))
"
There
'
s an issue with Aura Engine
'
%s
'
:
\n\n
%s
"
%
(
self
.
engine_id
,
status
))
# Route call of event via event dispatcher to provide ability for additional hooks
self
.
soundsystem
.
event_dispatcher
.
on_sick
(
status
)
threading
.
Timer
(
self
.
config
.
get
(
"
heartbeat_frequency
"
),
self
.
heartbeat
).
start
()
threading
.
Timer
(
self
.
config
.
get
(
"
heartbeat_frequency
"
),
self
.
heartbeat
).
start
()
...
...
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