Browse Source

rethinkdb collector new driver support (#6431)

* add new driver support (2.4.0+)
Ilya Mashchenko 5 years ago
parent
commit
bd333ab9bd
1 changed files with 15 additions and 2 deletions
  1. 15 2
      collectors/python.d.plugin/rethinkdbs/rethinkdbs.chart.py

+ 15 - 2
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,