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
Vincent Bechu
slapos
Commits
6283e389
Commit
6283e389
authored
Dec 19, 2013
by
Nicolas Wavrant
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
stack-monitor: monitor.py directly writes files, and is directly called by cron
it now also writes all results in the json
parent
9ca5848d
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
20 additions
and
45 deletions
+20
-45
stack/monitor/buildout.cfg
stack/monitor/buildout.cfg
+0
-8
stack/monitor/monitor.cfg.in
stack/monitor/monitor.cfg.in
+3
-13
stack/monitor/monitor.py.in
stack/monitor/monitor.py.in
+17
-20
stack/monitor/run-monitor-script.sh.in
stack/monitor/run-monitor-script.sh.in
+0
-4
No files found.
stack/monitor/buildout.cfg
View file @
6283e389
...
@@ -37,14 +37,6 @@ url = ${:_profile_base_location_}/make-rss.sh.in
...
@@ -37,14 +37,6 @@ url = ${:_profile_base_location_}/make-rss.sh.in
output = ${buildout:directory}/make-rss.sh.in
output = ${buildout:directory}/make-rss.sh.in
mode = 0644
mode = 0644
[run-monitor-script]
recipe = hexagonit.recipe.download
url = ${:_profile_base_location_}/${:filename}
download-only = true
#md5sum =
filename = run-monitor-script.sh.in
mode = 0644
[monitor-template]
[monitor-template]
recipe = slapos.recipe.template
recipe = slapos.recipe.template
url = ${:_profile_base_location_}/monitor.cfg.in
url = ${:_profile_base_location_}/monitor.cfg.in
...
...
stack/monitor/monitor.cfg.in
View file @
6283e389
...
@@ -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-
run-
monitor-script:rendered}
command = $${deploy-monitor-script:rendered}
[cron-entry-rss]
[cron-entry-rss]
<= cron
<= cron
...
@@ -55,18 +55,6 @@ name = build-rss
...
@@ -55,18 +55,6 @@ name = build-rss
frequency = * * * * *
frequency = * * * * *
command = $${make-rss:output}
command = $${make-rss:output}
[deploy-run-monitor-script]
recipe = slapos.recipe.template:jinja2
template = ${run-monitor-script:location}/${run-monitor-script:filename}
rendered = $${directory:bin}/run-monitor.sh
mode = 0744
context =
raw dash_bin ${dash:location}/bin/dash
key monitor_bin deploy-monitor-script:rendered
key output_directory directory:monitor-result
raw output_file_verbose monitor.json
raw output_file_quiet monitor.bool
[deploy-monitor-script]
[deploy-monitor-script]
recipe = slapos.recipe.template:jinja2
recipe = slapos.recipe.template:jinja2
template = ${monitor-bin:location}/${monitor-bin:filename}
template = ${monitor-bin:location}/${monitor-bin:filename}
...
@@ -74,6 +62,8 @@ rendered = $${directory:bin}/monitor.py
...
@@ -74,6 +62,8 @@ rendered = $${directory:bin}/monitor.py
mode = 0744
mode = 0744
context =
context =
section directory directory
section directory directory
raw monitoring_file_json $${directory:monitor-result}/monitor.json
raw monitoring_file_bool $${directory:monitor-result}/monitor.bool
[deploy-rss-script]
[deploy-rss-script]
recipe = hexagonit.recipe.download
recipe = hexagonit.recipe.download
...
...
stack/monitor/monitor.py.in
View file @
6283e389
...
@@ -5,13 +5,16 @@ import os
...
@@ -5,13 +5,16 @@ import os
import
subprocess
import
subprocess
import
sys
import
sys
import
time
import
time
from
optparse
import
OptionParser
promise_dir
=
"{{ directory['promise'] }}"
promise_dir
=
"{{ directory['promise'] }}"
service_dir
=
"{{ directory['service'] }}"
service_dir
=
"{{ directory['service'] }}"
monitor_dir
=
"{{ directory['monitor'] }}"
monitor_dir
=
"{{ directory['monitor'] }}"
instance_path
=
"{{ directory['home'] }}"
instance_path
=
"{{ directory['home'] }}"
monitoring_file_json
=
"{{ monitoring_file_json }}"
monitoring_file_bool
=
"{{ monitoring_file_bool }}"
def
getListOfScripts
():
def
getListOfScripts
():
scripts
=
[]
scripts
=
[]
for
dir
in
(
promise_dir
,
monitor_dir
):
for
dir
in
(
promise_dir
,
monitor_dir
):
...
@@ -24,14 +27,15 @@ def getListOfScripts():
...
@@ -24,14 +27,15 @@ def getListOfScripts():
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"
)
def
run
():
def
run
():
scripts
=
getListOfScripts
()
scripts
=
getListOfScripts
()
script_timeout
=
3
script_timeout
=
3
failed_scripts
=
[]
result
=
{}
failed_bool
=
False
for
script
in
scripts
:
for
script_path
in
scripts
:
command
=
[
os
.
path
.
join
(
promise_dir
,
script
)]
command
=
[
os
.
path
.
join
(
promise_dir
,
script_path
)]
script
=
os
.
path
.
basename
(
command
[
0
])
script
=
os
.
path
.
basename
(
command
[
0
])
result
[
script
]
=
''
process_handler
=
subprocess
.
Popen
(
command
,
process_handler
=
subprocess
.
Popen
(
command
,
cwd
=
instance_path
,
cwd
=
instance_path
,
...
@@ -47,27 +51,20 @@ def run():
...
@@ -47,27 +51,20 @@ def run():
if
process_handler
.
poll
()
is
None
:
if
process_handler
.
poll
()
is
None
:
process_handler
.
terminate
()
process_handler
.
terminate
()
failed_bool
=
True
result
[
script
]
=
"Time Out"
failed_scripts
.
append
({
script_path
:
"Time Out"
})
elif
process_handler
.
poll
()
!=
0
:
elif
process_handler
.
poll
()
!=
0
:
stderr
=
process_handler
.
communicate
()[
1
]
stderr
=
process_handler
.
communicate
()[
1
]
if
stderr
is
not
None
:
if
stderr
is
not
None
:
failed_bool
=
True
result
[
script
]
=
stderr
.
strip
()
failed_scripts
.
append
({
script_path
:
stderr
.
strip
()})
return
result
return
failed_scripts
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
parser
=
OptionParser
()
monitors
=
run
()
parser
.
add_option
(
"-v"
,
"--verbose"
,
action
=
"store_true"
,
dest
=
"verbose"
,
open
(
monitoring_file_json
,
"w+"
).
write
(
json
.
dumps
(
fails
))
help
=
"return a json containing info for each monitored script"
)
if
len
(
monitors
)
==
0
:
(
options
,
args
)
=
parser
.
parse_args
()
open
(
monitoring_file_bool
,
"w+"
).
write
(
"SUCCESS : everything is ok"
)
fails
=
run
()
if
options
.
verbose
:
print
fails
elif
len
(
fails
)
==
0
:
print
0
exit
(
0
)
exit
(
0
)
else
:
else
:
print
1
open
(
monitoring_file_bool
,
"w+"
).
write
(
"FAILURE : something went wrong"
)
exit
(
1
)
exit
(
1
)
\ No newline at end of file
stack/monitor/run-monitor-script.sh.in
deleted
100644 → 0
View file @
9ca5848d
#!{{ dash_bin }}
echo "`date`, `{{ monitor_bin }} -v`" > {{ output_directory }}/{{ output_file_verbose }}
echo "`date`, `{{ monitor_bin }}`" > {{ output_directory }}/{{ output_file_quiet }}
\ 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