Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cloudooo
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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boris Kocherov
cloudooo
Commits
0ec77252
Commit
0ec77252
authored
May 25, 2019
by
Boris Kocherov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix memory monitor
parent
e4ba9a63
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
28 additions
and
18 deletions
+28
-18
cloudooo/handler/ooo/application/application.py
cloudooo/handler/ooo/application/application.py
+5
-1
cloudooo/handler/ooo/application/openoffice.py
cloudooo/handler/ooo/application/openoffice.py
+3
-3
cloudooo/handler/ooo/monitor/memory.py
cloudooo/handler/ooo/monitor/memory.py
+14
-10
cloudooo/handler/ooo/monitor/timeout.py
cloudooo/handler/ooo/monitor/timeout.py
+3
-1
cloudooo/handler/ooo/tests/testOooMonitorMemory.py
cloudooo/handler/ooo/tests/testOooMonitorMemory.py
+3
-3
No files found.
cloudooo/handler/ooo/application/application.py
View file @
0ec77252
...
...
@@ -46,8 +46,11 @@ class Application(object):
self
.
getAddress
()[
-
1
],
self
.
pid
()))
def
stop
(
self
):
def
stop
(
self
,
pid
=
None
):
if
hasattr
(
self
,
'process'
):
if
pid
is
not
None
and
self
.
process
.
pid
!=
pid
:
# pid already stopped
return
False
error
=
False
process_pid
=
self
.
process
.
pid
returncode
=
self
.
process
.
poll
()
...
...
@@ -85,6 +88,7 @@ class Application(object):
self
.
daemonOutputLog
()
logger
.
debug
(
"Process %s ended with returncode %s"
,
process_pid
,
returncode
)
delattr
(
self
,
"process"
)
return
True
def
daemonOutputLog
(
self
):
if
hasattr
(
self
,
'process'
):
...
...
cloudooo/handler/ooo/application/openoffice.py
View file @
0ec77252
...
...
@@ -164,10 +164,10 @@ class OpenOffice(Application):
self
.
_cleanRequest
()
Application
.
start
(
self
)
def
stop
(
self
):
def
stop
(
self
,
pid
=
None
):
"""Stop the instance by pid. By the default
the signal is 15."""
Application
.
stop
(
self
)
if
Application
.
stop
(
self
,
pid
=
pid
):
self
.
_cleanRequest
()
def
isLocked
(
self
):
...
...
cloudooo/handler/ooo/monitor/memory.py
View file @
0ec77252
...
...
@@ -44,15 +44,18 @@ class MonitorMemory(Monitor, Process):
Process
.
__init__
(
self
)
self
.
limit
=
limit_memory_usage
def
create_process
(
self
):
self
.
process
=
psutil
.
Process
(
int
(
self
.
openoffice
.
pid
()))
def
create_process
(
self
,
pid
):
if
not
hasattr
(
self
,
'process'
)
or
\
self
.
process
.
pid
!=
int
(
pid
):
self
.
process
=
psutil
.
Process
(
pid
)
return
self
.
process
def
get_memory_usage
(
self
):
def
get_memory_usage
(
self
,
pid
):
if
pid
is
None
:
return
0
try
:
if
not
hasattr
(
self
,
'process'
)
or
\
self
.
process
.
pid
!=
int
(
self
.
openoffice
.
pid
()):
self
.
create_process
()
return
self
.
process
.
memory_info
().
rss
/
(
1024
*
1024
)
process
=
self
.
create_process
(
pid
)
return
process
.
memory_info
().
rss
/
(
1024
*
1024
)
except
TypeError
:
logger
.
debug
(
"OpenOffice is stopped"
)
return
0
...
...
@@ -69,9 +72,10 @@ class MonitorMemory(Monitor, Process):
self
.
status_flag
=
True
logger
.
debug
(
"Start MonitorMemory"
)
while
self
.
status_flag
:
if
self
.
get_memory_usage
()
>
self
.
limit
:
logger
.
debug
(
"Stopping OpenOffice"
)
self
.
openoffice
.
stop
()
pid
=
self
.
openoffice
.
pid
()
if
self
.
get_memory_usage
(
pid
)
>
self
.
limit
:
logger
.
debug
(
"Stopping OpenOffice on memory limit increase"
)
self
.
openoffice
.
stop
(
pid
=
pid
)
sleep
(
self
.
interval
)
logger
.
debug
(
"Stop MonitorMemory"
)
...
...
cloudooo/handler/ooo/monitor/timeout.py
View file @
0ec77252
...
...
@@ -50,7 +50,9 @@ class MonitorTimeout(Monitor, Process):
sleep
(
self
.
interval
)
if
self
.
openoffice
.
isLocked
():
logger
.
debug
(
"Stop OpenOffice - Port %s - Pid %s"
%
(
port
,
pid
))
self
.
openoffice
.
stop
()
# using pid is not necessary here
# but safe if incorrect use
self
.
openoffice
.
stop
(
pid
=
pid
)
def
terminate
(
self
):
"""Stop the process"""
...
...
cloudooo/handler/ooo/tests/testOooMonitorMemory.py
View file @
0ec77252
...
...
@@ -90,7 +90,7 @@ class TestMonitorMemory(unittest.TestCase):
def
testCreateProcess
(
self
):
"""Test if the psutil.Process is create correctly"""
self
.
monitor
=
MonitorMemory
(
openoffice
,
2
,
400
)
self
.
monitor
.
create_process
()
self
.
monitor
.
create_process
(
openoffice
.
pid
()
)
self
.
assertTrue
(
hasattr
(
self
.
monitor
,
'process'
))
self
.
assertEquals
(
type
(
self
.
monitor
.
process
),
Process
)
...
...
@@ -98,11 +98,11 @@ class TestMonitorMemory(unittest.TestCase):
"""Test memory usage"""
self
.
monitor
=
MonitorMemory
(
openoffice
,
2
,
400
)
openoffice
.
stop
()
memory_usage_int
=
self
.
monitor
.
get_memory_usage
()
memory_usage_int
=
self
.
monitor
.
get_memory_usage
(
openoffice
.
pid
()
)
self
.
assertEquals
(
memory_usage_int
,
0
)
if
not
openoffice
.
status
():
openoffice
.
start
()
memory_usage_int
=
self
.
monitor
.
get_memory_usage
()
memory_usage_int
=
self
.
monitor
.
get_memory_usage
(
openoffice
.
pid
()
)
self
.
assertEquals
(
type
(
memory_usage_int
),
IntType
)
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