Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.toolbox
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Lisa Casino
slapos.toolbox
Commits
77f49bd2
Commit
77f49bd2
authored
Jun 12, 2017
by
Alain Takoudjou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
monitor: prevent to run collect when another instance is running
parent
c2e0df76
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
2 deletions
+24
-2
slapos/monitor/collect.py
slapos/monitor/collect.py
+19
-0
slapos/monitor/monitor.py
slapos/monitor/monitor.py
+5
-2
No files found.
slapos/monitor/collect.py
View file @
77f49bd2
...
...
@@ -45,6 +45,8 @@ def parseArguments():
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
'--output_folder'
,
help
=
'Path of the folder where output files should be written.'
)
parser
.
add_argument
(
'--pid_file'
,
help
=
'Path where should be written the pid of process.'
)
parser
.
add_argument
(
'--partition_id'
,
help
=
'ID of the computer partition to collect data from.'
)
parser
.
add_argument
(
'--collector_db'
,
...
...
@@ -291,6 +293,20 @@ def main():
if
not
os
.
path
.
exists
(
parser
.
output_folder
)
and
os
.
path
.
isdir
(
parser
.
output_folder
):
raise
Exception
(
"Invalid ouput folder: %s"
%
parser
.
output_folder
)
if
parser
.
pid_file
:
# Check that this process is not running
if
os
.
path
.
exists
(
parser
.
pid_file
):
with
open
(
parser
.
pid_file
,
"r"
)
as
pidfile
:
try
:
pid
=
int
(
pidfile
.
read
(
6
))
except
ValueError
:
pid
=
None
if
pid
and
os
.
path
.
exists
(
"/proc/"
+
str
(
pid
)):
print
(
"A process is already running with pid "
+
str
(
pid
))
exit
(
1
)
with
open
(
parser
.
pid_file
,
"w"
)
as
pidfile
:
pidfile
.
write
(
'%s'
%
os
.
getpid
())
# Consumption global status
process_file
=
os
.
path
.
join
(
parser
.
output_folder
,
'monitor_resource_process.data.json'
)
mem_file
=
os
.
path
.
join
(
parser
.
output_folder
,
'monitor_resource_memory.data.json'
)
...
...
@@ -354,3 +370,6 @@ def main():
if
resource_process_status_list
:
with
open
(
resource_file
,
'w'
)
as
rf
:
rf
.
write
(
json
.
dumps
(
resource_process_status_list
))
if
os
.
path
.
exists
(
parser
.
pid_file
):
os
.
unlink
(
parser
.
pid_file
)
slapos/monitor/monitor.py
View file @
77f49bd2
...
...
@@ -522,8 +522,11 @@ class Monitoring(object):
if
self
.
nice_command
:
# run monitor collect with low priority
command
+=
'%s '
%
self
.
nice_command
command
+=
"%s --output_folder %s --collector_db %s"
%
(
self
.
collect_script
,
self
.
data_folder
,
self
.
collector_db
)
command
+=
"%s --output_folder %s --collector_db %s --pid_file %s"
%
(
self
.
collect_script
,
self
.
data_folder
,
self
.
collector_db
,
os
.
path
.
join
(
self
.
service_pid_folder
,
"monitor-collect.pid"
))
self
.
addCronEntry
(
'monitor_collect'
,
'* * * * *'
,
command
)
# Write an empty file when monitor bootstrap went until the end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment