From 4d5de7d80b1492e40db9289258e49460278492ef Mon Sep 17 00:00:00 2001 From: samson0v Date: Tue, 17 May 2022 16:53:54 +0300 Subject: [PATCH] Added timeout parameter --- thingsboard_gateway/config/statistics.json | 6 ++++++ thingsboard_gateway/gateway/statistics_service.py | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/thingsboard_gateway/config/statistics.json b/thingsboard_gateway/config/statistics.json index e2bef96b..432faa59 100644 --- a/thingsboard_gateway/config/statistics.json +++ b/thingsboard_gateway/config/statistics.json @@ -1,25 +1,31 @@ [ { + "timeout": 100, "command": ["/bin/sh", "-c", "ps -A -o cpu,%mem | awk '{cpu += $1}END{print cpu}'"], "attributeOnGateway": "CPU" }, { + "timeout": 100, "command": ["/bin/sh", "-c", "ps -A -o %cpu,%mem | awk '{mem += $2}END{print mem}'"], "attributeOnGateway": "Memory" }, { + "timeout": 100, "command": ["/bin/sh", "-c", "ipconfig getifaddr en0"], "attributeOnGateway": "IP address" }, { + "timeout": 100, "command": ["/bin/sh", "-c", "sw_vers -productName"], "attributeOnGateway": "OS" }, { + "timeout": 100, "command": ["/bin/sh", "-c", "uptime"], "attributeOnGateway": "Uptime" }, { + "timeout": 100, "command": ["/bin/sh", "-c", "system_profiler SPUSBDataType"], "attributeOnGateway": "USBs" } diff --git a/thingsboard_gateway/gateway/statistics_service.py b/thingsboard_gateway/gateway/statistics_service.py index ce9345f1..d9dc3c5e 100644 --- a/thingsboard_gateway/gateway/statistics_service.py +++ b/thingsboard_gateway/gateway/statistics_service.py @@ -34,7 +34,7 @@ class StatisticsService(Thread): data_to_send = {} for attribute in self._config: process = subprocess.run(attribute['command'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, - encoding='utf-8') + encoding='utf-8', timeout=attribute['timeout']) if process.returncode != 0: self._log.error("Statistic parameter raise the exception: %s", process.stderr)