From 5881ad8b683fc4778a6eaeab7c68ea0fb623e1d5 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Tue, 25 Oct 2016 14:38:31 -0400 Subject: [PATCH] Support sub-second interval If a user requests an interval that is not a whole number, begin honoring it and adjust the timestamp precision to indicate milliseconds. Do not bother with milliseconds on whole number intervals. --- confluent_client/bin/nodesensors | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/confluent_client/bin/nodesensors b/confluent_client/bin/nodesensors index dcda5cda..a086f4d3 100755 --- a/confluent_client/bin/nodesensors +++ b/confluent_client/bin/nodesensors @@ -16,6 +16,7 @@ # limitations under the License. import csv +import datetime import optparse import os import sys @@ -40,7 +41,7 @@ sensorcollections = { argparser = optparse.OptionParser( usage="Usage: %prog [options] noderange [sensor(s)") -argparser.add_option('-i', '--interval', type='int', +argparser.add_option('-i', '--interval', type='float', help='Interval to do repeated samples over') argparser.add_option('-n', '--numreadings', type='int', help='Number of readings to gather') @@ -146,7 +147,12 @@ def sensorpass(showout=True, appendtime=False): def format_csv(csvwriter, orderedsensors, resdata, showtime=True): for nodekey in resdata: if showtime: - rowdata = [time.strftime('%Y-%m-%dT%H:%M:%S'), nodekey] + if showtime.is_integer(): + rowdata = [time.strftime('%Y-%m-%dT%H:%M:%S'), nodekey] + else: + rowdata = [time.strftime('%Y-%m-%dT%H:%M:%S.') + + str(datetime.datetime.now().microsecond//1000), + nodekey] else: rowdata = [nodekey] for sensorkey in orderedsensors: @@ -197,7 +203,8 @@ def main(): nextstart = os.times()[4] + options.interval resdata = sensorpass(linebyline, True) if options.csv: - format_csv(csvwriter, orderedsensors, resdata) + format_csv(csvwriter, orderedsensors, resdata, + showtime=options.interval) if options.numreadings: options.numreadings -= 1 if options.numreadings <= 0: