- F# 89.7%
- CSS 7.3%
- Nix 3%
| Metrics | ||
| nix | ||
| Views | ||
| wwwroot | ||
| .gitignore | ||
| appsettings.Development.json | ||
| appsettings.json | ||
| Config.fs | ||
| Domain.fs | ||
| Errors.fs | ||
| flake.lock | ||
| flake.nix | ||
| Handlers.fs | ||
| Logging.fs | ||
| Program.fs | ||
| README.md | ||
| Router.fs | ||
| ServerDashboard.fsproj | ||
| Settings.fs | ||
| Startup.fs | ||
server-dashboard
The dashboard for nixos-server at server.steenblik.ch: the public services for
everyone, and on the LAN or VPN also the internal services and server metrics
(load, temperatures, free space, fan speeds, internet speed).
F# (Giraffe + Giraffe.ViewEngine) renders the HTML; the only browser script toggles the theme and probes the internal origin.
How the VPN view works
The app listens on two loopback ports:
| Port | nginx host | Serves |
|---|---|---|
publicPort (5180) |
server.steenblik.ch |
the public services |
internalPort (5181) |
server.internal.steenblik.ch |
/ the full dashboard, /fragment metrics + all services, /stream live metrics, POST /fan-mode/{id}, POST /speedtest |
/, /fragment and /stream take ?window=1h|24h|7d for the load graphs (1h by default).
The public page fetches https://server.internal.steenblik.ch/fragment. That host only resolves
and answers on the LAN or VPN (nginx allow-list), so when the fetch succeeds the page swaps
in the internal content. CORS on the internal port allows only PublicOrigin.
Configuration
appsettings.json holds defaults; the file named by SERVER_DASHBOARD_SETTINGS is layered on
top, and environment variables (Dashboard__Server__PublicOrigin=...) win over both. Lists
(Dashboard:Services, Dashboard:Metrics:Temperatures|Disks|Fans) come only from the
settings file, so they never merge index-by-index with the defaults.
appsettings.Development.json is a complete example.
Metrics come from the Prometheus server at Dashboard:Metrics:PrometheusUrl, in one instant query
per refresh for the readings and one range query per load graph. Temperatures and fans select a
sample by metric name and labels (node_hwmon_temp_celsius{chip=...,sensor=...}); a disk with a MountPoint uses
node_filesystem_{avail,size}_bytes on that mount point, and one with a Pool uses
zfs_exporter's zfs_pool_{free,size}_bytes for that pool,
since a ZFS dataset's size is only its own data plus the pool's free space. An Hdd temperature shows
"Spun down" instead of 0 °C, which is what CoolerControl reports for a sleeping disk. A
temperature's Kind (Cpu, Gpu, Board, Nic, Chipset, Hdd, Ssd or Nvme) picks when it
counts as warm or hot; the card's headline shows the worst state across all sensors.
A Nic counts as warm at 80 °C and hot at 85 °C. A Chipset counts as warm at 80 °C
and hot at 90 °C, matching the server’s cooling and alert thresholds.
The load card graphs CPU (node_cpu_seconds_total), GPU (nvidia_gpu_exporter's
nvidia_smi_utilization_gpu_ratio) and memory (node_memory_{MemAvailable,MemTotal}_bytes)
over the last hour, day or week, in about 120 steps that each average their whole span.
Dashboard:Metrics:Speedtest (true) shows the last speedtest, for example from
node_exporter's textfile collector. It reads speedtest_{download,upload}_bytes_per_second,
speedtest_{ping,download,upload}_latency_seconds, speedtest_ping_jitter_seconds,
speedtest_packet_loss_ratio (NaN when unmeasured) and speedtest_timestamp_seconds. The card
also shows the viewer's own round trip, which the browser times against /healthz. With
Dashboard:Metrics:SpeedtestUnit set, a button runs systemctl start --no-block on that unit
(the dashboard's user needs a polkit rule for it) and shows "Testing…" while it is activating. Like
the fan modes it is only routed on the internal port and needs the X-Dashboard-Action header.
Dashboard:Metrics:FanControlUrl is a CoolerControl daemon, with
FanControlTokenFile holding a token that has write access. Its modes then show as buttons in the fan
card; a click posts to /fan-mode/{id}, which activates the mode through CoolerControl's API. The
browser sends an X-Dashboard-Action header, so the request is preflighted and only the
dashboard's own origins can make it. With KeepCoolMode and KeepCoolOffMode set to the names of two
CoolerControl modes, the first becomes a snowflake toggle between Quiet (mute icon) and Full
(fan icon) in the Fans card; switching it off activates the second. Hovering a fan control for
250 ms shows its label. What keeping cool does is up to that mode's
profiles.
Maintenance scheduling and presence automation belong to the host's Home Assistant configuration.
The dashboard retains manual fan controls. KeepCoolManualUnit optionally identifies a systemd
oneshot that records manual ownership after a fan change; the dashboard user needs permission to
start it. The dashboard does not schedule maintenance or expose schedule endpoints.
To find the labels on the server:
curl -s localhost:9100/metrics | grep -E '^node_hwmon_(temp_celsius|fan_rpm)'
Develop
nix develop
ASPNETCORE_ENVIRONMENT=Development dotnet run
Then open http://localhost:5180 (public) or http://localhost:5181 (internal).
After changing NuGet packages, refresh the lock file:
nix build .#default.fetch-deps && ./result nix/deps.json
Deploy
In nixos-server, add the flake input and import the module:
inputs.server-dashboard.url = "git+file:///path/to/server-dashboard"; # or the forge URL
# ...
modules = [ inputs.server-dashboard.nixosModules.default ];
services.prometheus.exporters.node = {
enable = true;
listenAddress = "127.0.0.1";
};
services.prometheus = {
enable = true;
listenAddress = "127.0.0.1";
scrapeConfigs = [
{ job_name = "node"; static_configs = [ { targets = [ "127.0.0.1:9100" ]; } ]; }
];
};
services.server-dashboard = {
enable = true;
settings.Dashboard = {
Services = [ /* { Name; Description; Url; Icon; Group; Visibility = "Public" | "Internal"; } */ ];
Metrics = {
PrometheusUrl = "http://127.0.0.1:9090";
FanControlUrl = "http://127.0.0.1:11987"; # optional, with an optional FanControlTokenFile
KeepCoolMode = "Keep cool"; # optional, together with KeepCoolOffMode
KeepCoolOffMode = "Quiet";
KeepCoolWindowStart = "02:00"; # optional, together with KeepCoolWindowEnd
KeepCoolWindowEnd = "05:00";
Speedtest = true; # optional
SpeedtestUnit = "speedtest.service"; # optional, adds a button that starts it
Temperatures = [ /* { Label; Metric; Labels = [ { Name; Value; } ]; Kind?; } */ ];
Disks = [ /* { Label; MountPoint | Pool; } */ ];
Fans = [ /* same shape as Temperatures */ ];
};
};
};
and in proxy.nix add server = config.services.server-dashboard.publicPort; to publicServices
and server = config.services.server-dashboard.internalPort; to privateServices.