mirror of
https://github.com/sprockets/sprockets-influxdb.git
synced 2024-11-15 03:00:24 +00:00
Allow a measurement timestamp to be externally set
This commit is contained in:
parent
4548295995
commit
3eea44dfef
2 changed files with 15 additions and 2 deletions
|
@ -3,6 +3,10 @@
|
|||
Release History
|
||||
===============
|
||||
|
||||
`1.2.0`_ (23 Sep 2016)
|
||||
----------------------
|
||||
- Make the timestamp for a measurement something that can be overridden
|
||||
|
||||
`1.1.0`_ (23 Sep 2016)
|
||||
----------------------
|
||||
- Submit measurements one at a time for a rejected batch, logging error responses
|
||||
|
|
|
@ -20,7 +20,7 @@ except ImportError: # pragma: no cover
|
|||
logging.critical('Could not import Tornado')
|
||||
concurrent, httpclient, ioloop = None, None, None
|
||||
|
||||
version_info = (1, 1, 0)
|
||||
version_info = (1, 2, 0)
|
||||
__version__ = '.'.join(str(v) for v in version_info)
|
||||
__all__ = ['__version__', 'version_info', 'add_measurement', 'flush',
|
||||
'install', 'shutdown', 'Measurement']
|
||||
|
@ -646,6 +646,7 @@ class Measurement(object):
|
|||
self.name = name
|
||||
self.fields = {}
|
||||
self.tags = dict(_base_tags)
|
||||
self.timestamp = time.time()
|
||||
|
||||
@contextlib.contextmanager
|
||||
def duration(self, name):
|
||||
|
@ -675,7 +676,7 @@ class Measurement(object):
|
|||
','.join(['{}={}'.format(self._escape(k), self._escape(v))
|
||||
for k, v in self.tags.items()]),
|
||||
self._marshall_fields(),
|
||||
int(time.time() * 1000))
|
||||
int(self.timestamp * 1000))
|
||||
|
||||
def set_field(self, name, value):
|
||||
"""Set the value of a field in the measurement.
|
||||
|
@ -714,6 +715,14 @@ class Measurement(object):
|
|||
for key, value in tags.items():
|
||||
self.set_tag(key, value)
|
||||
|
||||
def set_timestamp(self, value):
|
||||
"""Override the timestamp of a measurement.
|
||||
|
||||
:param float value: The timestamp to assign to the measurement
|
||||
|
||||
"""
|
||||
self.timestamp = value
|
||||
|
||||
@staticmethod
|
||||
def _escape(value):
|
||||
"""Escape a string (key or value) for InfluxDB's line protocol.
|
||||
|
|
Loading…
Reference in a new issue