Code Duplication    Length = 30-35 lines in 2 locations

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

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