|
|
|
@ -73,6 +73,11 @@ def main(): |
|
|
|
|
|
|
|
|
|
last_flush_time = time.monotonic() |
|
|
|
|
gauges = {} |
|
|
|
|
while True: |
|
|
|
|
started_prev = sm['deviceState'].started |
|
|
|
|
sm.update() |
|
|
|
|
|
|
|
|
|
# Update metrics |
|
|
|
|
while True: |
|
|
|
|
try: |
|
|
|
|
metric = sock.recv_string(zmq.NOBLOCK) |
|
|
|
@ -88,10 +93,7 @@ def main(): |
|
|
|
|
except Exception: |
|
|
|
|
cloudlog.event("malformed metric", metric=metric) |
|
|
|
|
except zmq.error.Again: |
|
|
|
|
time.sleep(1e-3) |
|
|
|
|
|
|
|
|
|
started_prev = sm['deviceState'].started |
|
|
|
|
sm.update(0) |
|
|
|
|
break |
|
|
|
|
|
|
|
|
|
# flush when started state changes or after FLUSH_TIME_S |
|
|
|
|
if (time.monotonic() > last_flush_time + STATS_FLUSH_TIME_S) or (sm['deviceState'].started != started_prev): |
|
|
|
|