statsd: run at 2Hz (#23493)

pull/23494/head
Willem Melching 2022-01-11 14:24:18 +01:00 committed by GitHub
parent 6e817f9eb5
commit 44592f4b0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 19 additions and 17 deletions

View File

@ -74,24 +74,26 @@ def main():
last_flush_time = time.monotonic()
gauges = {}
while True:
try:
metric = sock.recv_string(zmq.NOBLOCK)
try:
metric_type = metric.split('|')[1]
metric_name = metric.split(':')[0]
metric_value = metric.split('|')[0].split(':')[1]
if metric_type == METRIC_TYPE.GAUGE:
gauges[metric_name] = metric_value
else:
cloudlog.event("unknown metric type", metric_type=metric_type)
except Exception:
cloudlog.event("malformed metric", metric=metric)
except zmq.error.Again:
time.sleep(1e-3)
started_prev = sm['deviceState'].started
sm.update(0)
sm.update()
# Update metrics
while True:
try:
metric = sock.recv_string(zmq.NOBLOCK)
try:
metric_type = metric.split('|')[1]
metric_name = metric.split(':')[0]
metric_value = metric.split('|')[0].split(':')[1]
if metric_type == METRIC_TYPE.GAUGE:
gauges[metric_name] = metric_value
else:
cloudlog.event("unknown metric type", metric_type=metric_type)
except Exception:
cloudlog.event("malformed metric", metric=metric)
except zmq.error.Again:
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):