aboutsummaryrefslogtreecommitdiff
path: root/src/zencore/system.cpp
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2026-03-23 14:19:57 +0100
committerGitHub Enterprise <[email protected]>2026-03-23 14:19:57 +0100
commit2a445406e09328cb4cf320300f2678997d6775b7 (patch)
treea92f02d94c92144cb6ae32160397298533e4c822 /src/zencore/system.cpp
parentadd hub instance crash recovery (#885) (diff)
downloadzen-2a445406e09328cb4cf320300f2678997d6775b7.tar.xz
zen-2a445406e09328cb4cf320300f2678997d6775b7.zip
Dashboard refresh (logs, storage, network, object store, docs) (#835)
## Summary This PR adds a session management service, several new dashboard pages, and a number of infrastructure improvements. ### Sessions Service - `SessionsServiceClient` in `zenutil` announces sessions to a remote zenserver with a 15s heartbeat (POST/PUT/DELETE lifecycle) - Storage server registers itself with its own local sessions service on startup - Session mode attribute coupled to server mode (Compute, Proxy, Hub, etc.) - Ended sessions tracked with `ended_at` timestamp; status filtering (Active/Ended/All) - `--sessions-url` config option for remote session announcement - In-process log sink (`InProcSessionLogSink`) forwards server log output to the server's own session, visible in the dashboard ### Session Log Viewer - POST/GET endpoints for session logs (`/sessions/{id}/log`) supporting raw text and structured JSON/CbObject with batch `entries` array - In-memory log storage per session (capped at 10k entries) with cursor-based pagination for efficient incremental fetching - Log panel in the sessions dashboard with incremental DOM updates, auto-scroll (Follow toggle), newest-first toggle, text filter, and log-level coloring - Auto-selects the server's own session on page load ### TCP Log Streaming - `LogStreamListener` and `TcpLogStreamSink` for log delivery over TCP - Sequence numbers on each message with drop detection and synthetic "dropped" notice on gaps - Gathered buffer writes to reduce syscall overhead when flushing batches - Tests covering basic delivery, multi-line splitting, drop detection, and sequencing ### New Dashboard Pages - **Sessions**: master-detail layout with selectable rows, metadata panel, live WebSocket updates, paging, abbreviated date formatting, and "this" pill for the local session - **Object Store**: summary stats tiles and bucket table with click-to-expand inline object listing (`GET /obj/`) - **Storage**: per-volume disk usage breakdown (`GET /admin/storage`), Garbage Collection status section (next-run countdown, last-run stats), and GC History table with paginated rows and expandable detail panels - **Network**: overview tiles, per-service request table, proxy connections, and live WebSocket updates; distinct client IPs and session counts via HyperLogLog ### Documentation Page - In-dashboard Docs page with sidebar navigation, markdown rendering (via `marked`), Mermaid diagram support (theme-aware), collapsible sections, text filtering with highlighting, and cross-document linking - New user-facing docs: `overview.md` (with architecture and per-mode diagrams), `sessions.md`, `cache.md`, `projects.md`; updated `compute.md` - Dev docs moved to `docs/dev/` ### Infrastructure & Bug Fixes - **Deflate compression** for the embedded frontend zip (~3.4MB → ~950KB); zlib inflate support added to `ZipFs` with cached decompressed buffers - **Local IP addresses**: `GetLocalIpAddresses()` (Windows via `GetAdaptersAddresses`, Linux/Mac via `getifaddrs`); surfaced in `/status/status`, `/health/info`, and the dashboard banner - **Dashboard nav**: unified into `zen-nav` web component with `MutationObserver` for dynamically added links, CSS `::part()` to merge banner/nav border radii, and prefix-based active link detection - Stats broadcast refactored from manual JSON string concatenation to `CbObjectWriter`; `CbObject`-to-JS conversion improved for `TimeSpan`, `DateTime`, and large integers - Stats WebSocket boilerplate consolidated into `ZenPage.connect_stats_ws()`
Diffstat (limited to 'src/zencore/system.cpp')
-rw-r--r--src/zencore/system.cpp90
1 files changed, 89 insertions, 1 deletions
diff --git a/src/zencore/system.cpp b/src/zencore/system.cpp
index 23178814c..6909e1a9b 100644
--- a/src/zencore/system.cpp
+++ b/src/zencore/system.cpp
@@ -14,20 +14,27 @@
# include <zencore/windows.h>
ZEN_THIRD_PARTY_INCLUDES_START
-# include <iphlpapi.h>
# include <winsock2.h>
+# include <ws2tcpip.h>
+# include <iphlpapi.h>
# include <pdh.h>
# pragma comment(lib, "pdh.lib")
ZEN_THIRD_PARTY_INCLUDES_END
#elif ZEN_PLATFORM_LINUX
# include <sys/utsname.h>
# include <unistd.h>
+# include <ifaddrs.h>
+# include <arpa/inet.h>
+# include <net/if.h>
#elif ZEN_PLATFORM_MAC
# include <unistd.h>
# include <mach/mach.h>
# include <mach/mach_host.h>
# include <sys/types.h>
# include <sys/sysctl.h>
+# include <ifaddrs.h>
+# include <arpa/inet.h>
+# include <net/if.h>
#endif
namespace zen {
@@ -140,6 +147,51 @@ GetSystemMetrics()
return Metrics;
}
+
+std::vector<std::string>
+GetLocalIpAddresses()
+{
+ std::vector<std::string> Result;
+
+ ULONG BufSize = 15000;
+ auto* Addresses = static_cast<IP_ADAPTER_ADDRESSES*>(Memory::Alloc(BufSize));
+
+ ULONG Flags = GAA_FLAG_SKIP_DNS_SERVER | GAA_FLAG_SKIP_MULTICAST | GAA_FLAG_SKIP_ANYCAST;
+ ULONG Ret = GetAdaptersAddresses(AF_INET, Flags, nullptr, Addresses, &BufSize);
+ if (Ret == ERROR_BUFFER_OVERFLOW)
+ {
+ Memory::Free(Addresses);
+ Addresses = static_cast<IP_ADAPTER_ADDRESSES*>(Memory::Alloc(BufSize));
+ Ret = GetAdaptersAddresses(AF_INET, Flags, nullptr, Addresses, &BufSize);
+ }
+
+ if (Ret == NO_ERROR)
+ {
+ for (IP_ADAPTER_ADDRESSES* Adapter = Addresses; Adapter != nullptr; Adapter = Adapter->Next)
+ {
+ if (Adapter->OperStatus != IfOperStatusUp)
+ {
+ continue;
+ }
+ if (Adapter->IfType == IF_TYPE_SOFTWARE_LOOPBACK)
+ {
+ continue;
+ }
+ for (IP_ADAPTER_UNICAST_ADDRESS* Unicast = Adapter->FirstUnicastAddress; Unicast != nullptr; Unicast = Unicast->Next)
+ {
+ sockaddr_in* SockAddr = reinterpret_cast<sockaddr_in*>(Unicast->Address.lpSockaddr);
+ char AddrBuf[INET_ADDRSTRLEN];
+ if (inet_ntop(AF_INET, &SockAddr->sin_addr, AddrBuf, sizeof(AddrBuf)))
+ {
+ Result.emplace_back(AddrBuf);
+ }
+ }
+ }
+ }
+
+ Memory::Free(Addresses);
+ return Result;
+}
#elif ZEN_PLATFORM_LINUX
std::string
GetMachineName()
@@ -350,6 +402,42 @@ GetSystemMetrics()
# error "Unknown platform"
#endif
+#if ZEN_PLATFORM_LINUX || ZEN_PLATFORM_MAC
+std::vector<std::string>
+GetLocalIpAddresses()
+{
+ std::vector<std::string> Result;
+
+ ifaddrs* Interfaces = nullptr;
+ if (getifaddrs(&Interfaces) != 0)
+ {
+ return Result;
+ }
+
+ for (ifaddrs* Iface = Interfaces; Iface != nullptr; Iface = Iface->ifa_next)
+ {
+ if (Iface->ifa_addr == nullptr || Iface->ifa_addr->sa_family != AF_INET)
+ {
+ continue;
+ }
+ if ((Iface->ifa_flags & IFF_LOOPBACK) != 0 || (Iface->ifa_flags & IFF_UP) == 0)
+ {
+ continue;
+ }
+
+ sockaddr_in* SockAddr = reinterpret_cast<sockaddr_in*>(Iface->ifa_addr);
+ char AddrBuf[INET_ADDRSTRLEN];
+ if (inet_ntop(AF_INET, &SockAddr->sin_addr, AddrBuf, sizeof(AddrBuf)))
+ {
+ Result.emplace_back(AddrBuf);
+ }
+ }
+
+ freeifaddrs(Interfaces);
+ return Result;
+}
+#endif
+
ExtendedSystemMetrics
ApplyReportingOverrides(ExtendedSystemMetrics Metrics)
{