-
Notifications
You must be signed in to change notification settings - Fork 9
feat(dashboard): add second drive stat; add network speed card #15
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
Merged
yusing
merged 2 commits into
main
from
session/agent_d3afa5f0-1f17-41c8-bc77-79541d305293
Feb 28, 2026
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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
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
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 |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| import { useWebSocketApi } from '@/hooks/websocket' | ||
| import type { DiskUsageStat, MemVirtualMemoryStat, StatsResponse, SystemInfo } from '@/lib/api' | ||
| import { store } from './store' | ||
| import { formatBytes } from '@/lib/format' | ||
| import { store } from './store' | ||
|
|
||
| export default function SystemStatsProvider() { | ||
| useWebSocketApi<SystemInfo>({ | ||
|
|
@@ -15,8 +15,12 @@ export default function SystemStatsProvider() { | |
| cpuAverage: Math.round(data.cpu_average * 100) / 100, | ||
| rootPartitionUsage: Math.round(getDiskUsage(data.disks, '/') ?? 0 * 100), | ||
| rootPartitionUsageDesc: getDiskUsageDesc(data.disks, '/'), | ||
| secondaryPartitionUsage: Math.round(getSecondaryDiskUsage(data.disks, '/') ?? 0 * 100), | ||
| secondaryPartitionUsageDesc: getSecondaryDiskUsageDesc(data.disks, '/'), | ||
| memoryUsage: Math.round(data.memory.used_percent * 100) / 100, | ||
| memoryUsageDesc: getMemoryUsageDesc(data.memory), | ||
| networkSpeedUpload: data.network?.upload_speed ?? 0, | ||
| networkSpeedDownload: data.network?.download_speed ?? 0, | ||
| }), | ||
| }) | ||
|
|
||
|
|
@@ -44,6 +48,42 @@ function getDiskUsageDesc(disks: Record<string, DiskUsageStat>, path: string) { | |
| return `${formatBytes(disk.used, { precision: 1 })} / ${formatBytes(disk.total, { precision: 1 })}` | ||
| } | ||
|
|
||
| function getSecondaryDisk(disks: Record<string, DiskUsageStat>, path: string) { | ||
| const allDisks = Object.values(disks) | ||
| const primaryDisk = getDisk(disks, path) | ||
| if (!primaryDisk) { | ||
| return undefined | ||
| } | ||
| return allDisks.find(d => !isSameDisk(d, primaryDisk)) | ||
| } | ||
|
|
||
| function isSameDisk(disk: DiskUsageStat, otherDisk: DiskUsageStat) { | ||
| if (disk.path === otherDisk.path) { | ||
| return true | ||
| } | ||
| if ( | ||
| disk.fstype === otherDisk.fstype && | ||
| disk.total === otherDisk.total && | ||
| disk.used === otherDisk.used | ||
| ) { | ||
| return true | ||
| } | ||
| return false | ||
| } | ||
|
Comment on lines
+60
to
+72
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fragile comparison: Comparing 🛡️ Proposed fix using stable properties only function isSameDisk(disk: DiskUsageStat, otherDisk: DiskUsageStat) {
if (disk.path === otherDisk.path) {
return true
}
- if (
- disk.fstype === otherDisk.fstype &&
- disk.total === otherDisk.total &&
- disk.used === otherDisk.used
- ) {
+ // Same filesystem type and total size likely indicates same physical disk
+ // (e.g., different mount points on the same partition)
+ if (disk.fstype === otherDisk.fstype && disk.total === otherDisk.total) {
return true
}
return false
}🤖 Prompt for AI Agents |
||
|
|
||
| function getSecondaryDiskUsage(disks: Record<string, DiskUsageStat>, path: string) { | ||
| return getSecondaryDisk(disks, path)?.used_percent | ||
| } | ||
|
|
||
| function getSecondaryDiskUsageDesc(disks: Record<string, DiskUsageStat>, path: string) { | ||
| const disk = getSecondaryDisk(disks, path) | ||
| if (!disk) { | ||
| return '' | ||
| } | ||
| const key = Object.entries(disks).find(([_, d]) => Object.is(d, disk))?.[0] | ||
| return `${key}: ${formatBytes(disk.used, { precision: 1 })} / ${formatBytes(disk.total, { precision: 1 })}` | ||
| } | ||
|
|
||
| function getMemoryUsageDesc(memory: MemVirtualMemoryStat) { | ||
| return `${formatBytes(memory.used, { precision: 1 })} / ${formatBytes(memory.total, { precision: 1 })}` | ||
| } | ||
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
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.
Operator precedence bug:
* 100is never applied.Due to operator precedence,
getDiskUsage(data.disks, '/') ?? 0 * 100evaluates asgetDiskUsage(...) ?? (0 * 100)which equalsgetDiskUsage(...) ?? 0. The multiplication is only applied to the fallback0, not to the disk usage value.If
used_percentfromDiskUsageStatis already 0-100, remove* 100. If it's 0-1, add parentheses.🐛 Proposed fix (assuming used_percent is already 0-100)
📝 Committable suggestion
🤖 Prompt for AI Agents