Skip to content

feat: show host metrics speedbar in monit dashboard - #6138

Open
ButchAnton wants to merge 1 commit into
Unitech:developmentfrom
ButchAnton:feat/monit-host-metrics-speedbar
Open

feat: show host metrics speedbar in monit dashboard#6138
ButchAnton wants to merge 1 commit into
Unitech:developmentfrom
ButchAnton:feat/monit-host-metrics-speedbar

Conversation

@ButchAnton

Copy link
Copy Markdown

What

pm2 status/pm2 ls already print a "host metrics" line (CPU, RAM, disk, network, etc.) when pm2:sysmonit is enabled, but pm2 monit/pm2 dashboard never showed it, even though the same getSystemData data is available there too. This adds the same line to the dashboard, directly below the existing help/shortcuts bar.

Details

  • lib/API/Extra.js: dashboard() now also polls getSystemData on its own 2s interval (independent of the existing 800ms per-process getMonitorData poll, since host metrics are a daemon-wide snapshot, not per-process) and forwards the result to Dashboard.refreshSystemData().
  • lib/API/Dashboard.js:
    • New speedbarBox widget, hidden by default.
    • New Dashboard.refreshSystemData() renders the line (ported from miniMonitBar() in lib/API/UX/pm2-ls.js, same thresholds/colors, just blessed content tags instead of chalk/ansis) and calls a new setSpeedbarLayout() helper.
    • setSpeedbarLayout() toggles between two fixed layouts so the bar only takes up space when there's actually data to show: when pm2:sysmonit is off (or hasn't reported yet), metadataBox/metricsBox/box4 sit exactly where they do today and speedbarBox is hidden - no permanent dead space. When data arrives, metadataBox/metricsBox shrink slightly and box4 moves up to make room for the bar. screen.realloc() is called on each transition so blessed does a full repaint instead of leaving stale borders/content from the previous layout (its incremental diff render only marks cells dirty on content changes, not dimension changes).
    • While sizing the new layout, this also happens to fix a pre-existing cosmetic bug: box4's stock top: '95%', height: '6%' ends at 101%, one point past both the screen and past metadataBox/metricsBox's own bottom edge (70% + 26% = 96%). At certain terminal row counts (rounding-dependent, e.g. exactly 50 rows) that 1% overlap causes box4 to paint over the bottom border of the metadata/custom metrics panels, since it's appended after them. Both states now use 25%/5% instead of 26%/6%, which closes the gap everywhere rather than only at the row counts stock pm2's rounding happens to dodge it at.

Testing

Manually verified against a scratch PM2_HOME in a tmux session at a few terminal sizes:

  • pm2:sysmonit on: speedbar renders below the help line with correct data/colors, no border clipping.
  • pm2:sysmonit off: layout matches current stock pm2 exactly, no empty reserved line.
  • Toggling on/off (via daemon restart) transitions cleanly with no stale artifacts.

Happy to add/adjust automated coverage if there's a preferred pattern for dashboard/blessed-UI tests in this repo - I didn't see existing ones to follow for lib/API/Dashboard.js.

Made with Cursor

pm2 status/ls already print a host metrics ("speedbar") line when
pm2:sysmonit is enabled, but pm2 monit/dashboard never showed it,
even though the same getSystemData data is available. This adds the
same line below the help bar in the dashboard, refreshed on its own
2s poll independent of the per-process 800ms refresh loop.

The bar only takes up space when there is data to show: layout
toggles between two fixed states (no speedbar vs. speedbar) so
metadata/custom metrics panels reclaim the space when pm2:sysmonit
is off, instead of leaving a permanent empty line.

While sizing the new layout, also fixes a pre-existing 1% overlap
between box4 and the metadata/custom metrics panels that clipped
their bottom border at certain terminal row counts even without this
change (heights are 25%/5% for both states now instead of 26%/6%).

Co-authored-by: Cursor <cursoragent@cursor.com>
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