CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/comm/project-status/utils.ts
Views: 687
1
/*
2
* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
import type {
7
CGroup,
8
DiskUsageInfo,
9
} from "@cocalc/util/types/project-info/types";
10
11
// DiskUsage for /tmp !
12
export function cgroup_stats(cg: CGroup, du?: DiskUsageInfo) {
13
// why? /tmp is a memory disk in kucalc
14
const mem_rss = cg.mem_stat.total_rss + (du?.usage ?? 0);
15
const mem_tot = cg.mem_stat.hierarchical_memory_limit;
16
const mem_pct = 100 * Math.min(1, mem_rss / mem_tot);
17
const cpu_pct = 100 * Math.min(1, cg.cpu_usage_rate / cg.cpu_cores_limit);
18
const cpu_tot = cg.cpu_usage; // seconds
19
return { mem_rss, mem_tot, mem_pct, cpu_pct, cpu_tot };
20
}
21
22