Code Duplication    Length = 31-32 lines in 2 locations

plumd/plugins/readers/memcache.py 1 location

@@ 152-183 (lines=32) @@
149
        return plumd.ResultSet([result])
150
151
152
    def get_stats(self):
153
        """Request and read stats from memcache socket."""
154
        stats = {}
155
156
        if not self.socket and not self.connect():
157
            return {}
158
159
        try:
160
            if PY3:
161
                self.socket.sendall(bytes(Memcache.STAT_CMD, 'utf8'))
162
            else:
163
                self.socket.sendall(Memcache.STAT_CMD)
164
165
            st_str = self.socket.recv(Memcache.RECV_SIZE)
166
            self.log.debug("Memcached: read: {0}".format(st_str))
167
168
            for line in st_str.split("\n"):
169
                vals = line.split()
170
                if len(vals) != 3:
171
                    continue
172
                stype, sname, sval = vals
173
                if stype == "STAT":
174
                    msg = "Memcached: {0} = {1}"
175
                    self.log.debug(msg.format(sname, sval))
176
                    stats[sname] = sval
177
178
        except Exception as e:
179
            msg = "Memcached: {0}: poll: exception: {1}"
180
            self.log.error(msg.format(self.addr, e))
181
            self.disconnect()
182
183
        return stats
184
185
186
    def connect(self):

plumd/plugins/readers/redis.py 1 location

@@ 212-242 (lines=31) @@
209
            result.add(plumd.Int(mname, sonline))
210
211
212
    def get_metrics(self):
213
        """Request and read stats from Redis socket."""
214
        stats = {}
215
216
        if not self.socket and not self.connect():
217
            return {}
218
219
        try:
220
            if PY3:
221
                self.socket.sendall(bytes(Redis.INFO_CMD, 'utf8'))
222
            else:
223
                self.socket.sendall(Redis.INFO_CMD)
224
225
            st_str = self.socket.recv(Redis.RECV_SIZE)
226
227
            for line in st_str.split("\n"):
228
                if line.startswith("#") or not line:
229
                    continue
230
                vals = line.split(":")
231
                if len(vals) != 2:
232
                    continue
233
                sname, sval = vals
234
                msg = "Redis: {0} = {1}"
235
                self.log.debug(msg.format(sname, sval))
236
                stats[sname] = sval
237
        except Exception as e:
238
            msg = "Redis: {0}: poll: exception: {1}"
239
            self.log.error(msg.format(self.addr, e))
240
            self.disconnect()
241
242
        return stats
243
244
245
    def connect(self):