Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,17 @@ import { api } from "@/utils/api";

interface Props {
appName: string;
serverId?: string;
}

export const ShowNomadAllocations = ({ appName }: Props) => {
export const ShowNomadAllocations = ({ appName, serverId }: Props) => {
const {
data: allocs,
isLoading,
isError,
refetch,
} = api.nomad.getJobAllocations.useQuery(
{ jobId: appName },
{ jobId: appName, serverId },
{ enabled: !!appName, refetchInterval: 10000 },
);

Expand Down Expand Up @@ -69,14 +70,20 @@ export const ShowNomadAllocations = ({ appName }: Props) => {
</p>
)}
{allocs?.map((alloc: any) => (
<AllocationRow key={alloc.ID} alloc={alloc} />
<AllocationRow key={alloc.ID} alloc={alloc} serverId={serverId} />
))}
</CardContent>
</Card>
);
};

const AllocationRow = ({ alloc }: { alloc: any }) => {
const AllocationRow = ({
alloc,
serverId,
}: {
alloc: any;
serverId?: string;
}) => {
const [open, setOpen] = useState(false);
const [logType, setLogType] = useState<"stdout" | "stderr">("stdout");

Expand Down Expand Up @@ -122,6 +129,7 @@ const AllocationRow = ({ alloc }: { alloc: any }) => {
allocId={alloc.ID}
taskName={taskName}
logType={logType}
serverId={serverId}
/>
</div>
)}
Expand All @@ -135,16 +143,21 @@ const AllocLogViewer = ({
allocId,
taskName,
logType,
serverId,
}: {
allocId: string;
taskName: string;
logType: "stdout" | "stderr";
serverId?: string;
}) => {
const { data: logs, isLoading, refetch } =
api.nomad.getAllocationLogs.useQuery(
{ allocId, taskName, logType },
{ refetchInterval: 5000 },
);
const {
data: logs,
isLoading,
refetch,
} = api.nomad.getAllocationLogs.useQuery(
{ allocId, taskName, logType, serverId },
{ refetchInterval: 5000 },
);

return (
<div className="relative">
Expand Down
52 changes: 41 additions & 11 deletions apps/dokploy/components/dashboard/nomad/jobs/show-nomad-jobs.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { AlertTriangle, Loader2, Play, RefreshCw, Square, Trash2 } from "lucide-react";
import {
AlertTriangle,
Loader2,
Play,
RefreshCw,
Square,
Trash2,
} from "lucide-react";
import { useState } from "react";
import { toast } from "sonner";
import { Alert, AlertDescription } from "@/components/ui/alert";
Expand Down Expand Up @@ -26,13 +33,13 @@ import {
} from "@/components/ui/table";
import { api } from "@/utils/api";

export const ShowNomadJobs = () => {
export const ShowNomadJobs = ({ serverId }: { serverId?: string }) => {
const {
data: jobs,
isLoading,
isError,
refetch,
} = api.nomad.getJobs.useQuery();
} = api.nomad.getJobs.useQuery({ serverId });

const stopJob = api.nomad.stopJob.useMutation({
onSuccess: () => {
Expand Down Expand Up @@ -95,7 +102,9 @@ export const ShowNomadJobs = () => {
Object.entries(job.JobSummary.Summary).map(
([group, summary]: [string, any]) => (
<div key={group} className="text-sm">
{group}: {summary.Running}/{summary.Running + summary.Starting + summary.Queued} running
{group}: {summary.Running}/
{summary.Running + summary.Starting + summary.Queued}{" "}
running
</div>
),
)}
Expand All @@ -110,15 +119,24 @@ export const ShowNomadJobs = () => {
</AlertDialogTrigger>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>Stop job "{job.Name}"?</AlertDialogTitle>
<AlertDialogTitle>
Stop job "{job.Name}"?
</AlertDialogTitle>
<AlertDialogDescription>
This will stop all allocations for this job. You can restart it later.
This will stop all allocations for this job. You can
restart it later.
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>Cancel</AlertDialogCancel>
<AlertDialogAction
onClick={() => stopJob.mutate({ jobId: job.ID, purge: false })}
onClick={() =>
stopJob.mutate({
jobId: job.ID,
purge: false,
serverId,
})
}
>
Stop
</AlertDialogAction>
Expand All @@ -134,16 +152,25 @@ export const ShowNomadJobs = () => {
</AlertDialogTrigger>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>Purge job "{job.Name}"?</AlertDialogTitle>
<AlertDialogTitle>
Purge job "{job.Name}"?
</AlertDialogTitle>
<AlertDialogDescription>
This will permanently remove the job and all its history. This cannot be undone.
This will permanently remove the job and all its
history. This cannot be undone.
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>Cancel</AlertDialogCancel>
<AlertDialogAction
className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
onClick={() => stopJob.mutate({ jobId: job.ID, purge: true })}
onClick={() =>
stopJob.mutate({
jobId: job.ID,
purge: true,
serverId,
})
}
>
Purge
</AlertDialogAction>
Expand All @@ -156,7 +183,10 @@ export const ShowNomadJobs = () => {
))}
{(!jobs || jobs.length === 0) && (
<TableRow>
<TableCell colSpan={5} className="text-center text-muted-foreground">
<TableCell
colSpan={5}
className="text-center text-muted-foreground"
>
No jobs running
</TableCell>
</TableRow>
Expand Down
18 changes: 13 additions & 5 deletions apps/dokploy/components/dashboard/nomad/logs/show-nomad-logs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from "@/components/ui/select";
import { api } from "@/utils/api";

export const ShowNomadLogs = () => {
export const ShowNomadLogs = ({ serverId }: { serverId?: string }) => {
const [selectedAlloc, setSelectedAlloc] = useState<string | null>(null);
const [selectedTask, setSelectedTask] = useState<string>("");
const [logType, setLogType] = useState<"stdout" | "stderr">("stdout");
Expand All @@ -22,9 +22,10 @@ export const ShowNomadLogs = () => {
isLoading,
isError,
refetch,
} = api.nomad.getAllocations.useQuery();
} = api.nomad.getAllocations.useQuery({ serverId });

const runningAllocs = allocs?.filter((a: any) => a.ClientStatus === "running") || [];
const runningAllocs =
allocs?.filter((a: any) => a.ClientStatus === "running") || [];

const currentAlloc = runningAllocs.find((a: any) => a.ID === selectedAlloc);

Expand Down Expand Up @@ -92,6 +93,7 @@ export const ShowNomadLogs = () => {
allocId={selectedAlloc}
taskName={selectedTask}
logType={logType}
serverId={serverId}
/>
)}
</>
Expand All @@ -105,13 +107,19 @@ const LogViewer = ({
allocId,
taskName,
logType,
serverId,
}: {
allocId: string;
taskName: string;
logType: "stdout" | "stderr";
serverId?: string;
}) => {
const { data: logs, isLoading, refetch } = api.nomad.getAllocationLogs.useQuery(
{ allocId, taskName, logType },
const {
data: logs,
isLoading,
refetch,
} = api.nomad.getAllocationLogs.useQuery(
{ allocId, taskName, logType, serverId },
{ refetchInterval: 5000 },
);

Expand Down
55 changes: 38 additions & 17 deletions apps/dokploy/components/dashboard/nomad/nodes/show-nomad-nodes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,19 @@ import {
} from "@/components/ui/table";
import { api } from "@/utils/api";

export const ShowNomadNodes = () => {
export const ShowNomadNodes = ({ serverId }: { serverId?: string }) => {
const {
data: nodes,
isLoading,
isError,
refetch,
} = api.nomad.getNodes.useQuery();
} = api.nomad.getNodes.useQuery({ serverId });

const { data: resources } = api.nomad.getClusterResources.useQuery();
const { data: resources } = api.nomad.getClusterResources.useQuery({
serverId,
});

const { data: allocs } = api.nomad.getAllocations.useQuery();
const { data: allocs } = api.nomad.getAllocations.useQuery({ serverId });

if (isLoading) {
return (
Expand Down Expand Up @@ -67,18 +69,26 @@ export const ShowNomadNodes = () => {
</TableHeader>
<TableBody>
{nodes?.map((node: any) => {
const nodeAllocs = allocs?.filter(
(a: any) => a.NodeID === node.ID && a.ClientStatus === "running",
) || [];
const nodeAllocs =
allocs?.filter(
(a: any) =>
a.NodeID === node.ID && a.ClientStatus === "running",
) || [];

const cpuTotal = resources?.cpu.total || 1;
const memTotal = resources?.memory.total || 1;
const cpuPercent = cpuTotal > 0
? Math.round((resources?.cpu.allocated || 0) / cpuTotal * 100)
: 0;
const memPercent = memTotal > 0
? Math.round((resources?.memory.allocated || 0) / memTotal * 100)
: 0;
const cpuPercent =
cpuTotal > 0
? Math.round(
((resources?.cpu.allocated || 0) / cpuTotal) * 100,
)
: 0;
const memPercent =
memTotal > 0
? Math.round(
((resources?.memory.allocated || 0) / memTotal) * 100,
)
: 0;

return (
<TableRow key={node.ID}>
Expand All @@ -89,7 +99,11 @@ export const ShowNomadNodes = () => {
</div>
</TableCell>
<TableCell>
<Badge variant={node.Status === "ready" ? "default" : "destructive"}>
<Badge
variant={
node.Status === "ready" ? "default" : "destructive"
}
>
{node.Status}
</Badge>
</TableCell>
Expand All @@ -98,21 +112,28 @@ export const ShowNomadNodes = () => {
<TableCell>
<div className="flex items-center gap-2 min-w-[120px]">
<Progress value={cpuPercent} className="h-2 flex-1" />
<span className="text-xs text-muted-foreground w-8">{cpuPercent}%</span>
<span className="text-xs text-muted-foreground w-8">
{cpuPercent}%
</span>
</div>
</TableCell>
<TableCell>
<div className="flex items-center gap-2 min-w-[120px]">
<Progress value={memPercent} className="h-2 flex-1" />
<span className="text-xs text-muted-foreground w-8">{memPercent}%</span>
<span className="text-xs text-muted-foreground w-8">
{memPercent}%
</span>
</div>
</TableCell>
</TableRow>
);
})}
{(!nodes || nodes.length === 0) && (
<TableRow>
<TableCell colSpan={6} className="text-center text-muted-foreground">
<TableCell
colSpan={6}
className="text-center text-muted-foreground"
>
No nodes found
</TableCell>
</TableRow>
Expand Down
30 changes: 20 additions & 10 deletions apps/dokploy/components/dashboard/nomad/overview.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import { Cpu, HardDrive, Loader2, MemoryStick, Server, Container } from "lucide-react";
import {
Container,
Cpu,
HardDrive,
Loader2,
MemoryStick,
Server,
} from "lucide-react";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { Progress } from "@/components/ui/progress";
import { api } from "@/utils/api";

export const NomadOverview = () => {
export const NomadOverview = ({ serverId }: { serverId?: string }) => {
const { data, isLoading } = api.nomad.getClusterResources.useQuery(
undefined,
{ serverId },
{ refetchInterval: 10000 },
);

Expand All @@ -17,12 +24,14 @@ export const NomadOverview = () => {
);
}

const cpuPercent = data.cpu.total > 0
? Math.round((data.cpu.allocated / data.cpu.total) * 100)
: 0;
const memPercent = data.memory.total > 0
? Math.round((data.memory.allocated / data.memory.total) * 100)
: 0;
const cpuPercent =
data.cpu.total > 0
? Math.round((data.cpu.allocated / data.cpu.total) * 100)
: 0;
const memPercent =
data.memory.total > 0
? Math.round((data.memory.allocated / data.memory.total) * 100)
: 0;

return (
<div className="grid gap-4 md:grid-cols-2 lg:grid-cols-4">
Expand All @@ -49,7 +58,8 @@ export const NomadOverview = () => {
<div className="text-2xl font-bold">{memPercent}%</div>
<Progress value={memPercent} className="mt-2" />
<p className="text-xs text-muted-foreground mt-1">
{formatMB(data.memory.allocated)} / {formatMB(data.memory.total)} allocated
{formatMB(data.memory.allocated)} / {formatMB(data.memory.total)}{" "}
allocated
</p>
</CardContent>
</Card>
Expand Down
Loading
Loading