Skip to content

Commit

Permalink
statsd: run at 2Hz (commaai#23493)
Browse files Browse the repository at this point in the history
  • Loading branch information
pd0wm authored Jan 11, 2022
1 parent 6e817f9 commit 44592f4
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions selfdrive/statsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,24 +74,26 @@ def get_influxdb_line(measurement: str, value: float, timestamp: datetime, tags:
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):
Expand Down

0 comments on commit 44592f4

Please sign in to comment.