@cryptotaxi247 / netdata-1 / commits / bd333ab9b

rethinkdb collector new driver support (#6431)

* add new driver support (2.4.0+)

Ilya Mashchenko committed Jul 11, 2019 at 18:54 UTC bd333ab9bd9959d781a8a96284bd35183257efc1
1 file changed +15 -2
collectors/python.d.plugin/rethinkdbs/rethinkdbs.chart.py
+15 -2
@@ -131,6 +131,15 @@ class Server:
131 return dict(('{0}_{1}'.format(self.name, k), d[k]) for k in d)
132
133
134 +# https://pypi.org/project/rethinkdb/2.4.0/
135 +# rdb.RethinkDB() can be used as rdb drop in replacement.
136 +# https://github.com/rethinkdb/rethinkdb-python#quickstart
137 +def get_rethinkdb():
138 + if hasattr(rdb, 'RethinkDB'):
139 + return rdb.RethinkDB()
140 + return rdb
141 +
142 +
143 class Service(SimpleService):
144 def __init__(self, configuration=None, name=None):
145 SimpleService.__init__(self, configuration=configuration, name=name)
@@ -141,6 +150,7 @@ class Service(SimpleService):
150 self.user = self.configuration.get('user', 'admin')
151 self.password = self.configuration.get('password')
152 self.timeout = self.configuration.get('timeout', 2)
153 + self.rdb = None
154 self.conn = None
155 self.alive = True
156
@@ -149,6 +159,9 @@ class Service(SimpleService):
159 self.error('"rethinkdb" module is needed to use rethinkdbs.py')
160 return False
161
162 + self.debug("rethinkdb driver version {0}".format(rdb.__version__))
163 + self.rdb = get_rethinkdb()
164 +
165 if not self.connect():
166 return None
167
@@ -196,14 +209,14 @@ class Service(SimpleService):
209
210 def get_stats(self):
211 try:
199 - return list(rdb.db('rethinkdb').table('stats').run(self.conn).items)
212 + return list(self.rdb.db('rethinkdb').table('stats').run(self.conn).items)
213 except rdb.errors.ReqlError:
214 self.alive = False
215 return None
216
217 def connect(self):
218 try:
206 - self.conn = rdb.connect(
219 + self.conn = self.rdb.connect(
220 host=self.host,
221 port=self.port,
222 user=self.user,