Skip to content

Add SSH metrics and watchdog control, moved from the Home Assistant integration - #66

Merged
chiconws merged 1 commit into
devfrom
feat/ssh-metrics
Oct 29, 2026
Merged

chiconws merged 1 commit into
devfrom
feat/ssh-metrics

Conversation

@chiconws

Copy link
Copy Markdown
Collaborator

Summary

Moves the SSH metric commands and their parsing from the Home Assistant integration into NanoKVMSSH, returning a typed model, and adds control of the non-Pro firmware's watchdog with a firmware check, so callers no longer gate it by version.

Changes

  • get_metrics() returns an SSHMetrics dataclass: boot_time (UTC), cpu_temperature (°C), memory_total and storage_total (MiB, root filesystem), memory_used_percent, storage_used_percent and watchdog_enabled. The commands are the integration's (/proc/stat, thermal_zone0/temp, /proc/meminfo, df -k /).
  • Unreadable values become None instead of failing the whole snapshot. Before, unexpected temperature output raised from a bare float(); a missing thermal zone now yields None too.
  • get_watchdog_enabled() / set_watchdog_enabled(). kvm_system reboots the device when the video service misses its heartbeat (/tmp/nanokvm_wd) for more than 10 seconds, but only while /etc/kvm/watchdog exists. Support is detected by looking for that path in the kvm_system binary, which the Pro doesn't have. Without it, the getter returns None and the setter raises NanoKVMNotSupportedError.
  • Docs. docs/ssh.md gains a metrics and watchdog section.

Notes

  • The support check greps the 380 KB kvm_system binary on every watchdog call (about 0.3 s on the PCIe). It could be cached per connection if polling gets tight.
  • Reconnecting stays with the caller, because NanoKVMSSH doesn't keep the password.

Behaviour changes

None. All methods are additions.

Testing

507 unit tests pass, 3 of them new. Against devices, every command run one by one, then through the new methods:

  • NanoKVM PCIe 2.5.2: all metrics parsed. The watchdog read False; enabled, the heartbeat appeared within 1.3 s and it read True; disabled again after 3.9 s. Boot time unchanged afterwards, so no reboot.
  • NanoKVM Pro 1.2.15: all metrics parsed. The watchdog read None, and set_watchdog_enabled(False) raised NanoKVMNotSupportedError without touching the file.

@chiconws
chiconws merged commit 391d526 into dev Oct 29, 2026
2 checks passed
@chiconws
chiconws deleted the feat/ssh-metrics branch October 29, 2026 01:53
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