Commit 6283e389 authored by Nicolas Wavrant's avatar Nicolas Wavrant

stack-monitor: monitor.py directly writes files, and is directly called by cron

it now also writes all results in the json
parent 9ca5848d
......@@ -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
......
......@@ -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
......
......@@ -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
#!{{ 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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment