Skip to content

Add top-like monitoring tool#333

Open
ben-grande wants to merge 8 commits into
QubesOS:mainfrom
ben-grande:qvm-top
Open

Add top-like monitoring tool#333
ben-grande wants to merge 8 commits into
QubesOS:mainfrom
ben-grande:qvm-top

Conversation

@ben-grande

@ben-grande ben-grande commented Jan 28, 2025

Copy link
Copy Markdown
Contributor

Add top-like monitoring tool

Inspiration and code from qui-domains and visuals from xentop.

  • Colors entries according to state
  • Footer with clock to show last time the screen was refreshed
  • Allows scrolling domain list when it is longer than the screen height,
    with a less-type hint indicating how many lines to scroll
  • To scroll, readline style (Emacs) navigation is supported, with some
    Vi keys also supported
  • Inexpensive calls using "admin.vm.Stats"

Requires: QubesOS/qubes-core-admin#826
Requires: QubesOS/qubes-core-admin#827

Breaking change on a commit, which requires new client versions:

@marmarek

Copy link
Copy Markdown
Member

is a blocking operation as well as proc.stdout.read(2)

Do you mean read() hangs for you? Maybe the service waits for something before starting to output any data (doesn't look like it based on the other PR...).

@ben-grande

ben-grande commented Jan 28, 2025 via email

Copy link
Copy Markdown
Contributor Author

@marmarek

Copy link
Copy Markdown
Member

Based on discussion in the other PR, this should be converted to use stat events (and events extended to include necessary info). Converting to draft until then.

@marmarek marmarek marked this pull request as draft June 10, 2026 00:49
@ben-grande ben-grande force-pushed the qvm-top branch 2 times, most recently from 75a9ee5 to bc049c9 Compare June 10, 2026 19:25
@ben-grande

Copy link
Copy Markdown
Contributor Author

LLM helped on draw_table(). It's almost stable. It works nicely on R4.2, but not on R4.3. I don't know yet why builds are failing on manpages.

@codecov

codecov Bot commented Jun 11, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 1.38889% with 1065 lines in your changes missing coverage. Please review.
✅ Project coverage is 69.04%. Comparing base (0c7b921) to head (b9be4aa).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
qubesadmin/tools/qvm_top.py 0.00% 1058 Missing ⚠️
qubesadmin/app.py 54.54% 5 Missing ⚠️
qubesadmin/tools/__init__.py 83.33% 1 Missing ⚠️
qubesadmin/vm/__init__.py 66.66% 1 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (0c7b921) and HEAD (b9be4aa). Click for more details.

HEAD has 1 upload less than BASE
Flag BASE (0c7b921) HEAD (b9be4aa)
2 1
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #333      +/-   ##
==========================================
- Coverage   76.79%   69.04%   -7.75%     
==========================================
  Files          53       54       +1     
  Lines        9402    10473    +1071     
==========================================
+ Hits         7220     7231      +11     
- Misses       2182     3242    +1060     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ben-grande

Copy link
Copy Markdown
Contributor Author

One thing I don't plan to fix is the memory reporting being wrong, as only qmemman has the knowledge about memory of each qube, and getting information from it is not currently nice with it's current API (synchonous), and I don't want to delay reporting statistics because qmemman is busy for seconds at a time.

@ben-grande

Copy link
Copy Markdown
Contributor Author

Maybe it's not necessary, reading past conversations, something that I didn't understand one year ago (qmemman, admin.vm.Stats), I think I will settle for meminfo: QubesOS/qubes-core-agent-linux#550 (comment).

@ben-grande

Copy link
Copy Markdown
Contributor Author
qvm-top

xentop has cpu_time for each vcpu, but that may be too much. Xentop has actually a lot of things that can be show about virtual blocks also, but I don't like that much info. Customizing delay is not important to us, the screen refreshed in a loop and the delay is pretty insignificant and is not causing issues to navigate up and down. One think I like is that xentop has sort order, but I can't really see which column is currently being sorted, it's supposed to be bold. Anyway, I like how qvm-top is right now and don't plan to improve further (unless I think about this again, tomorrow...).

@ben-grande

ben-grande commented Jun 11, 2026

Copy link
Copy Markdown
Contributor Author

And one more bug, for dom0, it should use cpu_usage_raw instead of cpu_usage. It seems that the value gets much closer to what xentop reports about Domain-0.

@ben-grande

Copy link
Copy Markdown
Contributor Author

And yes, vm-stats from my core-admin PR is reporting stubdomains, but as the client VMCollection doesn't know about stubdomains, it's never considered. Maybe I could workaround this limitation.

@ben-grande ben-grande force-pushed the qvm-top branch 4 times, most recently from 4ab3c3a to 8027157 Compare June 12, 2026 01:46
@ben-grande

Copy link
Copy Markdown
Contributor Author
new-qvm-top
  • stubdom reporting, can't show memory usage for it, but can show CPU stats
  • NA is better than lying how much memory the qube is using
  • I don't know why Xen adds one mebibyte to maxmem_kb (domain_getinfo) but not on static-max xenstore key.

@marmarek

Copy link
Copy Markdown
Member

I don't know why Xen adds one mebibyte to maxmem_kb (domain_getinfo) but not on static-max xenstore key.

I'm not sure either, but I guess domain_getinfo includes some internal overhead in Xen (EPT? maybe something else too?), but static-max is just what OS can really see.

Anyway, I don't like exposing stubdomains in a high level tool, it should be counted as part of the target qube; if anything, maybe some separate column for some internal overhead, but not separate row.
If somebody really want to look under the hood, they have xentop and other low level tools.

@ben-grande ben-grande force-pushed the qvm-top branch 8 times, most recently from fbcc633 to 3a573f8 Compare June 23, 2026 14:29
@ben-grande

Copy link
Copy Markdown
Contributor Author

I have added a ton of things recently. You can do everything from the keyboard or mouse. You can filter the view, sort by column (or invert), select one or more domains. For the latter, it does nothing currently besides highlighting, the goal is to have an htop like kill column, where you select the kill signal, in our case, it would be "shutdown, kill, (re)start". If there is anything you'd like to see, please let me know. There will be a video tomorrow, if QVC doesn't burn my computer.

In the far future, this might become the qube manager for headless connections, but for now, I will restrict just for statistics due to time.

When checking libvirt event callbacks, VIR_DOMAIN_EVENT_STOPPED is the
only event called when shutting down or destroying/killing a domain, so
the state transitions from Running->Halted, therefore, ever sending
"Halting" or "Dying". I made changes to core-admin to at least inform
the "Halting" state, while deprecating the "Dying" state.

I checked the clients, and only qubes-manager is using "Dying", but it
has a "Halting" equivalent, which all translate to the same visuals as
"Transient".
@ben-grande ben-grande force-pushed the qvm-top branch 7 times, most recently from c5079c0 to fa7a1c6 Compare July 1, 2026 16:22
ben-grande and others added 2 commits July 2, 2026 11:35
Cut in half the to get derived qubes.
Inspiration and code from qui-domains and visuals from xentop.

- Color data, when possible, qube names are colored according to label,
  it works okay on XTerm (except orang) but colors render perfectly on
  Xfce4-terminal. The black label is just printed as the default
  foreground color, because using standout on it would be unnecessary
  highlight.
- Clock to show last time the screen was refreshed
- Allows scrolling domain list when it is longer than the screen height,
  with a less-style type hint indicating pages
- To scroll, readline style (Emacs) navigation is supported, with some
  Vi keys also supported. Mouse navigation is also supported.
- Inexpensive calls using "admin.vm.Stats"
- Can show only columns you specify
- Shows all non-halted domains by default, but can show only specified
  ones also
- Screen refresh is delayed until needed, small sleep to avoid user
  perceiving delays when scrolling
- Can sort per column and click again to reverse the sort, with a little
  indicator at the end of the column
- Can filter list of domains after the program is already running
- Can act based on common actions available from all selected domains,
  such as kill if qubes are running, start if qubes are halted
@ben-grande ben-grande force-pushed the qvm-top branch 2 times, most recently from 677f43d to 9a000ea Compare July 2, 2026 17:42
Strings are trusted, they are just label and name. But some values such
as those reported by the qube via xenstore keys, are not so trusted and
can be large integers. Instead of printing dubious data, print an
ellipsis to symbolize it wouldn't fit. It might be a programming error,
might be a malicious information, fall on the safe side.
- Swap column introduced to know when the qube should have more memory,
  swaping is never nice.
- Columns are ordered in "total", "standard", "internal".
- Do not consider percentage intensity when irrelevant
@ben-grande

Copy link
Copy Markdown
Contributor Author
  • Tested with RemoteVM
  • Reduced default view to just a few columns
  • Improved no color view
  • Actions available, from niceties such as terminal or console to controlling qube state
  • Reordered columns as total, used, internal
  • New swap column
  • Qube names are colored according to their label if the terminal supports, else it will fallback to something close enough

I think I am finished on the client, but will have to retest it after writing and fixing tests of QubesOS/qubes-core-admin#827.


For the description of each column, see the manual page or the help= of the Column.

Minimal view (55 columns):

top-min

Default view (79 columns):

top-default

Maximum view (203 columns):

top-max

The min view is what qui-domains should show.

The default view is what you get without specifying any arguments.

If you noticed, I didn't include maxmem property in the default or min, as I think is MAU -> "memory_assigned_usable", which is what is available in the domain, is more relevant to show available to the domain and MU/MAU to show memory usage (excluding swap, separate column MUS).

The max view is all you can get. Great for debugging the application and see if values add up when they should.


Actions:

top-action top-preload top-action-common

Notice that when selecting both domains, you can only get the common actions.

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.

2 participants