summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <lars.wirzenius@codethink.co.uk>2014-02-04 14:49:07 +0000
committerLars Wirzenius <lars.wirzenius@codethink.co.uk>2014-02-04 14:49:07 +0000
commitf74dd8b736f5a04726340d96a8848578251e24db (patch)
tree253e9927a73ecc56a6a9373987bafcc256a14400
parent01f3aaaa6d679535cdd38d9003904dd0080a687c (diff)
downloadlorry-controller-f74dd8b736f5a04726340d96a8848578251e24db.tar.gz
Report disk free status
-rw-r--r--ARCH4
-rwxr-xr-xlorry-controller-webapp17
-rw-r--r--yarns.webapp/020-status.yarn3
-rw-r--r--yarns.webapp/900-implementations.yarn16
4 files changed, 37 insertions, 3 deletions
diff --git a/ARCH b/ARCH
index fe62ce7..2a368b0 100644
--- a/ARCH
+++ b/ARCH
@@ -247,6 +247,10 @@ Requests for admins:
filesystem Lorry Controller uses (in bytes). This information is
included in the `/1.0/status` query as well, but this is easier to
deal with for simple monitoring. (MON/DU)
+ - N.B.: It turns out it's not easy to return a JSON object that is
+ only an integer in bottle.py, so this helper method is skipped,
+ for now; the disk free status is added to the normal status in
+ any case
* `POST /1.0/stop-queue` causes WEBAPP to stop scheduling new jobs to
run. Any currently running jobs are not affected. (RT/QSTOP)
* `POST /1.0/start-queue` causes WEBAPP to start scheduling jobs
diff --git a/lorry-controller-webapp b/lorry-controller-webapp
index 0e5fd5c..e37420b 100755
--- a/lorry-controller-webapp
+++ b/lorry-controller-webapp
@@ -39,6 +39,7 @@ STATUS_HTML_TEMPLATE = '''
<h1>Status of Lorry Controller</h1>
<p>Running queue: {running-queue}.</p>
+ <p>Free disk space: {disk-free-gib} GiB.</p>
<hr>
@@ -113,7 +114,7 @@ class StatusRenderer(object):
'''Helper class for rendering service status as JSON/HTML'''
- def get_status_as_dict(self, statedb):
+ def get_status_as_dict(self, statedb, work_directory):
quotes = [
"Never get drunk unless you're willing to pay for it - "
"the next day.",
@@ -125,6 +126,7 @@ class StatusRenderer(object):
'running-queue': statedb.get_running_queue(),
'timestamp': time.strftime('%Y-%m-%d %H:%M:%S'),
}
+ status.update(self.get_free_disk_space(work_directory))
return status
def render_status_as_html(self, status):
@@ -135,6 +137,15 @@ class StatusRenderer(object):
with open(filename, 'w') as f:
f.write(html)
+ def get_free_disk_space(self, dirname):
+ result = os.statvfs(dirname)
+ free_bytes = result.f_bavail * result.f_bsize
+ return {
+ 'disk-free': free_bytes,
+ 'disk-free-mib': free_bytes / 1024**2,
+ 'disk-free-gib': free_bytes / 1024**2,
+ }
+
class Status(LorryControllerRoute):
@@ -143,7 +154,7 @@ class Status(LorryControllerRoute):
def run(self, **kwargs):
renderer = StatusRenderer()
- status = renderer.get_status_as_dict(self.statedb)
+ status = renderer.get_status_as_dict(self.statedb, self.app_settings['statedb'])
renderer.write_status_as_html(status, self.app_settings['status-html'])
return status
@@ -155,7 +166,7 @@ class StatusHTML(LorryControllerRoute):
def run(self, **kwargs):
renderer = StatusRenderer()
- status = renderer.get_status_as_dict(self.statedb)
+ status = renderer.get_status_as_dict(self.statedb, self.app_settings['statedb'])
renderer.write_status_as_html(status, self.app_settings['status-html'])
return renderer.render_status_as_html(status)
diff --git a/yarns.webapp/020-status.yarn b/yarns.webapp/020-status.yarn
index ae5a779..0a704e8 100644
--- a/yarns.webapp/020-status.yarn
+++ b/yarns.webapp/020-status.yarn
@@ -10,6 +10,9 @@ it has no Lorry or Trove specs.
WHEN admin makes request GET /1.0/status
THEN response is application/json
AND response has running-queue set to false
+ AND response has disk-free set
+ AND response has disk-free-mib set
+ AND response has disk-free-gib set
AND static status page got updated
FINALLY WEBAPP terminates
diff --git a/yarns.webapp/900-implementations.yarn b/yarns.webapp/900-implementations.yarn
index 0e3aa9e..01c6fbe 100644
--- a/yarns.webapp/900-implementations.yarn
+++ b/yarns.webapp/900-implementations.yarn
@@ -122,6 +122,22 @@ value is expresssed as a JSON value in the step.
sys.exit(1)
' < "$DATADIR/response.body"
+In some cases, such as free disk space, we don't care about the actual
+value, but we do care that it is there.
+
+ IMPLEMENTS THEN response has (\S+) set
+ cat "$DATADIR/response.body"
+ python -c '
+ import json, os, sys
+ data = json.load(sys.stdin)
+ key = os.environ["MATCH_1"]
+ if key not in data:
+ sys.stderr.write(
+ "Key {key} is not set, but was expected to be set".format (
+ key=key))
+ sys.exit(1)
+ ' < "$DATADIR/response.body"
+
Status web page
---------------