def send_stats(self): """Collect and send statistics""" try: stat_dict = daemonutils.return_stat_file_dict() if float(stat_dict['next_send']) < time.time(): self.timer_stats = time.time()+STATS_INTERVAL daemonutils.add_update_stat(self.logger, 'next_send', self.timer_stats) else: self.timer_stats = float(stat_dict['next_send']) except Exception as msg: self.logger.warning("Error: Cound not read file. Deleting file and regenerating. Error msg: {}".format(msg)) os.remove(STATS_CSV) daemonutils.recreate_stat_file() try: daemonutils.send_stats(self.logger, STATS_HOST, STATS_PORT, STATS_USER, STATS_PASSWORD, STATS_DATABASE) except Exception as msg: self.logger.warning("Error: Cound not send statistics: {}".format(msg))