Code Duplication    Length = 30-35 lines in 2 locations

plumd/plugins/readers/linux/proc.py 2 locations

@@ 351-385 (lines=35) @@
348
        return result
349
350
351
    def proc_net_dev(self):
352
        """Return network interface metrics from proc file net/dev.
353
354
        Add entries to the configuration value 'net_dev_re' to skip
355
        any network interfaces that match the regular expression.
356
357
        :rtype: plumd.Result
358
        """
359
        cols = self.config.get('net_dev_cols')
360
        result = plumd.Result("net")
361
        fname = "{0}/net/dev".format(self.proc_path)
362
        dat = {}
363
        # read and process /proc/stat
364
        try:
365
            dat = get_file_map(fname, 0, 0)
366
        except Exception as e:
367
            tb = traceback.format_exc()
368
            self.log.error("proc_net_dev: exception: {0}: {1}".format(e, tb))
369
            return result
370
        ts = time.time()
371
        for key, val in dat.items():
372
            key = key.replace(":", "")
373
            if self.net_dev_re.match(key):
374
                continue
375
            if len(val) < len(cols):
376
                #self.log.error("proc_net_dev: invalid entry: {0}".format(val))
377
                continue
378
            for mname in cols:
379
                if len(val) < 1:
380
                    break
381
                mval = int(val.popleft())
382
                mstr = "{0}.{1}".format(key, mname)
383
                dval = self.calc.per_second(mstr, mval, ts)
384
                result.add(plumd.Int(mstr, dval))
385
        return result
386
387
388
    def proc_net_snmp(self):
@@ 319-348 (lines=30) @@
316
        return result
317
318
319
    def proc_diskstats(self):
320
        """Return disk io metrics from proc file diskstats.
321
322
        :rtype: plumd.Result
323
        """
324
        # times in ms
325
        cols = self.config.get('diskstats_cols')
326
        result = plumd.Result("diskstats")
327
        fname = "{0}/diskstats".format(self.proc_path)
328
        dat = {}
329
        # read and process /proc/stat
330
        try:
331
            dat = get_file_map(fname, 2, 0)
332
        except Exception as e:
333
            tb = traceback.format_exc()
334
            self.log.error("proc_diskstats: exception: {0}: {1}".format(e, tb))
335
            return result
336
        ts = time.time()
337
        for key, val in dat.items():
338
            if self.diskstats_dev_re.match(key):
339
                continue
340
            if len(val) != 13:
341
                self.log.error("proc_diskstats: invalid entry: {0}".format(val))
342
                continue
343
            for mname in cols:
344
                mval = int(val.popleft())
345
                mstr = "{0}.{1}".format(key, mname)
346
                dval = self.calc.per_second(mstr, mval, ts)
347
                result.add(plumd.Int(mstr, dval))
348
        return result
349
350
351
    def proc_net_dev(self):