Application status
This commit is contained in:
+2
-3
@@ -1,9 +1,8 @@
|
||||
"use server";
|
||||
|
||||
import axios from "axios";
|
||||
import { Docker, Node } from "@/lib/types";
|
||||
import { Docker, Node, SimpleStats } from "@/lib/types";
|
||||
import { verifySession } from "./auth/session";
|
||||
import { ContainerStats } from "dockerode";
|
||||
import { getNodes } from "./node";
|
||||
|
||||
export async function getDocker(nodes: Node[]): Promise<Docker[]> {
|
||||
@@ -24,7 +23,7 @@ export async function getDocker(nodes: Node[]): Promise<Docker[]> {
|
||||
|
||||
export async function getContainerStats(
|
||||
containerId: string
|
||||
): Promise<ContainerStats | undefined> {
|
||||
): Promise<SimpleStats | undefined> {
|
||||
const nodes = await getNodes();
|
||||
|
||||
return (
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
"use server";
|
||||
|
||||
import Docker from "dockerode";
|
||||
import Docker, { Container, ContainerStats } from "dockerode";
|
||||
import { randomUUID } from "crypto";
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
import { exec } from "child_process";
|
||||
import util from "util";
|
||||
import { ImageApp } from "@/lib/types";
|
||||
import { CPUusage } from "@/lib/server/calc";
|
||||
|
||||
const docker = new Docker();
|
||||
const execAsync = util.promisify(exec);
|
||||
@@ -42,6 +43,9 @@ export async function getApplications(): Promise<ImageApp[]> {
|
||||
|
||||
if (containerInfo.State === "running") {
|
||||
const stats = await container.stats({ stream: false });
|
||||
|
||||
totalMem += (stats.memory_stats.usage / stats.memory_stats.limit) * 100;
|
||||
totalCpu += CPUusage(stats);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,8 +66,8 @@ export async function getApplications(): Promise<ImageApp[]> {
|
||||
image: imageName,
|
||||
containers: relatedContainers.length,
|
||||
replicas: `${running}/${relatedContainers.length}`,
|
||||
cpu: Math.round(totalCpu),
|
||||
memory: Math.round(totalMem),
|
||||
cpu: totalCpu,
|
||||
memory: totalMem,
|
||||
network: "—",
|
||||
status: running > 0 ? ("running" as const) : ("stopped" as const),
|
||||
ports: [...ports],
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
"use server";
|
||||
|
||||
import Docker, { ContainerStats } from "dockerode";
|
||||
import { CPUusage } from "@/lib/server/calc";
|
||||
import { SimpleStats } from "@/lib/types";
|
||||
import Docker from "dockerode";
|
||||
|
||||
const docker = new Docker();
|
||||
|
||||
@@ -12,8 +14,13 @@ export async function getDocker() {
|
||||
|
||||
export async function getContainerStats(
|
||||
containerId: string
|
||||
): Promise<ContainerStats | undefined> {
|
||||
return await docker.getContainer(containerId).stats();
|
||||
): Promise<SimpleStats | undefined> {
|
||||
const stats = await docker.getContainer(containerId).stats({ stream: false });
|
||||
|
||||
return {
|
||||
cpu: CPUusage(stats),
|
||||
memory: (stats.memory_stats.usage / stats.memory_stats.limit) * 100,
|
||||
};
|
||||
}
|
||||
|
||||
export async function startContainer(containerId: string) {
|
||||
|
||||
Reference in New Issue
Block a user