Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
inventory-provider
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
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
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
geant-swd
dashboardv3
inventory-provider
Commits
13044021
Commit
13044021
authored
4 years ago
by
Erik Reid
Browse files
Options
Downloads
Patches
Plain Diff
setup logging
parent
56cf8b65
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
inventory_provider/tasks/monitor.py
+23
-24
23 additions, 24 deletions
inventory_provider/tasks/monitor.py
with
23 additions
and
24 deletions
inventory_provider/tasks/monitor.py
+
23
−
24
View file @
13044021
"""
standalone process that monitors celery task events and
writes them to redis for reporting
as with the other processes, INVENTORY_PROVIDER_CONFIG_FILENAME
must be defined in the environment
"""
import
json
import
logging
import
os
from
inventory_provider
import
config
,
environment
from
inventory_provider.tasks.worker
import
app
from
inventory_provider.tasks.common
import
get_current_redis
from
threading
import
Thread
logger
=
logging
.
getLogger
(
__name__
)
INFO_EVENT_TYPES
=
(
'
task-info
'
,
'
task-warning
'
,
'
task-error
'
)
def
_monitor_proc
(
config
):
def
run
():
"""
save
'
task-*
'
events to redis, never returns
"""
environment
.
setup_logging
()
with
open
(
os
.
environ
[
'
INVENTORY_PROVIDER_CONFIG_FILENAME
'
])
as
f
:
logging
.
info
(
'
loading config from: %r
'
%
os
.
environ
[
'
INVENTORY_PROVIDER_CONFIG_FILENAME
'
])
config_params
=
config
.
load
(
f
)
state
=
app
.
events
.
State
()
...
...
@@ -23,26 +40,20 @@ def _monitor_proc(config):
if
event
[
'
type
'
]
in
INFO_EVENT_TYPES
:
key
+=
f
'
:
{
event
[
"
clock
"
]
}
'
r
=
get_current_redis
(
config
)
r
=
get_current_redis
(
config
_params
)
r
.
set
(
key
,
json
.
dumps
(
event
))
logger
.
debug
(
f
'
{
key
}
:
{
json
.
dumps
(
event
)
}
'
)
with
app
.
connection
()
as
connection
:
recv
=
app
.
events
.
Receiver
(
connection
,
handlers
=
{
'
*
'
:
_log_event
,
'
*
'
:
_log_event
})
recv
.
capture
(
limit
=
None
,
timeout
=
None
,
wakeup
=
True
)
def
start_monitoring
():
thread
=
Thread
(
target
=
_monitor_proc
,
args
=
())
thread
.
start
()
def
clear_joblog
(
r
):
"""
:param r:
:return:
"""
...
...
@@ -53,17 +64,5 @@ def clear_joblog(r):
if
__name__
==
'
__main__
'
:
import
os
from
inventory_provider
import
config
logging
.
basicConfig
(
level
=
logging
.
DEBUG
)
filename
=
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'
..
'
,
'
config-sentinel.json
'
)
with
open
(
filename
)
as
f
:
params
=
config
.
load
(
f
)
_monitor_proc
(
params
)
run
()
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