brainframe-sys-tools 0.5.6__tar.gz → 0.5.7__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. brainframe_sys_tools-0.5.7/PKG-INFO +201 -0
  2. brainframe_sys_tools-0.5.7/README.md +175 -0
  3. {brainframe_sys_tools-0.5.6 → brainframe_sys_tools-0.5.7}/brainframe_sys_tools/bf_info.py +2 -0
  4. {brainframe_sys_tools-0.5.6 → brainframe_sys_tools-0.5.7}/brainframe_sys_tools/bf_service_monitor.py +156 -68
  5. {brainframe_sys_tools-0.5.6 → brainframe_sys_tools-0.5.7}/brainframe_sys_tools/brainframe_monitor/__pycache__/benchmarker.cpython-312.pyc +0 -0
  6. brainframe_sys_tools-0.5.7/brainframe_sys_tools/brainframe_monitor/__pycache__/brainframe_monitor.cpython-312.pyc +0 -0
  7. brainframe_sys_tools-0.5.7/brainframe_sys_tools/brainframe_monitor/__pycache__/curses_utils.cpython-312.pyc +0 -0
  8. brainframe_sys_tools-0.5.7/brainframe_sys_tools/setup_monitor.py +438 -0
  9. {brainframe_sys_tools-0.5.6 → brainframe_sys_tools-0.5.7}/pyproject.toml +1 -1
  10. brainframe_sys_tools-0.5.6/PKG-INFO +0 -62
  11. brainframe_sys_tools-0.5.6/README.md +0 -36
  12. brainframe_sys_tools-0.5.6/brainframe_sys_tools/.python-version +0 -1
  13. brainframe_sys_tools-0.5.6/brainframe_sys_tools/brainframe_monitor/__pycache__/brainframe_monitor.cpython-312.pyc +0 -0
  14. {brainframe_sys_tools-0.5.6 → brainframe_sys_tools-0.5.7}/COPYING +0 -0
  15. {brainframe_sys_tools-0.5.6 → brainframe_sys_tools-0.5.7}/brainframe_sys_tools/__init__.py +0 -0
  16. {brainframe_sys_tools-0.5.6 → brainframe_sys_tools-0.5.7}/brainframe_sys_tools/bf_ssh_tunnel.py +0 -0
  17. {brainframe_sys_tools-0.5.6 → brainframe_sys_tools-0.5.7}/brainframe_sys_tools/brainframe_monitor/__pycache__/fake_screen.cpython-312.pyc +0 -0
  18. {brainframe_sys_tools-0.5.6 → brainframe_sys_tools-0.5.7}/brainframe_sys_tools/brainframe_monitor/__pycache__/report.cpython-312.pyc +0 -0
  19. {brainframe_sys_tools-0.5.6 → brainframe_sys_tools-0.5.7}/brainframe_sys_tools/brainframe_monitor/__pycache__/system_monitor.cpython-312.pyc +0 -0
  20. {brainframe_sys_tools-0.5.6 → brainframe_sys_tools-0.5.7}/brainframe_sys_tools/brainframe_monitor/benchmarker.py +0 -0
  21. {brainframe_sys_tools-0.5.6 → brainframe_sys_tools-0.5.7}/brainframe_sys_tools/brainframe_monitor/brainframe_monitor.py +0 -0
  22. {brainframe_sys_tools-0.5.6 → brainframe_sys_tools-0.5.7}/brainframe_sys_tools/brainframe_monitor/curses_utils.py +0 -0
  23. {brainframe_sys_tools-0.5.6 → brainframe_sys_tools-0.5.7}/brainframe_sys_tools/brainframe_monitor/fake_screen.py +0 -0
  24. {brainframe_sys_tools-0.5.6 → brainframe_sys_tools-0.5.7}/brainframe_sys_tools/brainframe_monitor/report.py +0 -0
  25. {brainframe_sys_tools-0.5.6 → brainframe_sys_tools-0.5.7}/brainframe_sys_tools/check_memory.py +0 -0
  26. {brainframe_sys_tools-0.5.6 → brainframe_sys_tools-0.5.7}/brainframe_sys_tools/cli.py +0 -0
  27. {brainframe_sys_tools-0.5.6 → brainframe_sys_tools-0.5.7}/brainframe_sys_tools/command_utils.py +0 -0
  28. {brainframe_sys_tools-0.5.6 → brainframe_sys_tools-0.5.7}/brainframe_sys_tools/perf_monitor.py +0 -0
  29. {brainframe_sys_tools-0.5.6 → brainframe_sys_tools-0.5.7}/brainframe_sys_tools/print_utils.py +0 -0
  30. {brainframe_sys_tools-0.5.6 → brainframe_sys_tools-0.5.7}/brainframe_sys_tools/translations/portal.en.yml +0 -0
