From 56cbed64cf6dd1131917e542cf1df796d6fd2a81 Mon Sep 17 00:00:00 2001 From: Dina Belova Date: Mon, 29 Dec 2014 14:39:14 +0300 Subject: [PATCH] Add 'commit' parameter to put_meter for immediate data sending Change-Id: I17295f73e1485f0c213a1d656347725228e1c014 --- opentsdbclient/base.py | 2 +- opentsdbclient/socket/client.py | 25 +++++++++++++++---------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/opentsdbclient/base.py b/opentsdbclient/base.py index b45b318..0ff3a9a 100644 --- a/opentsdbclient/base.py +++ b/opentsdbclient/base.py @@ -24,7 +24,7 @@ class BaseOpenTSDBClient(object): """Get info about what metrics are registered and with what stats.""" raise NotImplementedError - def put_meter(self, meters): + def put_meter(self, meters, **kwargs): """Post new meter(s) to the database. Meter dictionary *should* contain the following four required fields: diff --git a/opentsdbclient/socket/client.py b/opentsdbclient/socket/client.py index 9b82fad..1acac9c 100644 --- a/opentsdbclient/socket/client.py +++ b/opentsdbclient/socket/client.py @@ -160,17 +160,22 @@ class SocketOpenTSDBClient(base.BaseOpenTSDBClient): LOG.error('Failed to connect to %s:%d', self.host, self.port) self.blacklist_tsd_host() - def put_meter(self, meters): + def put_meter(self, meters, commit=False): """Post new meter(s) to the database. - Meter dictionary *should* contain the following four required fields: - - metric: the name of the metric you are storing - - timestamp: a Unix epoch style timestamp in seconds or milliseconds. - The timestamp must not contain non-numeric characters. - - value: the value to record for this data point. It may be quoted or - not quoted and must conform to the OpenTSDB value rules. - - tags: a map of tag name/tag value pairs. At least one pair must be - supplied. + :param meters: dictionary containing only four required fields: + - metric: the name of the metric you are storing + - timestamp: a Unix epoch style timestamp in seconds or + milliseconds. The timestamp must not contain + non-numeric characters. + - value: the value to record for this data point. + It may be quoted or not quoted and must conform to the + OpenTSDB value rules. + - tags: a map of tag name/tag value pairs. At least one + pair must be supplied. + :param commit: bool variable defining if data sending *should* be + processed immediately (no matter if queue is full or + not) """ # put meter to the send_queue and check if it's time to send it to the @@ -178,7 +183,7 @@ class SocketOpenTSDBClient(base.BaseOpenTSDBClient): meters = self._check_meters(meters) self.send_queue = list(itertools.chain(self.send_queue, meters)) - if len(self.send_queue) <= self.send_queue_max_size: + if len(self.send_queue) <= self.send_queue_max_size and not commit: return self.maintain_connection()