From 2d7f4c9c4366a1658620c24fb097d7ba0c4b286c Mon Sep 17 00:00:00 2001 From: Paul Sherwood Date: Tue, 23 Feb 2016 07:10:50 +0000 Subject: [PATCH] Tidyup riemann code to lose some lines --- ybd/app.py | 31 ++++++++++++++++--------------- ybd/assembly.py | 19 +------------------ 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 @@ 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):