From e708f56598414929091524ce68a56da602d082e7 Mon Sep 17 00:00:00 2001 From: mbeierl Date: Thu, 15 Oct 2015 10:48:58 -0400 Subject: Logging and timestamp Added logging and fixed issue if fio does not produce the current timestamp in its output JIRA: STORPERF-4 Change-Id: Ifd0dbc4e17d984907e63089ebfae1d0e9e749dcc Signed-off-by: mbeierl --- storperf/carbon/converter.py | 15 ++++++++++++--- storperf/carbon/emitter.py | 14 ++++++++------ 2 files changed, 20 insertions(+), 9 deletions(-) (limited to 'storperf/carbon') diff --git a/storperf/carbon/converter.py b/storperf/carbon/converter.py index 4ad5be2..42dbeef 100644 --- a/storperf/carbon/converter.py +++ b/storperf/carbon/converter.py @@ -6,13 +6,22 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## +import calendar +import logging +import time class JSONToCarbon(object): def __init__(self): - pass - + self.logger = logging.getLogger(__name__) + def convert_to_dictionary(self, json_object, prefix=None): - self.timestamp = str(json_object['timestamp']) + # Use the timestamp reported by fio, or current time if + # not present. + if 'timestamp' in json_object: + self.timestamp = str(json_object['timestamp']) + else: + self.timestamp = str(calendar.timegm(time.gmtime())) + self.flat_dictionary = {} self.resurse_to_flat_dictionary(json_object, prefix) return self.flat_dictionary diff --git a/storperf/carbon/emitter.py b/storperf/carbon/emitter.py index 1a3f89b..526a96f 100644 --- a/storperf/carbon/emitter.py +++ b/storperf/carbon/emitter.py @@ -6,23 +6,25 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## +import logging import socket class CarbonMetricTransmitter(): - + carbon_host = '127.0.0.1' carbon_port = 2003 - + def __init__(self): - pass - + self.logger = logging.getLogger(__name__) + def transmit_metrics(self, metrics): self.carbon_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.carbon_socket.connect((self.carbon_host, self.carbon_port)) - + for key, metric in metrics.items(): message = key + " " + metric + "\n" + print message self.carbon_socket.send(message) - + self.carbon_socket.close() -- cgit 1.2.3-korg