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
Iliya Manolov
slapos.toolbox
Commits
848a10f0
Commit
848a10f0
authored
Dec 03, 2012
by
Marco Mariani
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'slapmonitor'
parents
fd078caf
8ab1ea86
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
18 deletions
+41
-18
setup.py
setup.py
+1
-0
slapos/monitor.py
slapos/monitor.py
+40
-18
No files found.
setup.py
View file @
848a10f0
...
...
@@ -65,6 +65,7 @@ setup(name=name,
'shacache = slapos.shacache:main'
,
'slapbuilder = slapos.builder:main'
,
'slapmonitor = slapos.monitor:run_slapmonitor'
,
'slapmonitor-xml = slapos.monitor:run_slapmonitor_xml'
,
'slapreport = slapos.monitor:run_slapreport'
,
'slaprunner = slapos.runner:run'
,
'killpidfromfile = slapos.systool:killpidfromfile'
,
...
...
slapos/monitor.py
View file @
848a10f0
...
...
@@ -25,20 +25,28 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
import
datetime
import
os
import
time
from
time
import
strftime
import
logging
import
optparse
import
os
import
sys
import
time
from
lxml
import
etree
as
ElementTree
import
psutil
from
optparse
import
OptionParser
import
sqlite3.dbapi2
as
sqlite3
import
psutil
#define global variable for log file
log_file
=
False
def
read_pid
(
path
):
with
open
(
path
,
'r'
)
as
fin
:
# pid file might contain other stuff we don't care about (ie. postgres)
pid
=
fin
.
readline
()
return
int
(
pid
)
class
MonitoringTool
(
object
):
"""Provide functions to monitor CPU and Memory"""
def
__init__
(
self
):
...
...
@@ -196,7 +204,7 @@ def parse_opt():
usage
=
"""usage: slapmonitor [options] PID_FILE_PATH DATABASE_PATH
Usage: slapreport [options] LOG_PATH DATABASE_PATH LOGBOX_IP LOGBOX_PORT LOGBOX_LOGIN LOGBOX_PASSWORD"""
parser
=
OptionParser
(
usage
=
usage
)
parser
=
optparse
.
OptionParser
(
usage
=
usage
)
parser
.
add_option
(
'-t'
,
'--update_time'
,
type
=
int
,
dest
=
'update_time'
,
help
=
'Specify the interval'
\
'(in seconds) to check resources consumption [default 30 seconds]'
,
default
=
3
)
parser
.
add_option
(
'-l'
,
'--log_file'
,
dest
=
'path_log_file'
,
help
=
'Specify the logfile destination path'
,
...
...
@@ -235,7 +243,7 @@ class SlapMonitor(object):
except
IOError
:
if
log_file
:
logging
.
info
(
"ERROR : process with pid : %s watched by slap monitor exited too quickly at %s"
%
(
self
.
proc
.
pid
,
strftime
(
"%Y-%m-%d at %H:%m"
)))
%
(
self
.
proc
.
pid
,
time
.
strftime
(
"%Y-%m-%d at %H:%m"
)))
sys
.
exit
(
1
)
if
log_file
:
logging
.
info
(
"EXIT 0: Process terminated normally!"
)
...
...
@@ -285,7 +293,7 @@ class SlapReport(object):
except
Exception
:
if
log_file
:
logging
.
info
(
"ERROR : Unable to connect to % at %s"
%
(
self
.
ssh_parameters
[
'ip'
],
strftime
(
"%Y-%m-%d at %H:%m"
)))
%
(
self
.
ssh_parameters
[
'ip'
],
time
.
strftime
(
"%Y-%m-%d at %H:%m"
)))
#sys.exit(1)
cursor
.
close
()
...
...
@@ -307,7 +315,7 @@ class SlapReport(object):
except
IOError
:
if
log_file
:
logging
.
info
(
"ERROR : process with pid : %s watched by slap monitor exited too quickly at %s"
%
(
self
.
proc
.
pid
,
strftime
(
"%Y-%m-%d at %H:%m"
)))
%
(
self
.
proc
.
pid
,
time
.
strftime
(
"%Y-%m-%d at %H:%m"
)))
sys
.
exit
(
1
)
if
log_file
:
logging
.
info
(
"EXIT 0: Process terminated normally!"
)
...
...
@@ -325,12 +333,29 @@ def run_slapmonitor():
global
log_file
log_file
=
True
fed
=
open
(
args
[
0
],
'r'
)
pid_read
=
fed
.
read
()
fed
.
close
()
proc
=
psutil
.
Process
(
int
(
pid_read
))
proc
=
psutil
.
Process
(
read_pid
(
args
[
0
]))
# XXX FIXME: THE PID IS ONLY READ ONCE.
# process death and pid reuse are not detected.
SlapMonitor
(
proc
,
opts
.
update_time
,
args
[
1
])
def
run_slapmonitor_xml
():
#This function require the database path and XML path
parser
=
parse_opt
()
opts
,
args
=
parser
.
parse_args
()
if
len
(
args
)
!=
2
:
parser
.
error
(
"Incorrect number of arguments, 2 required but "
+
str
(
len
(
args
))
+
" detected"
)
if
opts
.
path_log_file
:
logging
.
basicConfig
(
filename
=
opts
.
path_log_file
,
level
=
logging
.
DEBUG
)
global
log_file
log_file
=
True
get_xml_hand
=
GenerateXML
(
ElementTree
,
args
[
0
],
args
[
1
])
get_xml_hand
.
dump_xml
()
def
run_slapreport_
():
#This function require the xml_path and database_path
parser
=
parse_opt
()
...
...
@@ -371,15 +396,12 @@ def run_slapreport():
ssh_parameters
[
'passwd'
]
=
args
[
6
]
try
:
fed
=
open
(
pid_file_path
,
'r'
)
pid_read
=
fed
.
read
()
fed
.
close
()
proc
=
psutil
.
Process
(
int
(
pid_read
))
proc
=
psutil
.
Process
(
read_pid
(
pid_file_path
))
SlapReport
(
proc
,
opts
.
update_time
,
args
[
1
],
args
[
2
],
ssh_parameters
)
except
IOError
:
if
log_file
:
logging
.
info
(
"ERROR : process with pid : %s watched by slap monitor exited too quickly at %s"
%
(
proc
.
pid
,
strftime
(
"%Y-%m-%d at %H:%m"
)))
%
(
proc
.
pid
,
time
.
strftime
(
"%Y-%m-%d at %H:%m"
)))
sys
.
exit
(
1
)
if
log_file
:
...
...
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