Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
K
km3mon
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
km3py
km3mon
Commits
07734295
Commit
07734295
authored
5 years ago
by
Tamas Gal
Browse files
Options
Downloads
Patches
Plain Diff
Add log cycle for MSG dumps
parent
bba4d917
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
scripts/msg_dumper.py
+41
-16
41 additions, 16 deletions
scripts/msg_dumper.py
supervisord_template.conf
+1
-1
1 addition, 1 deletion
supervisord_template.conf
with
42 additions
and
17 deletions
scripts/msg_dumper.py
+
41
−
16
View file @
07734295
...
...
@@ -13,25 +13,49 @@ Usage:
Options:
-l LIGIER_IP The IP of the ligier [default: 127.0.0.1].
-p LIGIER_PORT The port of the ligier [default: 5553].
-f LOG_FILE Log file to dump the messages [default: MSG.log].
-o LOG_DIR Directory to dump the messages [default: logs].
-x PREFIX Prefix for the log files [default: MSG].
-h --help Show this screen.
"""
import
datetime
import
os
import
tim
e
from
shutil
import
copyfil
e
from
km3pipe
import
Pipeline
,
Module
from
km3pipe.io
import
CHPump
def
current_date_str
(
fmt
=
"
%Y-%m-%d
"
):
"""
Return the current datetime string
"""
return
datetime
.
datetime
.
now
().
strftime
(
fmt
)
class
MSGDumper
(
Module
):
def
configure
(
self
):
self
.
filename
=
self
.
get
(
'
filename
'
,
default
=
'
MSG.log
'
)
self
.
fobj
=
open
(
os
.
path
.
abspath
(
self
.
filename
),
'
a
'
)
self
.
path
=
os
.
path
.
abspath
(
self
.
require
(
'
path
'
))
self
.
prefix
=
self
.
require
(
'
prefix
'
)
self
.
current_date
=
current_date_str
()
self
.
filename
=
self
.
prefix
+
"
.log
"
self
.
filepath
=
os
.
path
.
join
(
self
.
path
,
self
.
filename
)
self
.
fobj
=
open
(
self
.
filepath
,
'
a
'
)
def
update_file_descriptor
(
self
):
current_date
=
current_date_str
()
if
self
.
current_date
!=
current_date
:
archived_name
=
"
{}_{}.log
"
.
format
(
self
.
prefix
,
self
.
current_date
)
self
.
print
(
"
Cycling the log file: {} -> {}
"
.
format
(
self
.
filename
,
archived_name
))
copyfile
(
self
.
filepath
,
os
.
path
.
join
(
self
.
path
,
archived_name
))
self
.
fobj
.
close
()
self
.
fobj
=
open
(
self
.
filepath
,
'
w
'
)
self
.
current_date
=
current_date
def
process
(
self
,
blob
):
data
=
blob
[
'
CHData
'
].
decode
()
source
=
"
Other
"
if
"
A0
"
in
data
:
source
=
"
AcousticDataFilter
"
if
"
F0
"
in
data
:
source
=
"
DataFilter
"
if
"
Q0
"
in
data
:
...
...
@@ -39,14 +63,15 @@ class MSGDumper(Module):
if
"
W0
"
in
data
:
source
=
"
DataWriter
"
entry
=
"
{} [{}]: {}
\n
"
.
format
(
os
.
path
.
basename
(
self
.
filename
),
source
,
data
)
entry
=
"
{} [{}]: {}
\n
"
.
format
(
self
.
filename
,
source
,
data
)
self
.
update_file_descriptor
(
)
self
.
fobj
.
write
(
entry
)
self
.
fobj
.
flush
()
return
blob
def
finish
(
self
):
self
.
fobj
.
close
()
if
self
.
fobj
is
not
None
:
self
.
fobj
.
close
()
def
main
():
...
...
@@ -55,17 +80,17 @@ def main():
ligier_ip
=
args
[
'
-l
'
]
ligier_port
=
int
(
args
[
'
-p
'
])
filename
=
args
[
'
-f
'
]
path
=
args
[
'
-o
'
]
prefix
=
args
[
'
-x
'
]
pipe
=
Pipeline
()
pipe
.
attach
(
CHPump
,
host
=
ligier_ip
,
port
=
ligier_port
,
tags
=
'
MSG
'
,
timeout
=
7
*
60
*
60
*
24
,
max_queue
=
500
)
pipe
.
attach
(
MSGDumper
,
filename
=
filename
)
pipe
.
attach
(
CHPump
,
host
=
ligier_ip
,
port
=
ligier_port
,
tags
=
'
MSG
'
,
timeout
=
7
*
60
*
60
*
24
,
max_queue
=
500
)
pipe
.
attach
(
MSGDumper
,
prefix
=
prefix
,
path
=
path
)
pipe
.
drain
()
...
...
This diff is collapsed.
Click to expand it.
supervisord_template.conf
+
1
−
1
View file @
07734295
...
...
@@ -146,7 +146,7 @@ stderr_logfile=logs/%(program_name)s.err.log
;
stderr_logfile
=
logs
/%(
program_name
)
s
.
err
.
log
[
program
:
msg_dumper
]
command
=
python
-
u
scripts
/
msg_dumper
.
py
-
l
%(
ENV_LOG_LIGIER_IP
)
s
-
p
%(
ENV_LOG_LIGIER_PORT
)
s
-
f
logs
/
MSG
.
log
command
=
python
-
u
scripts
/
msg_dumper
.
py
-
l
%(
ENV_LOG_LIGIER_IP
)
s
-
p
%(
ENV_LOG_LIGIER_PORT
)
s
-
o
logs
priority
=
200
stdout_logfile
=
logs
/%(
program_name
)
s
.
out
.
log
stderr_logfile
=
logs
/%(
program_name
)
s
.
err
.
log
...
...
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