Skip to content

Commit 735b394

Browse files
committed
Add device stats to aiomqtt service
1 parent 8dc9ebe commit 735b394

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

aioservices/services/aiomqtt_service.py

+30
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import sys
2+
import os
13
import time
24
import ssl as _ssl
35
from aioclass import Service
@@ -59,6 +61,17 @@ def _suid(self, _aioctl, name):
5961
name = f"{_name}@{_id}"
6062
return name
6163

64+
def _df(self):
65+
size_info = os.statvfs("")
66+
self._total_b = size_info[0] * size_info[2]
67+
self._used_b = (size_info[0] * size_info[2]) - (size_info[0] * size_info[3])
68+
self._free_b = size_info[0] * size_info[3]
69+
70+
def _taskinfo(self):
71+
self._tasks_total = len(aioctl.tasks_match("*"))
72+
self._services_total = len(aioctl.tasks_match("*.service"))
73+
self._ctasks_total = len(aioctl.tasks_match("*.service.*"))
74+
6275
@aioctl.aiotask
6376
async def do_action(self, action, service):
6477
if action == "status":
@@ -120,7 +133,24 @@ def show(self):
120133
)
121134

122135
def stats(self):
136+
# fs,mem,tasks,firmware
137+
self._df()
138+
self._taskinfo()
139+
gc.collect()
123140
return {
141+
"fstotal": self._total_b,
142+
"fsfree": self._free_b,
143+
"fsused": self._used_b,
144+
"mtotal": gc.mem_free() + gc.mem_alloc(),
145+
"mfree": gc.mem_free(),
146+
"mused": gc.mem_alloc(),
147+
"tasks": self._tasks_total,
148+
"services": self._services_total,
149+
"ctasks": self._ctasks_total,
150+
"requests": self.n_msg,
151+
"firmware": sys.version,
152+
"machine": sys.implementation._machine,
153+
"platform": sys.platform,
124154
"npub": self.n_pub,
125155
"nrecv": self.n_msg,
126156
}

0 commit comments

Comments
 (0)