Skip to content

Commit 2b52fc0

Browse files
refactor(web): report service ping memory/disk stats in MiB
Report the systemInfo memory and disk fields in whole MiB (binary, 1024-based units) instead of raw bytes, so the values are directly human-readable when diagnosing resource issues (e.g. a 16Gi container limit reads as 16384). Converts at the collection boundary via a bytesToMiB helper and updates the mirrored docs. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 6f7caaf commit 2b52fc0

3 files changed

Lines changed: 33 additions & 27 deletions

File tree

docs/docs/misc/service-ping.mdx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ The `systemInfo` object contains a best-effort snapshot of the resources the dep
3636
| `cpuCores` | `integer` | Number of logical CPU cores visible to the host. |
3737
| `cpuQuota` | `number \| null` | Effective cgroup CPU limit in cores, or `null` if unlimited. |
3838
| `loadAverage1m` | `number \| null` | 1-minute load average. |
39-
| `totalMemoryBytes` | `integer` | Total host memory, in bytes. |
40-
| `freeMemoryBytes` | `integer` | Free host memory, in bytes. |
41-
| `memoryLimitBytes` | `integer \| null` | cgroup memory limit in bytes, or `null` if unlimited. |
42-
| `memoryUsedBytes` | `integer \| null` | Current cgroup memory usage, in bytes. |
43-
| `diskTotalBytes` | `integer \| null` | Total disk space for the data volume, in bytes. |
44-
| `diskFreeBytes` | `integer \| null` | Free disk space for the data volume, in bytes. |
39+
| `totalMemoryMiB` | `number` | Total host memory, in MiB. |
40+
| `freeMemoryMiB` | `number` | Free host memory, in MiB. |
41+
| `memoryLimitMiB` | `number \| null` | cgroup memory limit in MiB, or `null` if unlimited. |
42+
| `memoryUsedMiB` | `number \| null` | Current cgroup memory usage, in MiB. |
43+
| `diskTotalMiB` | `number \| null` | Total disk space for the data volume, in MiB. |
44+
| `diskFreeMiB` | `number \| null` | Free disk space for the data volume, in MiB. |
4545

4646

4747
You can fetch the schema for the Service Ping by submitting a GET request to `https://deployments.sourcebot.dev/schema`
@@ -82,12 +82,12 @@ body: {
8282
"cpuCores": 8,
8383
"cpuQuota": 4,
8484
"loadAverage1m": 1.24,
85-
"totalMemoryBytes": 16777216000,
86-
"freeMemoryBytes": 4194304000,
87-
"memoryLimitBytes": 8589934592,
88-
"memoryUsedBytes": 3221225472,
89-
"diskTotalBytes": 107374182400,
90-
"diskFreeBytes": 53687091200
85+
"totalMemoryMiB": 16000,
86+
"freeMemoryMiB": 4000,
87+
"memoryLimitMiB": 8192,
88+
"memoryUsedMiB": 3072,
89+
"diskTotalMiB": 102400,
90+
"diskFreeMiB": 54968
9191
},
9292
"activationCode": "sb_act_3a925f51...."
9393
}

packages/web/src/features/billing/systemInfo.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,21 @@ export const getSystemInfo = async (): Promise<SystemInfo> => {
4242
cpuQuota,
4343
// os.loadavg() returns [0, 0, 0] on unsupported platforms (e.g. Windows).
4444
loadAverage1m: os.platform() === 'win32' ? null : os.loadavg()[0],
45-
totalMemoryBytes: os.totalmem(),
46-
freeMemoryBytes: os.freemem(),
47-
memoryLimitBytes,
48-
memoryUsedBytes,
49-
diskTotalBytes: disk.totalBytes,
50-
diskFreeBytes: disk.freeBytes,
45+
totalMemoryMiB: bytesToMiB(os.totalmem()),
46+
freeMemoryMiB: bytesToMiB(os.freemem()),
47+
memoryLimitMiB: memoryLimitBytes === null ? null : bytesToMiB(memoryLimitBytes),
48+
memoryUsedMiB: memoryUsedBytes === null ? null : bytesToMiB(memoryUsedBytes),
49+
diskTotalMiB: disk.totalBytes === null ? null : bytesToMiB(disk.totalBytes),
50+
diskFreeMiB: disk.freeBytes === null ? null : bytesToMiB(disk.freeBytes),
5151
};
5252
};
5353

54+
const BYTES_PER_MIB = 1024 * 1024;
55+
56+
// Memory and disk are both reported in whole MiB (binary, 1024-based units),
57+
// matching how RAM and container/k8s volumes are sized.
58+
const bytesToMiB = (bytes: number): number => Math.round(bytes / BYTES_PER_MIB);
59+
5460
const readFileTrimmed = async (path: string): Promise<string | null> => {
5561
try {
5662
const contents = await fs.readFile(path, 'utf8');

packages/web/src/features/billing/types.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@ export const systemInfoSchema = z.object({
1717
cpuQuota: z.number().nonnegative().nullable(),
1818
loadAverage1m: z.number().nonnegative().nullable(),
1919

20-
// Memory, in bytes. `total`/`free` are host-level (os.totalmem / os.freemem);
20+
// Memory, in MiB. `total`/`free` are host-level (os.totalmem / os.freemem);
2121
// `limit`/`used` come from the cgroup and reflect the container's actual RAM
2222
// allocation and current usage (null when unset or unreadable).
23-
totalMemoryBytes: z.number().nonnegative(),
24-
freeMemoryBytes: z.number().nonnegative(),
25-
memoryLimitBytes: z.number().nonnegative().nullable(),
26-
memoryUsedBytes: z.number().nonnegative().nullable(),
27-
28-
// Disk, in bytes, for the DATA_CACHE_DIR volume (where repos are indexed).
29-
diskTotalBytes: z.number().nonnegative().nullable(),
30-
diskFreeBytes: z.number().nonnegative().nullable(),
23+
totalMemoryMiB: z.number().nonnegative(),
24+
freeMemoryMiB: z.number().nonnegative(),
25+
memoryLimitMiB: z.number().nonnegative().nullable(),
26+
memoryUsedMiB: z.number().nonnegative().nullable(),
27+
28+
// Disk, in MiB, for the DATA_CACHE_DIR volume (where repos are indexed).
29+
diskTotalMiB: z.number().nonnegative().nullable(),
30+
diskFreeMiB: z.number().nonnegative().nullable(),
3131
});
3232
export type SystemInfo = z.infer<typeof systemInfoSchema>;
3333

0 commit comments

Comments
 (0)