Skip to content

Serve a read-only dashboard screen over the local network - #13

Open
cnLuca0702 wants to merge 1 commit into
gentpan:mainfrom
cnLuca0702:dashboard-screen
Open

cnLuca0702 wants to merge 1 commit into
gentpan:mainfrom
cnLuca0702:dashboard-screen

Conversation

@cnLuca0702

Copy link
Copy Markdown

概述

给 OpenStats 增加「监控大屏」:开启后在局域网提供只读网页仪表盘,同一网络里的平板、旧电脑、电视用浏览器打开 http://<Mac 的 IP>:8790/ 即可实时查看这台 Mac 的监控,适合接一块屏幕当监控墙。

功能

  • 设置 → 监控大屏:开关、端口(8790 / 8791 / 8888)、运行状态与访问地址;字段进出云同步文档,旧文档解码不受影响
  • 零依赖 HTTP 服务:基于 Network.framework(NWListener)自实现,一连接一请求,只读三个端点(/ 页面、/metrics JSON、/healthz 存活);数据不出局域网
  • 页面:自包含单文件 HTML,深色大字,隔远可读;CPU(总占用 + 各核心 + 5 分钟走势)、内存(含交换)、网络上下行速率与走势、磁盘、负载、电量、进程 TOP;自适应横屏 / 竖屏平板 / 窄屏三种形态;断网保留最后读数并持续重连
  • 按需采样:开启大屏时才补采磁盘 / 电量 / 进程,关闭即停;每 2 秒出一份快照,服务器只读快照、互不阻塞;端口被占用等启动失败会在设置页显示原因

实现说明

  • 新增 DashboardServer.swift(HTTP 传输)、DashboardController.swift(快照组装与生命周期)、DashboardPage.swift(页面常量)、DashboardSettings.swift(设置页);其余为在各注册点的少量增量改动(PanelTab / AppSettings / SettingsDocument / AppModel / MainWindowView / Translations)
  • 监听状态由采样循环轮询获得,没有跨线程回调
  • 不改动任何现有监控项的行为

测试

  • 新增 DashboardTests 六项:设置默认值与端口校验、云同步字段往返、HTTP 路由纯函数、/metrics 快照映射(CPU / 内存 / 磁盘的归一化与走势历史)、空库健壮性
  • 全部 192 项测试通过(上游基线 186 + 新增 6)
  • 已在本机与一块竖屏 Mac mini(Firefox kiosk 模式)上端到端联调

Settings gains a Dashboard screen page: when enabled, a built-in HTTP server (NWListener, zero dependencies) publishes /, /metrics and /healthz. Any device on the LAN can open the address for a live view of CPU, memory, network, disk, load, battery and top processes with sparklines. The page adapts to landscape, portrait and phone layouts and keeps retrying through network drops.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant