From 34f488f41ee820371159111bf621f11d0f54f669 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 4 Aug 2019 10:56:44 +0200 Subject: Adding upstream version 1.16.1. Signed-off-by: Daniel Baumann --- .../python.d.plugin/rethinkdbs/rethinkdbs.chart.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'collectors/python.d.plugin/rethinkdbs/rethinkdbs.chart.py') diff --git a/collectors/python.d.plugin/rethinkdbs/rethinkdbs.chart.py b/collectors/python.d.plugin/rethinkdbs/rethinkdbs.chart.py index ee2fb68b3..80cc1cf18 100644 --- a/collectors/python.d.plugin/rethinkdbs/rethinkdbs.chart.py +++ b/collectors/python.d.plugin/rethinkdbs/rethinkdbs.chart.py @@ -131,6 +131,15 @@ class Server: return dict(('{0}_{1}'.format(self.name, k), d[k]) for k in d) +# https://pypi.org/project/rethinkdb/2.4.0/ +# rdb.RethinkDB() can be used as rdb drop in replacement. +# https://github.com/rethinkdb/rethinkdb-python#quickstart +def get_rethinkdb(): + if hasattr(rdb, 'RethinkDB'): + return rdb.RethinkDB() + return rdb + + class Service(SimpleService): def __init__(self, configuration=None, name=None): SimpleService.__init__(self, configuration=configuration, name=name) @@ -141,6 +150,7 @@ class Service(SimpleService): self.user = self.configuration.get('user', 'admin') self.password = self.configuration.get('password') self.timeout = self.configuration.get('timeout', 2) + self.rdb = None self.conn = None self.alive = True @@ -149,6 +159,9 @@ class Service(SimpleService): self.error('"rethinkdb" module is needed to use rethinkdbs.py') return False + self.debug("rethinkdb driver version {0}".format(rdb.__version__)) + self.rdb = get_rethinkdb() + if not self.connect(): return None @@ -196,14 +209,14 @@ class Service(SimpleService): def get_stats(self): try: - return list(rdb.db('rethinkdb').table('stats').run(self.conn).items) + return list(self.rdb.db('rethinkdb').table('stats').run(self.conn).items) except rdb.errors.ReqlError: self.alive = False return None def connect(self): try: - self.conn = rdb.connect( + self.conn = self.rdb.connect( host=self.host, port=self.port, user=self.user, -- cgit v1.2.3