Code Duplication    Length = 12-13 lines in 2 locations

glances/exports/glances_opentsdb/__init__.py 1 location

@@ 59-71 (lines=13) @@
56
57
        return db
58
59
    def export(self, name, columns, points):
60
        """Export the stats to the Statsd server."""
61
        for i in range(len(columns)):
62
            if not isinstance(points[i], Number):
63
                continue
64
            stat_name = f'{self.prefix}.{name}.{columns[i]}'
65
            stat_value = points[i]
66
            tags = self.parse_tags(self.tags)
67
            try:
68
                self.client.send(stat_name, stat_value, **tags)
69
            except Exception as e:
70
                logger.error(f"Can not export stats {name} to OpenTSDB ({e})")
71
        logger.debug(f"Export {name} stats to OpenTSDB")
72
73
    def exit(self):
74
        """Close the OpenTSDB export module."""

glances/exports/glances_statsd/__init__.py 1 location

@@ 51-62 (lines=12) @@
48
        logger.info(f"Stats will be exported to StatsD server: {self.host}:{self.port}")
49
        return StatsClient(self.host, int(self.port), prefix=self.prefix)
50
51
    def export(self, name, columns, points):
52
        """Export the stats to the Statsd server."""
53
        for i in range(len(columns)):
54
            if not isinstance(points[i], Number):
55
                continue
56
            stat_name = f'{name}.{columns[i]}'
57
            stat_value = points[i]
58
            try:
59
                self.client.gauge(normalize(stat_name), stat_value)
60
            except Exception as e:
61
                logger.error(f"Can not export stats to Statsd ({e})")
62
        logger.debug(f"Export {name} stats to Statsd")
63
64
65
def normalize(name):