-
Notifications
You must be signed in to change notification settings - Fork 34
feat: add cpu and ram visualiser #175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughThis update adds the Changes
Sequence Diagram(s)sequenceDiagram
participant U as User
participant SA as Streamlit App
participant RS as render_sidebar
participant MH as monitor_hardware
participant PS as psutil
U->>SA: Launch application
SA->>RS: Render sidebar
RS->>MH: Invoke monitor_hardware (every 5 sec)
MH->>PS: Request CPU & RAM metrics
PS-->>MH: Return hardware data
MH->>RS: Update sidebar display (text, progress, caption)
RS->>U: Display updated hardware stats
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
⏰ Context from checks skipped due to timeout of 90000ms (3)
🔇 Additional comments (3)
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🔭 Outside diff range comments (1)
src/common/common.py (1)
226-230: 💡 Verification agent🧩 Analysis chain
Fix the variable assignment issue reported by Pylint.
There's a potential issue where
workspaces_dirmight be used before it's assigned on line 231, as indicated by the pipeline failure.Apply this fix to ensure the variable is properly initialized:
- workspace_dir = '..' + workspaces_dir = '..' # Check if workspace logic is enabled if st.session_state.settings["enable_workspaces"]:Let's verify this issue with a script:
🏁 Script executed:
#!/bin/bash # Verify the variable naming consistency in the code rg "workspace_dir" src/common/common.py rg "workspaces_dir" src/common/common.pyLength of output: 1299
Fix variable naming for workspace settings consistency
- In file
src/common/common.py, update the variable assignment on line 226 fromworkspace_dir = '..'toworkspaces_dir = '..'to ensure it matches the rest of the file.- This change resolves the potential issue flagged by Pylint where
workspaces_dirmight have been referenced before being initialized.- workspace_dir = '..' + workspaces_dir = '..'🧰 Tools
🪛 Ruff (0.8.2)
226-226: Local variable
workspace_diris assigned to but never usedRemove assignment to unused variable
workspace_dir(F841)
🧹 Nitpick comments (2)
environment.yml (1)
18-18: Dependency added correctly.The
psutildependency has been added at the specific version 7.0.0, which is consistent with the addition inrequirements.txt.Consider adding a newline at the end of the file to satisfy linting rules:
- psutil==7.0.0 +🧰 Tools
🪛 YAMLlint (1.35.1)
[error] 18-18: no new line character at the end of file
(new-line-at-end-of-file)
src/common/common.py (1)
26-37: Good implementation of hardware monitoring feature.The function implements CPU and RAM visualization with appropriate refresh rate. The use of
@st.fragment(run_every=5)is an excellent choice for this type of monitoring feature, as it allows updating the UI component without requiring a full page refresh.Two small improvements could be made:
- Consider adding a docstring to explain the function's purpose
- Consider rounding the RAM percentage for better readability
@st.fragment(run_every=5) def monitor_hardware(): + """ + Monitors and displays CPU and RAM usage statistics. + This function is automatically refreshed every 5 seconds. + """ cpu_progress = psutil.cpu_percent(interval=None) / 100 - ram_progress = 1 - psutil.virtual_memory().available / psutil.virtual_memory().total + memory = psutil.virtual_memory() + ram_progress = memory.percent / 100 st.text(f"Ram ({ram_progress * 100:.2f}%)") st.progress(ram_progress) st.text(f"CPU ({cpu_progress * 100:.2f}%)") st.progress(cpu_progress) st.caption(f"Last fetched at: {time.strftime('%H:%M:%S')}")
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
environment.yml(1 hunks)requirements.txt(1 hunks)src/common/common.py(4 hunks)
🧰 Additional context used
🪛 YAMLlint (1.35.1)
environment.yml
[error] 18-18: no new line character at the end of file
(new-line-at-end-of-file)
🪛 GitHub Actions: Pylint
src/common/common.py
[error] 231-231: E0606: Possibly using variable 'workspaces_dir' before assignment (possibly-used-before-assignment)
⏰ Context from checks skipped due to timeout of 90000ms (3)
- GitHub Check: build-simple-app
- GitHub Check: build-full-app
- GitHub Check: build-openms
🔇 Additional comments (4)
requirements.txt (1)
11-11: Dependency added correctly.The
psutildependency has been added at version 7.0.0, which is consistent with the addition inenvironment.yml.src/common/common.py (3)
13-13: Import added for new functionality.The
psutillibrary import is correctly added to support the new hardware monitoring feature.
294-296: Good integration of the monitoring feature in the sidebar.The CPU and RAM visualization has been cleanly integrated into the sidebar with an appropriate expandable section.
365-365: Minor formatting adjustment.The whitespace change around the session state assignment is minor and doesn't affect functionality.
t0mdavid-m
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me! Just two minor things: Could you rename the expander to "Resource Utilization" and move it below the settings expander? After this the PR is ready to merge from my side.
Sure! |
…lit-template into cpu-visualiser
|
LGTM! Thank you for your contribution. |

Fixes: #124
st.fragmentwithre-runto check cpu and ram stats every 5 secondsRecording
Screen.Recording.2025-03-12.at.9.04.39.PM.mov
Summary by CodeRabbit
psutil==7.0.0, to enhance system monitoring capabilities.