1
0
mirror of https://github.com/thingsboard/thingsboard-gateway synced 2025-10-26 22:31:42 +08:00

Fixed blocking statistics collecting

This commit is contained in:
samson0v
2022-08-01 13:43:04 +03:00
parent a62e2f0288
commit 4d126270be
2 changed files with 11 additions and 7 deletions

View File

@@ -15,7 +15,7 @@ class StatisticsService(Thread):
'allBytesSentToDevices': 0,
}
def __init__(self, config_path, stats_send_period_in_seconds, gateway, log):
def __init__(self, stats_send_period_in_seconds, gateway, log, config_path=None):
super().__init__()
self.name = 'Statistics Thread'
self.daemon = True
@@ -35,8 +35,11 @@ class StatisticsService(Thread):
self._stopped = True
def _load_config(self):
with open(self._config_path, 'r') as file:
return simplejson.load(file)
if self._config_path:
with open(self._config_path, 'r') as file:
return simplejson.load(file)
return []
@classmethod
def add_bytes(cls, stat_type, bytes_count):

View File

@@ -203,10 +203,11 @@ class TBGatewayService:
self.__statistics = self.__config['thingsboard'].get('statistics', DEFAULT_STATISTIC)
self.__statistics_service = None
if self.__statistics['enable'] and self.__statistics.get('configuration'):
statistics_config_path = self._config_dir + self.__statistics['configuration']
self.__statistics_service = StatisticsService(statistics_config_path,
self.__statistics['statsSendPeriodInSeconds'], self, log)
if self.__statistics['enable']:
self.__statistics_service = StatisticsService(self.__statistics['statsSendPeriodInSeconds'], self, log,
config_path=self._config_dir + self.__statistics[
'configuration'] if self.__statistics.get(
'configuration') else None)
self._published_events = SimpleQueue()
self._send_thread = Thread(target=self.__read_data_from_storage, daemon=True,