Skip to content

Comments

Remove psutil and compute metrics from procfs#8865

Open
macladson wants to merge 3 commits intosigp:unstablefrom
macladson:remove-psutil
Open

Remove psutil and compute metrics from procfs#8865
macladson wants to merge 3 commits intosigp:unstablefrom
macladson:remove-psutil

Conversation

@macladson
Copy link
Member

Issue Addressed

We can remove psutil as a dependency as it is infrequently maintained and unnecessary. We can simply compute the same information using a combination of procfs and nix (which is already a transitive dep)

Proposed Changes

Compute health metrics using procfs instead of psutil and remove psutil as a dependency.

metrics = { workspace = true }

[target.'cfg(target_os = "linux")'.dependencies]
nix = { version = "0.26", default-features = false, features = ["fs"] }
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We deliberately use an outdated version of nix to avoid a duplicate dependency. Once our dependencies update their version of nix, we can bump this too

Comment on lines +233 to +239
/// Compare the new procfs-based implementation against psutil to verify
/// we get equivalent values from the same underlying /proc data source.
///
/// Note: Some values (memory, I/O counters) can change between when we read
/// our values and when psutil reads its values, so we allow small tolerances.
#[test]
fn compare_system_health_with_psutil() {
Copy link
Member Author

@macladson macladson Feb 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got Claude to generate some comparison tests which verify that our procfs-based implementation matches the previous psutil version (within certain tolerances). This will hopefully mean our users don't see system metrics vary wildly when they update.

I just wanted these to ensure they can pass CI but we can remove them once we are sure the new implementation works fine. We can also keep them around, either is fine with me.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually once we are confident this works, we should remove them. Because of the usage of tolerances, they could be flaky

@macladson macladson added the ready-for-review The code is ready for review label Feb 19, 2026
procfs = { version = "0.18", default-features = false }

[target.'cfg(target_os = "linux")'.dev-dependencies]
psutil = "3.3.0"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But this PR is not removing psutil?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once we remove the consistency tests we can remove it. Also, even if we kept the tests it is now just a dev-dependency so it will never be compiled in any release build

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

code-quality ready-for-review The code is ready for review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants