diff --git a/hbd/server/notify.py b/hbd/server/notify.py index be5bf61..4cc6655 100644 --- a/hbd/server/notify.py +++ b/hbd/server/notify.py @@ -114,6 +114,11 @@ def eventlog(host, lvl, m, service=None): "message": m, } data.msgs.append(msg) + # Cap the in-memory buffer so it doesn't grow without bound; this list is + # replayed to every dashboard client on connect and persisted in the pickle. + cap = _config.get("msg_buffer_size", 500) + if cap and len(data.msgs) > cap: + del data.msgs[:-cap] s = f"{time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(ts))} {lvl} " if host: s += f"{host} " diff --git a/hbd/server/ws.py b/hbd/server/ws.py index f8f9d6c..1128203 100644 --- a/hbd/server/ws.py +++ b/hbd/server/ws.py @@ -90,7 +90,7 @@ async def handler(request): # the client knows to append rather than prepend). if data.msgs: try: - for m in reversed(data.msgs): + for m in reversed(data.msgs[-30:]): host_name = m.get("host") if isinstance(m, dict) else None if not host_name or _user_can_see_host(user, host_name): await ws.send_str(json.dumps({"type": "message", "data": m, "history": True}))