Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion potsdb/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version__ = '1.0.3'
__version__ = '1.0.4'
from potsdb.client import Client
8 changes: 6 additions & 2 deletions potsdb/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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"
Expand Down