diff --git a/docs/history.rst b/docs/history.rst index 383bba1..3c099bb 100644 --- a/docs/history.rst +++ b/docs/history.rst @@ -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 diff --git a/sprockets_influxdb.py b/sprockets_influxdb.py index decc987..d2ac81f 100644 --- a/sprockets_influxdb.py +++ b/sprockets_influxdb.py @@ -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.