-
-
Notifications
You must be signed in to change notification settings - Fork 52
feat: Add system health monitoring module (#128) #292
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
Closed
Closed
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
1a56ba1
feat: Implement comprehensive system health checks for #128
hyaku0121 dc54e53
feat: Add health monitor core logic, CLI integration, and unit tests
hyaku0121 0889c76
fix: Add timeouts to subprocess calls to improve reliability
hyaku0121 fd88be0
refactor: Address code review feedback (docstrings, timeouts, complex…
hyaku0121 f4ced43
refactor: Improve security check complexity and SSH parsing logic
hyaku0121 f87bd8c
fix: Resolve SonarCloud code smells and reduce complexity
hyaku0121 2e950b1
docs: Add missing docstrings to HealthMonitor public APIs
hyaku0121 8240944
fix: Address SonarCloud and CodeRabbit feedback (redundant exceptions…
hyaku0121 db3bf19
fix: improve CodeQL compliance in health checks
hyaku0121 6f2d8a3
style: fix ruff linter errors in health module
hyaku0121 fa3b020
style: fix W292 and W293 ruff errors
hyaku0121 14b5158
fix: secure verify_ubuntu_compatibility.py and fix ruff errors
hyaku0121 ee2e8e6
fix: resolve syntax error in cli.py and missing newline
hyaku0121 9582f3b
style: apply black formatting to remaining files
hyaku0121 dea2609
fix: correct expected score in test_apt_updates test
hyaku0121 ef9a253
fix: correct test assertion and restore files to main state
hyaku0121 7a6d42d
style: fix import sorting in cli.py
127bb75
style: fix black formatting in intent module
f974bd6
Merge branch 'main' into feature/health-score-128
hyaku0121 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| import shutil | ||
|
|
||
| from ..monitor import CheckResult, HealthCheck | ||
|
|
||
|
|
||
| class DiskCheck(HealthCheck): | ||
| """Check root filesystem disk usage.""" | ||
|
|
||
| def run(self) -> CheckResult: | ||
| """Calculate disk usage percentage. | ||
|
|
||
| Returns: | ||
| CheckResult based on usage thresholds. | ||
| """ | ||
| try: | ||
| # Use _ for unused variable (free space) | ||
| total, used, _ = shutil.disk_usage("/") | ||
| usage_percent = (used / total) * 100 | ||
| except Exception as e: | ||
| return CheckResult( | ||
| name="Disk Usage", | ||
| category="disk", | ||
| score=0, | ||
| status="CRITICAL", | ||
| details=f"Check failed: {e}", | ||
| recommendation="Check disk mounts and permissions", | ||
| weight=0.20, | ||
| ) | ||
|
|
||
| # Explicit early returns to avoid static analysis confusion | ||
| if usage_percent > 90: | ||
| return CheckResult( | ||
| name="Disk Usage", | ||
| category="disk", | ||
| score=0, | ||
| status="CRITICAL", | ||
| details=f"{usage_percent:.1f}% used", | ||
| recommendation="Clean up disk space immediately", | ||
| weight=0.20, | ||
| ) | ||
|
|
||
| if usage_percent > 80: | ||
| return CheckResult( | ||
| name="Disk Usage", | ||
| category="disk", | ||
| score=50, | ||
| status="WARNING", | ||
| details=f"{usage_percent:.1f}% used", | ||
| recommendation="Consider cleaning up disk space", | ||
| weight=0.20, | ||
| ) | ||
|
|
||
| return CheckResult( | ||
| name="Disk Usage", | ||
| category="disk", | ||
| score=100, | ||
| status="OK", | ||
| details=f"{usage_percent:.1f}% used", | ||
| recommendation=None, | ||
| weight=0.20, | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| import multiprocessing | ||
| import os | ||
|
|
||
| from ..monitor import CheckResult, HealthCheck | ||
|
|
||
|
|
||
| class PerformanceCheck(HealthCheck): | ||
| """Check system performance metrics including CPU load and memory usage.""" | ||
|
|
||
| def run(self) -> CheckResult: | ||
| """Check system load and memory usage. | ||
|
|
||
| Returns: | ||
| CheckResult with performance score. | ||
| """ | ||
| score = 100 | ||
| issues = [] | ||
| rec = None | ||
|
|
||
| # 1. Load Average (1min) | ||
| try: | ||
| load1, _, _ = os.getloadavg() | ||
| cores = multiprocessing.cpu_count() | ||
| # Load ratio against core count | ||
| load_ratio = load1 / cores | ||
|
|
||
| if load_ratio > 1.0: | ||
| score -= 50 | ||
| issues.append(f"High Load ({load1:.2f})") | ||
| rec = "Check top processes" | ||
| except OSError: | ||
| pass # Skip on Windows etc. | ||
|
|
||
| # 2. Memory Usage (Linux /proc/meminfo) | ||
| try: | ||
| with open("/proc/meminfo") as f: | ||
| meminfo = {} | ||
| for line in f: | ||
| parts = line.split(":") | ||
| if len(parts) == 2: | ||
| meminfo[parts[0].strip()] = int(parts[1].strip().split()[0]) | ||
|
|
||
| if "MemTotal" in meminfo and "MemAvailable" in meminfo: | ||
| total = meminfo["MemTotal"] | ||
| avail = meminfo["MemAvailable"] | ||
| used_percent = ((total - avail) / total) * 100 | ||
|
|
||
| if used_percent > 80: | ||
| penalty = int(used_percent - 80) | ||
| score -= penalty | ||
| issues.append(f"High Memory ({used_percent:.0f}%)") | ||
| except FileNotFoundError: | ||
| pass # Non-Linux systems | ||
|
|
||
| # Summary of results | ||
| status = "OK" | ||
| if score < 50: | ||
| status = "CRITICAL" | ||
| elif score < 90: | ||
| status = "WARNING" | ||
|
|
||
| details = ", ".join(issues) if issues else "Optimal" | ||
|
|
||
| return CheckResult( | ||
| name="System Load", | ||
| category="performance", | ||
| score=max(0, score), | ||
| status=status, | ||
| details=details, | ||
| recommendation=rec, | ||
| weight=0.20, # 20% | ||
| ) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Fix duplicate import causing CI failure.
Lines 11-15 import
InstallationHistory,InstallationStatus,InstallationTypefromcortex.installation_history, but line 17 imports the same symbols again. This causes the Ruff I001 error (import block is unsorted/unformatted) and is blocking CI.🔎 Proposed fix
Remove the duplicate import on line 17:
from cortex.installation_history import ( InstallationHistory, InstallationStatus, InstallationType, ) from cortex.demo import run_demo -from cortex.installation_history import InstallationHistory, InstallationStatus, InstallationType from cortex.llm.interpreter import CommandInterpreter🧰 Tools
🪛 GitHub Check: Lint
[failure] 17-17: Ruff (F811)
cortex/cli.py:17:82: F811 Redefinition of unused
InstallationTypefrom line 14[failure] 17-17: Ruff (F811)
cortex/cli.py:17:62: F811 Redefinition of unused
InstallationStatusfrom line 13[failure] 17-17: Ruff (F811)
cortex/cli.py:17:41: F811 Redefinition of unused
InstallationHistoryfrom line 12🤖 Prompt for AI Agents