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
Georgios Dagkakis
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
output = ${buildout:directory}/make-rss.sh.in
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]
recipe = slapos.recipe.template
url = ${:_profile_base_location_}/monitor.cfg.in
...
...
stack/monitor/monitor.cfg.in
View file @
6283e389
...
...
@@ -46,7 +46,7 @@ log = $${directory:log}/cron.log
recipe = slapos.cookbook:cron.d
name = launch-monitor
frequency = * * * * *
command = $${deploy-
run-
monitor-script:rendered}
command = $${deploy-monitor-script:rendered}
[cron-entry-rss]
<= cron
...
...
@@ -55,18 +55,6 @@ name = build-rss
frequency = * * * * *
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]
recipe = slapos.recipe.template:jinja2
template = ${monitor-bin:location}/${monitor-bin:filename}
...
...
@@ -74,6 +62,8 @@ rendered = $${directory:bin}/monitor.py
mode = 0744
context =
section directory directory
raw monitoring_file_json $${directory:monitor-result}/monitor.json
raw monitoring_file_bool $${directory:monitor-result}/monitor.bool
[deploy-rss-script]
recipe = hexagonit.recipe.download
...
...
stack/monitor/monitor.py.in
View file @
6283e389
...
...
@@ -5,13 +5,16 @@ import os
import
subprocess
import
sys
import
time
from
optparse
import
OptionParser
promise_dir
=
"{{ directory['promise'] }}"
service_dir
=
"{{ directory['service'] }}"
monitor_dir
=
"{{ directory['monitor'] }}"
instance_path
=
"{{ directory['home'] }}"
monitoring_file_json
=
"{{ monitoring_file_json }}"
monitoring_file_bool
=
"{{ monitoring_file_bool }}"
def
getListOfScripts
():
scripts
=
[]
for
dir
in
(
promise_dir
,
monitor_dir
):
...
...
@@ -24,14 +27,15 @@ def getListOfScripts():
exit
(
"There is a problem in your directories"
\
"of monitoring. Please check them"
)
def
run
():
scripts
=
getListOfScripts
()
script_timeout
=
3
failed_scripts
=
[]
failed_bool
=
False
for
script_path
in
scripts
:
command
=
[
os
.
path
.
join
(
promise_dir
,
script_path
)]
result
=
{}
for
script
in
scripts
:
command
=
[
os
.
path
.
join
(
promise_dir
,
script
)]
script
=
os
.
path
.
basename
(
command
[
0
])
result
[
script
]
=
''
process_handler
=
subprocess
.
Popen
(
command
,
cwd
=
instance_path
,
...
...
@@ -47,27 +51,20 @@ def run():
if
process_handler
.
poll
()
is
None
:
process_handler
.
terminate
()
failed_bool
=
True
failed_scripts
.
append
({
script_path
:
"Time Out"
})
result
[
script
]
=
"Time Out"
elif
process_handler
.
poll
()
!=
0
:
stderr
=
process_handler
.
communicate
()[
1
]
if
stderr
is
not
None
:
failed_bool
=
True
failed_scripts
.
append
({
script_path
:
stderr
.
strip
()})
return
failed_scripts
result
[
script
]
=
stderr
.
strip
()
return
result
if
__name__
==
"__main__"
:
parser
=
OptionParser
()
parser
.
add_option
(
"-v"
,
"--verbose"
,
action
=
"store_true"
,
dest
=
"verbose"
,
help
=
"return a json containing info for each monitored script"
)
(
options
,
args
)
=
parser
.
parse_args
()
fails
=
run
()
if
options
.
verbose
:
print
fails
elif
len
(
fails
)
==
0
:
print
0
monitors
=
run
()
open
(
monitoring_file_json
,
"w+"
).
write
(
json
.
dumps
(
fails
))
if
len
(
monitors
)
==
0
:
open
(
monitoring_file_bool
,
"w+"
).
write
(
"SUCCESS : everything is ok"
)
exit
(
0
)
else
:
print
1
open
(
monitoring_file_bool
,
"w+"
).
write
(
"FAILURE : something went wrong"
)
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