Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
slapos
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Iliya Manolov
slapos
Commits
5f052cce
Commit
5f052cce
authored
Dec 19, 2013
by
Nicolas Wavrant
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
stack-monitor: monitor.py now takes args for modularity
parent
6283e389
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
71 additions
and
21 deletions
+71
-21
stack/monitor/monitor.cfg.in
stack/monitor/monitor.cfg.in
+3
-3
stack/monitor/monitor.py.in
stack/monitor/monitor.py.in
+68
-18
No files found.
stack/monitor/monitor.cfg.in
View file @
5f052cce
...
@@ -21,7 +21,7 @@ log = $${:var}/log
...
@@ -21,7 +21,7 @@ log = $${:var}/log
monitor = $${:etc}/monitor
monitor = $${:etc}/monitor
monitor-result = $${:var}/monitor
monitor-result = $${:var}/monitor
promise = $${:etc}/promise
promise = $${:etc}/promise
run = $${:
etc
}/run
run = $${:
var
}/run
service = $${:etc}/service/
service = $${:etc}/service/
tmp = $${:home}/tmp
tmp = $${:home}/tmp
www = $${:var}/www
www = $${:var}/www
...
@@ -46,7 +46,7 @@ log = $${directory:log}/cron.log
...
@@ -46,7 +46,7 @@ log = $${directory:log}/cron.log
recipe = slapos.cookbook:cron.d
recipe = slapos.cookbook:cron.d
name = launch-monitor
name = launch-monitor
frequency = * * * * *
frequency = * * * * *
command = $${deploy-monitor-script:rendered}
command = $${deploy-monitor-script:rendered}
-a
[cron-entry-rss]
[cron-entry-rss]
<= cron
<= cron
...
@@ -126,7 +126,7 @@ global-ip = $${slap-parameters:ipv6}
...
@@ -126,7 +126,7 @@ global-ip = $${slap-parameters:ipv6}
ssl-certificate = $${ca-nginx:cert-file}
ssl-certificate = $${ca-nginx:cert-file}
ssl-key = $${ca-nginx:key-file}
ssl-key = $${ca-nginx:key-file}
# Log
# Log
path_pid = $${directory:run}/nginx.pid
path_pid = $${directory:run}/nginx
-rss
.pid
path_log = $${directory:log}/nginx.log
path_log = $${directory:log}/nginx.log
path_access_log = $${directory:log}/nginx.access.log
path_access_log = $${directory:log}/nginx.access.log
path_error_log = $${directory:log}/nginx.error.log
path_error_log = $${directory:log}/nginx.error.log
...
...
stack/monitor/monitor.py.in
View file @
5f052cce
...
@@ -5,31 +5,57 @@ import os
...
@@ -5,31 +5,57 @@ import os
import
subprocess
import
subprocess
import
sys
import
sys
import
time
import
time
from
optparse
import
OptionParser
,
make_option
promise_dir
=
"{{ directory['promise'] }}"
service_dir
=
"{{ directory['service'] }}"
monitor_dir
=
"{{ directory['monitor'] }}"
instance_path
=
"{{ directory['home'] }}"
instance_path
=
"{{ directory['home'] }}"
monitor_dir
=
"{{ directory['monitor'] }}"
pid_dir
=
"{{ directory['run'] }}"
promise_dir
=
"{{ directory['promise'] }}"
monitoring_file_json
=
"{{ monitoring_file_json }}"
monitoring_file_bool
=
"{{ monitoring_file_bool }}"
monitoring_file_bool
=
"{{ monitoring_file_bool }}"
monitoring_file_json
=
"{{ monitoring_file_json }}"
option_list
=
[
make_option
(
"-a"
,
"--all"
,
action
=
"store_true"
,
dest
=
"all"
,
help
=
"test everything : promises, services, customs"
),
make_option
(
"-n"
,
"--no-write"
,
action
=
"store_true"
,
dest
=
"only_stdout"
,
help
=
"just show the json output on stdout"
),
make_option
(
"-m"
,
"--monitors"
,
action
=
"store_true"
,
dest
=
"monitor"
,
help
=
"add the custom monitoring file to the files to monitor"
),
make_option
(
"-p"
,
"--promises"
,
action
=
"store_true"
,
dest
=
"promise"
,
help
=
"add the promises
\
'
file to the files to monitor"
),
make_option
(
"-s"
,
"--services"
,
action
=
"store_true"
,
dest
=
"service"
,
help
=
"add the file containing services
\
'
pid to the files to monitor"
)
]
def
getListOfScripts
():
def
getListOfScripts
(
directory
):
scripts
=
[]
scripts
=
[]
for
dir
in
(
promise_dir
,
monitor_dir
):
if
os
.
path
.
exists
(
directory
)
and
os
.
path
.
isdir
(
directory
):
if
os
.
path
.
exists
(
dir
)
and
os
.
path
.
isdir
(
dir
):
for
file
in
os
.
listdir
(
directory
):
for
file
in
os
.
listdir
(
dir
):
scripts
.
append
(
os
.
path
.
join
(
directory
,
file
))
scripts
.
append
(
os
.
path
.
join
(
dir
,
file
))
if
scripts
:
return
scripts
else
:
else
:
exit
(
"There is a problem in your directories"
\
exit
(
"There is a problem in your directories"
\
"of monitoring. Please check them"
)
"of monitoring. Please check them"
)
return
scripts
def
runServices
(
directory
):
services
=
getListOfScripts
(
directory
)
result
=
{}
for
service
in
services
:
service_path
=
os
.
path
.
join
(
pid_dir
,
service
)
service_name
=
os
.
path
.
basename
(
service_path
)
pid
=
int
(
open
(
service_path
).
read
())
try
:
os
.
kill
(
pid
,
0
)
result
[
service_name
]
=
''
except
OSError
:
result
[
service_name
]
=
"This service is not running anymore"
return
result
def
run
(
):
def
run
Scripts
(
directory
):
scripts
=
getListOfScripts
()
scripts
=
getListOfScripts
(
directory
)
script_timeout
=
3
script_timeout
=
3
result
=
{}
result
=
{}
for
script
in
scripts
:
for
script
in
scripts
:
...
@@ -59,12 +85,36 @@ def run():
...
@@ -59,12 +85,36 @@ def run():
return
result
return
result
if
__name__
==
"__main__"
:
def
writeFiles
(
monitors
):
monitors
=
run
()
open
(
monitoring_file_json
,
"w+"
).
write
(
json
.
dumps
(
monitors
))
open
(
monitoring_file_json
,
"w+"
).
write
(
json
.
dumps
(
fails
))
if
len
(
monitors
)
==
0
:
if
len
(
monitors
)
==
0
:
open
(
monitoring_file_bool
,
"w+"
).
write
(
"SUCCESS : everything is ok"
)
open
(
monitoring_file_bool
,
"w+"
).
write
(
"SUCCESS : everything is ok"
)
exit
(
0
)
else
:
else
:
open
(
monitoring_file_bool
,
"w+"
).
write
(
"FAILURE : something went wrong"
)
open
(
monitoring_file_bool
,
"w+"
).
write
(
"FAILURE : something went wrong"
)
if
__name__
==
"__main__"
:
parser
=
OptionParser
(
option_list
=
option_list
)
monitors
=
{}
(
options
,
args
)
=
parser
.
parse_args
()
if
not
(
options
.
monitor
or
options
.
promise
or
options
.
service
or
options
.
all
):
exit
(
"Please provide at list one arg in : -a, -m, -p, -s"
)
if
options
.
monitor
or
options
.
all
:
monitors
.
update
(
runScripts
(
monitor_dir
))
if
options
.
promise
or
options
.
all
:
monitors
.
update
(
runScripts
(
promise_dir
))
if
options
.
service
or
options
.
all
:
monitors
.
update
(
runServices
(
pid_dir
))
if
options
.
only_stdout
:
print
json
.
dumps
(
monitors
)
else
:
writeFiles
(
monitors
)
if
len
(
monitors
)
==
0
:
exit
(
0
)
else
:
exit
(
1
)
exit
(
1
)
\ No newline at end of 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