summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Sherwood <paul.sherwood@codethink.co.uk>2016-02-23 07:10:50 +0000
committerPaul Sherwood <paul.sherwood@codethink.co.uk>2016-02-27 22:43:38 +0000
commit2d7f4c9c4366a1658620c24fb097d7ba0c4b286c (patch)
treec8b79cd25edd96509279af01ebfb5651541f623b
parent1f66db58050498f96b997afb7c0caabbb900828c (diff)
downloadybd-2d7f4c9c4366a1658620c24fb097d7ba0c4b286c.tar.gz
Tidyup riemann code to lose some lines
-rw-r--r--ybd/app.py31
-rw-r--r--ybd/assembly.py19
2 files changed, 17 insertions, 33 deletions
diff --git a/ybd/app.py b/ybd/app.py
index 791f8e6..277d924 100644
--- a/ybd/app.py
+++ b/ybd/app.py
@@ -230,21 +230,22 @@ def timer(this, message=''):
yield
except:
raise
- else:
- text = '' if message == '' else ' for ' + message
- time_elapsed = elapsed(starttime)
- log(this, 'Elapsed time' + text, time_elapsed)
- if riemann_available and 'riemann-server' in config:
- host_name = config['riemann-server']
- port = config['riemann-port']
- time_split = time_elapsed.split(':')
- time_sec = int(time_split[0]) * 3600 \
- + int(time_split[1]) * 60 + int(time_split[2])
- with QueuedClient(TCPTransport(host_name, port,
- timeout=30)) as client:
- client.event(service="Timer",
- description=text, metric_f=time_sec)
- client.flush()
+ text = '' if message == '' else ' for ' + message
+ time_elapsed = elapsed(starttime)
+ log(this, 'Elapsed time' + text, time_elapsed)
+ log_riemann(this, 'Timer', text, time_elapsed)
+
+
+def log_riemann(this, service, text, time_elapsed):
+ if riemann_available and 'riemann-server' in config:
+ time_split = time_elapsed.split(':')
+ time_sec = int(time_split[0]) * 3600 \
+ + int(time_split[1]) * 60 + int(time_split[2])
+ with QueuedClient(TCPTransport(config['riemann-server'],
+ config['riemann-port'],
+ timeout=30)) as client:
+ client.event(service=service, description=text, metric_f=time_sec)
+ client.flush()
def elapsed(starttime):
diff --git a/ybd/assembly.py b/ybd/assembly.py
index cd0e4b8..dd2bf74 100644
--- a/ybd/assembly.py
+++ b/ybd/assembly.py
@@ -29,12 +29,6 @@ from shutil import copyfile
import time
import datetime
import splitting
-try:
- from riemann_client.transport import TCPTransport
- from riemann_client.client import QueuedClient
- riemann_available = True
-except ImportError:
- riemann_available = False
class RetryException(Exception):
@@ -158,18 +152,7 @@ def run_build(defs, this):
with open(this['log'], "a") as logfile:
time_elapsed = app.elapsed(this['start-time'])
logfile.write('Elapsed_time: %s\n' % time_elapsed)
- if riemann_available and 'riemann-server' in app.config:
- host_name = app.config['riemann-server']
- port = app.config['riemann-port']
- time_split = time_elapsed.split(':')
- time_sec = int(time_split[0]) * 3600 \
- + int(time_split[1]) * 60 + int(time_split[2])
- with QueuedClient(TCPTransport(host_name, port,
- timeout=30)) as client:
- client.event(service="Artifact_Timer",
- description=this['name'],
- metric_f=time_sec)
- client.flush()
+ app.log_riemann(this, 'Artifact_Timer', this['name'], time_elapsed)
def shuffle(contents):