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

Added timeout parameter

This commit is contained in:
samson0v
2022-05-17 16:53:54 +03:00
parent ba3c4e3c03
commit 4d5de7d80b
2 changed files with 7 additions and 1 deletions

View File

@@ -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"
}

View File

@@ -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)