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
6
Merge Requests
6
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
slapos.toolbox
Commits
ee4f5b89
Commit
ee4f5b89
authored
Nov 29, 2012
by
Marco Mariani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
read postgres .pid files; import cleanup
parent
af114351
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
18 deletions
+20
-18
slapos/monitor.py
slapos/monitor.py
+20
-18
No files found.
slapos/monitor.py
View file @
ee4f5b89
...
...
@@ -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,10 +333,7 @@ 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
]))
SlapMonitor
(
proc
,
opts
.
update_time
,
args
[
1
])
def
run_slapreport_
():
...
...
@@ -371,15 +376,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