|
|
|
@ -23,6 +23,8 @@ class METRIC_TYPE: |
|
|
|
|
class StatLog: |
|
|
|
|
def __init__(self): |
|
|
|
|
self.pid = None |
|
|
|
|
self.zctx = None |
|
|
|
|
self.sock = None |
|
|
|
|
|
|
|
|
|
def connect(self) -> None: |
|
|
|
|
self.zctx = zmq.Context() |
|
|
|
@ -31,6 +33,12 @@ class StatLog: |
|
|
|
|
self.sock.connect(STATS_SOCKET) |
|
|
|
|
self.pid = os.getpid() |
|
|
|
|
|
|
|
|
|
def __del__(self): |
|
|
|
|
if self.sock is not None: |
|
|
|
|
self.sock.close() |
|
|
|
|
if self.zctx is not None: |
|
|
|
|
self.zctx.term() |
|
|
|
|
|
|
|
|
|
def _send(self, metric: str) -> None: |
|
|
|
|
if os.getpid() != self.pid: |
|
|
|
|
self.connect() |
|
|
|
@ -68,7 +76,7 @@ def main() -> NoReturn: |
|
|
|
|
return res |
|
|
|
|
|
|
|
|
|
# open statistics socket |
|
|
|
|
ctx = zmq.Context().instance() |
|
|
|
|
ctx = zmq.Context.instance() |
|
|
|
|
sock = ctx.socket(zmq.PULL) |
|
|
|
|
sock.bind(STATS_SOCKET) |
|
|
|
|
|
|
|
|
@ -92,6 +100,7 @@ def main() -> NoReturn: |
|
|
|
|
last_flush_time = time.monotonic() |
|
|
|
|
gauges = {} |
|
|
|
|
samples: Dict[str, List[float]] = defaultdict(list) |
|
|
|
|
try: |
|
|
|
|
while True: |
|
|
|
|
started_prev = sm['deviceState'].started |
|
|
|
|
sm.update() |
|
|
|
@ -156,6 +165,9 @@ def main() -> NoReturn: |
|
|
|
|
idx += 1 |
|
|
|
|
else: |
|
|
|
|
cloudlog.error("stats dir full") |
|
|
|
|
finally: |
|
|
|
|
sock.close() |
|
|
|
|
ctx.term() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
|
|