@@ -0,0 +1,201 @@
1
+ Metadata-Version: 2.1
2
+ Name: brainframe-sys-tools
3
+ Version: 0.5.7
4
+ Summary: This is the package including tools for BrainFrame developers to monitor and debug the system.
5
+ License: BSD License
6
+ Author: Stephen Li
7
+ Author-email: stephen@aotu.ai
8
+ Requires-Python: >=3.9,<4.0
9
+ Classifier: License :: OSI Approved :: BSD License
10
+ Classifier: License :: Other/Proprietary License
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.9
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Requires-Dist: PyYAML (>=6.0.2,<7.0.0)
17
+ Requires-Dist: apscheduler (>=3.10.4,<4.0.0)
18
+ Requires-Dist: brainframe-api (>=0.30.4,<0.31.0)
19
+ Requires-Dist: brainframe_apps (>=0.5.4,<0.6.0)
20
+ Requires-Dist: psutil (>=5.8.0,<6.0.0)
21
+ Requires-Dist: python_i18n (>=0.3.9,<0.4.0)
22
+ Requires-Dist: requests (>=2.32.3,<3.0.0)
23
+ Requires-Dist: tabulate (>=0.8.9,<0.9.0)
24
+ Description-Content-Type: text/markdown
25
+
26
+ # brainframe-sys-tools
27
+
28
+ Python CLI tools for monitoring and debugging BrainFrame system deployment.
29
+
30
+ ## Installation
31
+
32
+ ```bash
33
+ pip install brainframe-sys-tools
34
+ ```
35
+
36
+ ## Usage
37
+
38
+ ```bash
39
+ brainframe-sys-tools <command> [options]
40
+ ```
41
+
42
+ ### Commands
43
+
44
+ - `perf-monitor` - Monitor CPU, GPU, memory, storage, and temperatures
45
+ - `fps-monitor` - Monitor BrainFrame stream FPS and throughput
46
+ - `service-monitor` - Run in the foreground, or use `install`, `status`,
47
+ and `uninstall` to manage the daemon and WDAT watchdog
48
+ - `sys-info` - Display system information
49
+ - `ssh-tunnel` - Create SSH tunnels
50
+
51
+ ### Example
52
+
53
+ ```bash
54
+ brainframe-sys-tools perf-monitor
55
+ brainframe-sys-tools fps-monitor --server-url http://localhost
56
+ brainframe-sys-tools service-monitor install --dry-run
57
+ ```
58
+
59
+ ## Help
60
+
61
+ ```bash
62
+ brainframe-sys-tools <command> --help
63
+ ```
64
+
65
+ ## BrainFrame Service Monitoring & Recovery Design
66
+
67
+ The target NUC setup has two independent recovery layers. Follow the setup
68
+ steps below to activate them; neither layer is active just because this
69
+ repository has been updated.
70
+
71
+ 1. **BrainFrame service monitor:** every 30 seconds, request the local
72
+ BrainFrame version with a 10-second timeout. After three consecutive
73
+ failures, and no sooner than 10 minutes after the previous automatic
74
+ recovery, run `brainframe compose down` and `brainframe compose up -d`.
75
+ On startup, allow BrainFrame up to five minutes to initialize before
76
+ counting failed checks. Zone status is logged after a successful version
77
+ check but never triggers a restart. This layer never reboots the host.
78
+ systemd also restarts the monitor itself if it exits or stops sending
79
+ its service heartbeat for 10 minutes.
80
+ 2. **Hardware watchdog:** the kernel's `wdat_wdt` driver exposes the NUC's
81
+ WDAT device as `/dev/watchdog0`. systemd (PID 1) feeds the device. If
82
+ systemd cannot run long enough to feed it, the hardware timer resets the
83
+ host. The BrainFrame monitor does not feed this timer: an application
84
+ failure should restart the application, not the whole machine.
85
+
86
+ The old `watchdog.service` used a load-average check that rebooted this NUC
87
+ when its 15-minute load average exceeded 12 for 60 seconds. Keep that
88
+ service disabled. It did not detect out-of-memory events. The previous
89
+ BrainFrame monitor would restart the full Compose stack after a single
90
+ failed API check; the NUC had no monitor service installed.
91
+
92
+ ### Install the system watchdog and service monitor
93
+
94
+ On a WDAT-capable BrainFrame server, run the installed sys-tools command
95
+ as the account that runs BrainFrame:
96
+
97
+ ```bash
98
+ brainframe-sys-tools service-monitor install
99
+ ```
100
+
101
+ Run the command as the login account, **not** with `sudo`. It prompts for
102
+ sudo when changing system settings. Use `--dry-run` to inspect the generated
103
+ unit and configuration without changing the machine.
104
+
105
+ `service-monitor install` checks for the WDAT firmware device and BrainFrame CLI,
106
+ then performs these steps in order:
107
+
108
+ 1. Mask the old watchdog's keepalive helper, then disable the load-based
109
+ `watchdog.service` before loading WDAT. Neither can then take ownership
110
+ of the hardware timer.
111
+ 2. Load `wdat_wdt`, confirm `/dev/watchdog0` identifies as `wdat_wdt`, add
112
+ the module to the initramfs, and rebuild the initramfs for future boots.
113
+ 3. Configure systemd (PID 1) to feed `/dev/watchdog0` with a three-minute
114
+ timeout. This is within the inspected NUC's 2-613 second range.
115
+ 4. Install and enable `brainframe-service-monitor.service` for the login account,
116
+ with 30-second checks, 10-second request timeout, three failures before
117
+ recovery, a 10-minute restart cooldown, and a 10-minute systemd service
118
+ watchdog for a stuck monitor process.
119
+ 5. Confirm that the hardware watchdog and BrainFrame monitor are active.
120
+
121
+ The command stops with an error if this host lacks WDAT or if verification
122
+ fails. It does not deliberately expire the hardware timer. A controlled
123
+ expiry test is still needed to prove that the firmware resets the machine;
124
+ do that during a maintenance window. Enabling the hardware watchdog arms a
125
+ real reset timer, so run setup while you can observe the machine.
126
+
127
+ ### Run service-monitor daemon
128
+
129
+ `service-monitor install` installs `brainframe-service-monitor.service`, starts it immediately,
130
+ and enables it at boot. The daemon runs as the login account supplied during
131
+ setup. It checks the BrainFrame API and writes heartbeat logs to
132
+ `~/.local/state/brainframe-service-monitor/`.
133
+
134
+ Use systemd to start, stop, or restart daemon mode:
135
+
136
+ ```bash
137
+ sudo systemctl start brainframe-service-monitor.service
138
+ sudo systemctl stop brainframe-service-monitor.service
139
+ sudo systemctl restart brainframe-service-monitor.service
140
+ ```
141
+
142
+ Restarting the monitor process does not restart BrainFrame unless the monitor
143
+ later observes three consecutive API failures.
144
+
145
+ For foreground troubleshooting, stop the systemd service before running the
146
+ CLI directly. This avoids two monitors trying to recover BrainFrame at once:
147
+
148
+ ```bash
149
+ sudo systemctl stop brainframe-service-monitor.service
150
+ brainframe-sys-tools service-monitor
151
+ ```
152
+
153
+ Press `Ctrl+C` to stop foreground mode, then run
154
+ `sudo systemctl start brainframe-service-monitor.service` to restore daemon
155
+ mode. The local URL, log path, check interval, request timeout, failure
156
+ count, and restart cooldown shown by `service-monitor --help` have defaults;
157
+ pass options only when you need to override them.
158
+
159
+ ### Check status
160
+
161
+ Check both recovery layers and show the last 30 monitor journal entries with:
162
+
163
+ ```bash
164
+ brainframe-sys-tools service-monitor status
165
+ ```
166
+
167
+ The summary reports whether `brainframe-service-monitor.service` is active
168
+ and enabled, whether WDAT is active and fed by systemd, and whether the old
169
+ load watchdog is inactive. It also lists machine boots from `wtmp` and
170
+ monitor-initiated BrainFrame stack restarts from the system journal for the
171
+ past 30 days. The available history may be shorter if `wtmp` or journal
172
+ records have been rotated away; manual Compose restarts are not logged by the
173
+ monitor. The command exits with an error if a recovery layer is missing. Use
174
+ `--logs 0` to omit the recent monitor log tail (the 30-day history still
175
+ appears), or `--logs N` to choose its length. Repeat the status check after
176
+ the next planned host reboot to verify both layers started automatically.
177
+
178
+ ### Uninstall the system watchdog and service monitor
179
+
180
+ To stop the BrainFrame monitor and disarm systemd's hardware watchdog, run:
181
+
182
+ ```bash
183
+ brainframe-sys-tools service-monitor uninstall
184
+ ```
185
+
186
+ Run this as the login account; the command prompts for sudo. It removes
187
+ only configuration files marked as managed by sys-tools and the WDAT
188
+ initramfs entry if sys-tools added it. It unmasks the old `wd_keepalive`
189
+ helper without starting it, and does not re-enable the old load-based
190
+ `watchdog.service`. The WDAT driver may remain loaded until the next
191
+ reboot, but its timer is inactive. Use `service-monitor uninstall --dry-run`
192
+ to preview the changes and `service-monitor status --logs 0` to inspect the
193
+ result.
194
+
195
+ If WDAT cannot be made usable, the kernel's `softdog` is a fallback for a
196
+ stalled user-space feeder while kernel timers still work. It cannot reset a
197
+ fully frozen kernel, so it is weaker than the NUC's hardware watchdog.
198
+
199
+ See the [systemd hardware watchdog settings](https://manpages.ubuntu.com/manpages/jammy/man5/systemd-system.conf.5.html)
200
+ and the [initramfs module loading rules](https://manpages.ubuntu.com/manpages/jammy/man7/initramfs-tools.7.html).
201
+
@@ -0,0 +1,175 @@
1
+ # brainframe-sys-tools
2
+
3
+ Python CLI tools for monitoring and debugging BrainFrame system deployment.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pip install brainframe-sys-tools
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```bash
14
+ brainframe-sys-tools <command> [options]
15
+ ```
16
+
17
+ ### Commands
18
+
19
+ - `perf-monitor` - Monitor CPU, GPU, memory, storage, and temperatures
20
+ - `fps-monitor` - Monitor BrainFrame stream FPS and throughput
21
+ - `service-monitor` - Run in the foreground, or use `install`, `status`,
22
+ and `uninstall` to manage the daemon and WDAT watchdog
23
+ - `sys-info` - Display system information
24
+ - `ssh-tunnel` - Create SSH tunnels
25
+
26
+ ### Example
27
+
28
+ ```bash
29
+ brainframe-sys-tools perf-monitor
30
+ brainframe-sys-tools fps-monitor --server-url http://localhost
31
+ brainframe-sys-tools service-monitor install --dry-run
32
+ ```
33
+
34
+ ## Help
35
+
36
+ ```bash
37
+ brainframe-sys-tools <command> --help
38
+ ```
39
+
40
+ ## BrainFrame Service Monitoring & Recovery Design
41
+
42
+ The target NUC setup has two independent recovery layers. Follow the setup
43
+ steps below to activate them; neither layer is active just because this
44
+ repository has been updated.
45
+
46
+ 1. **BrainFrame service monitor:** every 30 seconds, request the local
47
+ BrainFrame version with a 10-second timeout. After three consecutive
48
+ failures, and no sooner than 10 minutes after the previous automatic
49
+ recovery, run `brainframe compose down` and `brainframe compose up -d`.
50
+ On startup, allow BrainFrame up to five minutes to initialize before
51
+ counting failed checks. Zone status is logged after a successful version
52
+ check but never triggers a restart. This layer never reboots the host.
53
+ systemd also restarts the monitor itself if it exits or stops sending
54
+ its service heartbeat for 10 minutes.
55
+ 2. **Hardware watchdog:** the kernel's `wdat_wdt` driver exposes the NUC's
56
+ WDAT device as `/dev/watchdog0`. systemd (PID 1) feeds the device. If
57
+ systemd cannot run long enough to feed it, the hardware timer resets the
58
+ host. The BrainFrame monitor does not feed this timer: an application
59
+ failure should restart the application, not the whole machine.
60
+
61
+ The old `watchdog.service` used a load-average check that rebooted this NUC
62
+ when its 15-minute load average exceeded 12 for 60 seconds. Keep that
63
+ service disabled. It did not detect out-of-memory events. The previous
64
+ BrainFrame monitor would restart the full Compose stack after a single
65
+ failed API check; the NUC had no monitor service installed.
66
+
67
+ ### Install the system watchdog and service monitor
68
+
69
+ On a WDAT-capable BrainFrame server, run the installed sys-tools command
70
+ as the account that runs BrainFrame:
71
+
72
+ ```bash
73
+ brainframe-sys-tools service-monitor install
74
+ ```
75
+
76
+ Run the command as the login account, **not** with `sudo`. It prompts for
77
+ sudo when changing system settings. Use `--dry-run` to inspect the generated
78
+ unit and configuration without changing the machine.
79
+
80
+ `service-monitor install` checks for the WDAT firmware device and BrainFrame CLI,
81
+ then performs these steps in order:
82
+
83
+ 1. Mask the old watchdog's keepalive helper, then disable the load-based
84
+ `watchdog.service` before loading WDAT. Neither can then take ownership
85
+ of the hardware timer.
86
+ 2. Load `wdat_wdt`, confirm `/dev/watchdog0` identifies as `wdat_wdt`, add
87
+ the module to the initramfs, and rebuild the initramfs for future boots.
88
+ 3. Configure systemd (PID 1) to feed `/dev/watchdog0` with a three-minute
89
+ timeout. This is within the inspected NUC's 2-613 second range.
90
+ 4. Install and enable `brainframe-service-monitor.service` for the login account,
91
+ with 30-second checks, 10-second request timeout, three failures before
92
+ recovery, a 10-minute restart cooldown, and a 10-minute systemd service
93
+ watchdog for a stuck monitor process.
94
+ 5. Confirm that the hardware watchdog and BrainFrame monitor are active.
95
+
96
+ The command stops with an error if this host lacks WDAT or if verification
97
+ fails. It does not deliberately expire the hardware timer. A controlled
98
+ expiry test is still needed to prove that the firmware resets the machine;
99
+ do that during a maintenance window. Enabling the hardware watchdog arms a
100
+ real reset timer, so run setup while you can observe the machine.
101
+
102
+ ### Run service-monitor daemon
103
+
104
+ `service-monitor install` installs `brainframe-service-monitor.service`, starts it immediately,
105
+ and enables it at boot. The daemon runs as the login account supplied during
106
+ setup. It checks the BrainFrame API and writes heartbeat logs to
107
+ `~/.local/state/brainframe-service-monitor/`.
108
+
109
+ Use systemd to start, stop, or restart daemon mode:
110
+
111
+ ```bash
112
+ sudo systemctl start brainframe-service-monitor.service
113
+ sudo systemctl stop brainframe-service-monitor.service
114
+ sudo systemctl restart brainframe-service-monitor.service
115
+ ```
116
+
117
+ Restarting the monitor process does not restart BrainFrame unless the monitor
118
+ later observes three consecutive API failures.
119
+
120
+ For foreground troubleshooting, stop the systemd service before running the
121
+ CLI directly. This avoids two monitors trying to recover BrainFrame at once:
122
+
123
+ ```bash
124
+ sudo systemctl stop brainframe-service-monitor.service
125
+ brainframe-sys-tools service-monitor
126
+ ```
127
+
128
+ Press `Ctrl+C` to stop foreground mode, then run
129
+ `sudo systemctl start brainframe-service-monitor.service` to restore daemon
130
+ mode. The local URL, log path, check interval, request timeout, failure
131
+ count, and restart cooldown shown by `service-monitor --help` have defaults;
132
+ pass options only when you need to override them.
133
+
134
+ ### Check status
135
+
136
+ Check both recovery layers and show the last 30 monitor journal entries with:
137
+
138
+ ```bash
139
+ brainframe-sys-tools service-monitor status
140
+ ```
141
+
142
+ The summary reports whether `brainframe-service-monitor.service` is active
143
+ and enabled, whether WDAT is active and fed by systemd, and whether the old
144
+ load watchdog is inactive. It also lists machine boots from `wtmp` and
145
+ monitor-initiated BrainFrame stack restarts from the system journal for the
146
+ past 30 days. The available history may be shorter if `wtmp` or journal
147
+ records have been rotated away; manual Compose restarts are not logged by the
148
+ monitor. The command exits with an error if a recovery layer is missing. Use
149
+ `--logs 0` to omit the recent monitor log tail (the 30-day history still
150
+ appears), or `--logs N` to choose its length. Repeat the status check after
151
+ the next planned host reboot to verify both layers started automatically.
152
+
153
+ ### Uninstall the system watchdog and service monitor
154
+
155
+ To stop the BrainFrame monitor and disarm systemd's hardware watchdog, run:
156
+
157
+ ```bash
158
+ brainframe-sys-tools service-monitor uninstall
159
+ ```
160
+
161
+ Run this as the login account; the command prompts for sudo. It removes
162
+ only configuration files marked as managed by sys-tools and the WDAT
163
+ initramfs entry if sys-tools added it. It unmasks the old `wd_keepalive`
164
+ helper without starting it, and does not re-enable the old load-based
165
+ `watchdog.service`. The WDAT driver may remain loaded until the next
166
+ reboot, but its timer is inactive. Use `service-monitor uninstall --dry-run`
167
+ to preview the changes and `service-monitor status --logs 0` to inspect the
168
+ result.
169
+
170
+ If WDAT cannot be made usable, the kernel's `softdog` is a fallback for a
171
+ stalled user-space feeder while kernel timers still work. It cannot reset a
172
+ fully frozen kernel, so it is weaker than the NUC's hardware watchdog.
173
+
174
+ See the [systemd hardware watchdog settings](https://manpages.ubuntu.com/manpages/jammy/man5/systemd-system.conf.5.html)
175
+ and the [initramfs module loading rules](https://manpages.ubuntu.com/manpages/jammy/man7/initramfs-tools.7.html).
@@ -57,6 +57,8 @@ cmdlines = [
57
57
  "uname -a",
58
58
  "ldd --version",
59
59
  "cat /proc/cpuinfo",
60
+ "cat /proc/meminfo",
61
+ "lsblk",
60
62
  "cat /etc/docker/daemon.json",
61
63
  "nvidia-smi",
62
64
  "whereis nvidia",