From 8dac013748f0b2ff3ed381489a31b002bd479857 Mon Sep 17 00:00:00 2001 From: Matt Davis Date: Wed, 2 Nov 2016 10:33:49 +0000 Subject: [PATCH] Add parameter to enable ms precision --- README.md | 3 ++- potsdb/__init__.py | 2 +- potsdb/client.py | 8 ++++++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 174ef6e..b2852cb 100644 --- a/README.md +++ b/README.md @@ -32,11 +32,12 @@ import potsdb # minimum is hostname. port is defaulted to 4242: metrics = potsdb.Client('hostname.local') # all options: -metrics = potsdb.Client('hostname.local', port=4242, qsize=1000, host_tag=True, mps=100, check_host=True) +metrics = potsdb.Client('hostname.local', port=4242, qsize=1000, host_tag=True, mps=100, ms_precision=True, check_host=True) # qsize: Max Size of Queue. Note: if Queue reaches qsize, old metrics will be dropped. 0 = unlimited. Default is 100k # host_tag: True for automatic, string value for override, None for nothing # mps: Metrics Per Second rate limiting. Default is 0 (unlimited) +# ms_precision: Enable millisecond precision when writing metrics. Default is False # check_host: change to false to skip startup connectivity checking # Bare minimum is metric name, metric value diff --git a/potsdb/__init__.py b/potsdb/__init__.py index 2dcb022..afee557 100644 --- a/potsdb/__init__.py +++ b/potsdb/__init__.py @@ -1,2 +1,2 @@ -__version__ = '1.0.3' +__version__ = '1.0.4' from potsdb.client import Client diff --git a/potsdb/client.py b/potsdb/client.py index b90199f..ff78f3a 100644 --- a/potsdb/client.py +++ b/potsdb/client.py @@ -78,7 +78,7 @@ def _push(host, port, q, done, mps, stop, test_mode): class Client(): def __init__(self, host, port=4242, qsize=100000, host_tag=True, - mps=MPS_LIMIT, check_host=True, test_mode=False): + mps=MPS_LIMIT, ms_precision=False, check_host=True, test_mode=False): """Main tsdb client. Connect to host/port. Buffer up to qsize metrics""" self.q = queue.Queue(maxsize=qsize) @@ -87,6 +87,7 @@ def __init__(self, host, port=4242, qsize=100000, host_tag=True, self.host = host self.port = int(port) self.queued = 0 + self.ms_precision = ms_precision # Make initial check that the host is up, because once in the # background thread it will be silently ignored/retried @@ -126,7 +127,10 @@ def log(self, name, val, **tags): tags['host'] = self.host_tag # get timestamp from system time, unless it's supplied as a tag - timestamp = int(tags.pop('timestamp', time.time())) + if self.ms_precision: + timestamp = int(tags.pop('timestamp', time.time() * 1000)) + else: + timestamp = int(tags.pop('timestamp', time.time())) assert not self.done.is_set(), "tsdb object has been closed" assert tags != {}, "Need at least one tag"