Skip to content

Commit

Permalink
Added conversion try before sending custom statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
imbeacon committed Nov 15, 2024
1 parent 5933d3a commit b31c767
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions thingsboard_gateway/gateway/statistics/statistics_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,12 @@ def __collect_custom_command_statistics(self):
value = process.stdout
else:
value = attribute['function'](self._gateway)
if value is None:
continue
try:
value = float(value)
except ValueError:
pass
except Exception as e:
self._log.warning("Statistic parameter %s raise the exception: %s",
attribute['attributeOnGateway'], e)
Expand Down Expand Up @@ -208,12 +214,12 @@ def run(self) -> None:

cur_monotonic = int(monotonic())

if cur_monotonic - self._last_service_poll >= self._stats_send_period_in_seconds:
if cur_monotonic - self._last_service_poll >= self._stats_send_period_in_seconds or self._last_service_poll == 0:
self._last_service_poll = cur_monotonic
self.__send_statistics()
self.clear_statistics()

if cur_monotonic - self._last_custom_command_poll >= self._custom_stats_send_period_in_seconds:
if cur_monotonic - self._last_custom_command_poll >= self._custom_stats_send_period_in_seconds or self._last_custom_command_poll == 0:
self._last_custom_command_poll = cur_monotonic
self.__send_custom_command_statistics()

Expand Down

0 comments on commit b31c767

Please sign in to comment.