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
Hide 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):
...
@@ -46,8 +46,11 @@ class Application(object):
self
.
getAddress
()[
-
1
],
self
.
getAddress
()[
-
1
],
self
.
pid
()))
self
.
pid
()))
def
stop
(
self
):
def
stop
(
self
,
pid
=
None
):
if
hasattr
(
self
,
'process'
):
if
hasattr
(
self
,
'process'
):
if
pid
is
not
None
and
self
.
process
.
pid
!=
pid
:
# pid already stopped
return
False
error
=
False
error
=
False
process_pid
=
self
.
process
.
pid
process_pid
=
self
.
process
.
pid
returncode
=
self
.
process
.
poll
()
returncode
=
self
.
process
.
poll
()
...
@@ -85,6 +88,7 @@ class Application(object):
...
@@ -85,6 +88,7 @@ class Application(object):
self
.
daemonOutputLog
()
self
.
daemonOutputLog
()
logger
.
debug
(
"Process %s ended with returncode %s"
,
process_pid
,
returncode
)
logger
.
debug
(
"Process %s ended with returncode %s"
,
process_pid
,
returncode
)
delattr
(
self
,
"process"
)
delattr
(
self
,
"process"
)
return
True
def
daemonOutputLog
(
self
):
def
daemonOutputLog
(
self
):
if
hasattr
(
self
,
'process'
):
if
hasattr
(
self
,
'process'
):
...
...
cloudooo/handler/ooo/application/openoffice.py
View file @
0ec77252
...
@@ -164,11 +164,11 @@ class OpenOffice(Application):
...
@@ -164,11 +164,11 @@ class OpenOffice(Application):
self
.
_cleanRequest
()
self
.
_cleanRequest
()
Application
.
start
(
self
)
Application
.
start
(
self
)
def
stop
(
self
):
def
stop
(
self
,
pid
=
None
):
"""Stop the instance by pid. By the default
"""Stop the instance by pid. By the default
the signal is 15."""
the signal is 15."""
Application
.
stop
(
self
)
if
Application
.
stop
(
self
,
pid
=
pid
):
self
.
_cleanRequest
()
self
.
_cleanRequest
()
def
isLocked
(
self
):
def
isLocked
(
self
):
"""Verify if OOo instance is being used."""
"""Verify if OOo instance is being used."""
...
...
cloudooo/handler/ooo/monitor/memory.py
View file @
0ec77252
...
@@ -44,15 +44,18 @@ class MonitorMemory(Monitor, Process):
...
@@ -44,15 +44,18 @@ class MonitorMemory(Monitor, Process):
Process
.
__init__
(
self
)
Process
.
__init__
(
self
)
self
.
limit
=
limit_memory_usage
self
.
limit
=
limit_memory_usage
def
create_process
(
self
):
def
create_process
(
self
,
pid
):
self
.
process
=
psutil
.
Process
(
int
(
self
.
openoffice
.
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
:
try
:
if
not
hasattr
(
self
,
'process'
)
or
\
process
=
self
.
create_process
(
pid
)
self
.
process
.
pid
!=
int
(
self
.
openoffice
.
pid
()):
return
process
.
memory_info
().
rss
/
(
1024
*
1024
)
self
.
create_process
()
return
self
.
process
.
memory_info
().
rss
/
(
1024
*
1024
)
except
TypeError
:
except
TypeError
:
logger
.
debug
(
"OpenOffice is stopped"
)
logger
.
debug
(
"OpenOffice is stopped"
)
return
0
return
0
...
@@ -69,9 +72,10 @@ class MonitorMemory(Monitor, Process):
...
@@ -69,9 +72,10 @@ class MonitorMemory(Monitor, Process):
self
.
status_flag
=
True
self
.
status_flag
=
True
logger
.
debug
(
"Start MonitorMemory"
)
logger
.
debug
(
"Start MonitorMemory"
)
while
self
.
status_flag
:
while
self
.
status_flag
:
if
self
.
get_memory_usage
()
>
self
.
limit
:
pid
=
self
.
openoffice
.
pid
()
logger
.
debug
(
"Stopping OpenOffice"
)
if
self
.
get_memory_usage
(
pid
)
>
self
.
limit
:
self
.
openoffice
.
stop
()
logger
.
debug
(
"Stopping OpenOffice on memory limit increase"
)
self
.
openoffice
.
stop
(
pid
=
pid
)
sleep
(
self
.
interval
)
sleep
(
self
.
interval
)
logger
.
debug
(
"Stop MonitorMemory"
)
logger
.
debug
(
"Stop MonitorMemory"
)
...
...
cloudooo/handler/ooo/monitor/timeout.py
View file @
0ec77252
...
@@ -50,7 +50,9 @@ class MonitorTimeout(Monitor, Process):
...
@@ -50,7 +50,9 @@ class MonitorTimeout(Monitor, Process):
sleep
(
self
.
interval
)
sleep
(
self
.
interval
)
if
self
.
openoffice
.
isLocked
():
if
self
.
openoffice
.
isLocked
():
logger
.
debug
(
"Stop OpenOffice - Port %s - Pid %s"
%
(
port
,
pid
))
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
):
def
terminate
(
self
):
"""Stop the process"""
"""Stop the process"""
...
...
cloudooo/handler/ooo/tests/testOooMonitorMemory.py
View file @
0ec77252
...
@@ -90,7 +90,7 @@ class TestMonitorMemory(unittest.TestCase):
...
@@ -90,7 +90,7 @@ class TestMonitorMemory(unittest.TestCase):
def
testCreateProcess
(
self
):
def
testCreateProcess
(
self
):
"""Test if the psutil.Process is create correctly"""
"""Test if the psutil.Process is create correctly"""
self
.
monitor
=
MonitorMemory
(
openoffice
,
2
,
400
)
self
.
monitor
=
MonitorMemory
(
openoffice
,
2
,
400
)
self
.
monitor
.
create_process
()
self
.
monitor
.
create_process
(
openoffice
.
pid
()
)
self
.
assertTrue
(
hasattr
(
self
.
monitor
,
'process'
))
self
.
assertTrue
(
hasattr
(
self
.
monitor
,
'process'
))
self
.
assertEquals
(
type
(
self
.
monitor
.
process
),
Process
)
self
.
assertEquals
(
type
(
self
.
monitor
.
process
),
Process
)
...
@@ -98,11 +98,11 @@ class TestMonitorMemory(unittest.TestCase):
...
@@ -98,11 +98,11 @@ class TestMonitorMemory(unittest.TestCase):
"""Test memory usage"""
"""Test memory usage"""
self
.
monitor
=
MonitorMemory
(
openoffice
,
2
,
400
)
self
.
monitor
=
MonitorMemory
(
openoffice
,
2
,
400
)
openoffice
.
stop
()
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
)
self
.
assertEquals
(
memory_usage_int
,
0
)
if
not
openoffice
.
status
():
if
not
openoffice
.
status
():
openoffice
.
start
()
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
)
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