mirror of
https://github.com/louislam/dockge.git
synced 2026-05-21 14:02:17 +00:00
Add resource usage stats to the compose page (#700)
Co-authored-by: cmcooper1980 <31871143+cmcooper1980@users.noreply.github.com>
This commit is contained in:
@@ -637,6 +637,35 @@ export class DockgeServer {
|
||||
return list;
|
||||
}
|
||||
|
||||
async getDockerStats() : Promise<Map<string, object>> {
|
||||
let stats = new Map<string, object>();
|
||||
|
||||
try {
|
||||
let res = await childProcessAsync.spawn("docker", [ "stats", "--format", "json", "--no-stream" ], {
|
||||
encoding: "utf-8",
|
||||
});
|
||||
|
||||
if (!res.stdout) {
|
||||
return stats;
|
||||
}
|
||||
|
||||
let lines = res.stdout?.toString().split("\n");
|
||||
|
||||
for (let line of lines) {
|
||||
try {
|
||||
let obj = JSON.parse(line);
|
||||
stats.set(obj.Name, obj);
|
||||
} catch (e) {
|
||||
}
|
||||
}
|
||||
|
||||
return stats;
|
||||
} catch (e) {
|
||||
log.error("getDockerStats", e);
|
||||
return stats;
|
||||
}
|
||||
}
|
||||
|
||||
get stackDirFullPath() {
|
||||
return path.resolve(this.stacksDir);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user