cleanup
This commit is contained in:
1 parent
8470631162
commit
ea115ede53
19 files changed
+10
-997
No files matched your search
@@ -0,0 +1,50 @@
|
||||
import Stack from "@mui/material/Stack";
|
||||
import { StatBox } from "@/Components/v2/design-elements";
|
||||
|
||||
import { useTheme } from "@mui/material";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import type { QueueMetrics } from "@/Types/Queue";
|
||||
|
||||
interface MetricsProps {
|
||||
metrics: QueueMetrics | null;
|
||||
}
|
||||
|
||||
export const Metrics = ({ metrics }: MetricsProps) => {
|
||||
const { t } = useTranslation();
|
||||
const theme = useTheme();
|
||||
|
||||
if (!metrics) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<Stack
|
||||
direction={{ xs: "column", md: "row" }}
|
||||
gap={theme.spacing(8)}
|
||||
>
|
||||
<StatBox
|
||||
title={t("pages.logs.metrics.jobs")}
|
||||
subtitle={String(metrics.jobs)}
|
||||
/>
|
||||
<StatBox
|
||||
palette={metrics.activeJobs > 0 ? "success" : undefined}
|
||||
title={t("pages.logs.metrics.activeJobs")}
|
||||
subtitle={String(metrics.activeJobs)}
|
||||
/>
|
||||
<StatBox
|
||||
palette={metrics.failingJobs > 0 ? "error" : undefined}
|
||||
title={t("pages.logs.metrics.failingJobs")}
|
||||
subtitle={String(metrics.failingJobs)}
|
||||
/>
|
||||
<StatBox
|
||||
title={t("pages.logs.metrics.totalRuns")}
|
||||
subtitle={String(metrics.totalRuns)}
|
||||
/>
|
||||
<StatBox
|
||||
palette={metrics.totalFailures > 0 ? "error" : undefined}
|
||||
title={t("pages.logs.metrics.totalFailures")}
|
||||
subtitle={String(metrics.totalFailures)}
|
||||
/>
|
||||
</Stack>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,84 @@
|
||||
import Stack from "@mui/material/Stack";
|
||||
import { DetailGauge } from "@/Components/v2/design-elements";
|
||||
|
||||
import prettyBytes from "pretty-bytes";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { useTheme } from "@mui/material";
|
||||
import type { Diagnostics } from "@/Types/Diagnostics";
|
||||
|
||||
interface StatGaugesProps {
|
||||
diagnostics: Diagnostics | null;
|
||||
}
|
||||
|
||||
const getPercentage = (value: number, total: number) => {
|
||||
if (!value || !total) return 0;
|
||||
return (value / total) * 100;
|
||||
};
|
||||
|
||||
const formatPercentage = new Intl.NumberFormat("en-US", {
|
||||
style: "percent",
|
||||
minimumFractionDigits: 1,
|
||||
maximumFractionDigits: 1,
|
||||
});
|
||||
|
||||
export const StatGauges = ({ diagnostics }: StatGaugesProps) => {
|
||||
const theme = useTheme();
|
||||
const { t } = useTranslation();
|
||||
if (!diagnostics) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const heapTotalSize = getPercentage(
|
||||
diagnostics?.v8HeapStats?.totalHeapSizeBytes,
|
||||
diagnostics?.v8HeapStats?.heapSizeLimitBytes
|
||||
);
|
||||
|
||||
const heapUsedSize = getPercentage(
|
||||
diagnostics?.v8HeapStats?.usedHeapSizeBytes,
|
||||
diagnostics?.v8HeapStats?.heapSizeLimitBytes
|
||||
);
|
||||
|
||||
const actualHeapUsed = getPercentage(
|
||||
diagnostics?.v8HeapStats?.usedHeapSizeBytes,
|
||||
diagnostics?.v8HeapStats?.totalHeapSizeBytes
|
||||
);
|
||||
|
||||
return (
|
||||
<Stack
|
||||
direction={{ xs: "column", md: "row" }}
|
||||
gap={theme.spacing(8)}
|
||||
>
|
||||
<DetailGauge
|
||||
title={t("pages.logs.diagnostics.gauges.heapAllocation")}
|
||||
progress={heapTotalSize}
|
||||
upperValue={formatPercentage.format(heapTotalSize / 100)}
|
||||
lowerLabel={t("pages.logs.diagnostics.gauges.total")}
|
||||
lowerValue={prettyBytes(diagnostics.v8HeapStats?.heapSizeLimitBytes ?? 0)}
|
||||
/>
|
||||
<DetailGauge
|
||||
title={t("pages.logs.diagnostics.gauges.heapUsage")}
|
||||
progress={heapUsedSize}
|
||||
upperLabel={t("pages.logs.diagnostics.gauges.availableMemoryPercentage")}
|
||||
upperValue={formatPercentage.format(heapUsedSize / 100)}
|
||||
lowerLabel={t("pages.logs.diagnostics.gauges.used")}
|
||||
lowerValue={prettyBytes(diagnostics.v8HeapStats?.usedHeapSizeBytes ?? 0)}
|
||||
/>
|
||||
<DetailGauge
|
||||
title={t("pages.logs.diagnostics.gauges.heapUtilization")}
|
||||
progress={actualHeapUsed}
|
||||
upperLabel={t("pages.logs.diagnostics.gauges.allocatedPercentage")}
|
||||
upperValue={formatPercentage.format(actualHeapUsed / 100)}
|
||||
lowerLabel={t("pages.logs.diagnostics.gauges.total")}
|
||||
lowerValue={prettyBytes(diagnostics.v8HeapStats?.usedHeapSizeBytes ?? 0)}
|
||||
/>
|
||||
<DetailGauge
|
||||
title={t("pages.logs.diagnostics.gauges.instantCpuUsage")}
|
||||
progress={diagnostics.cpuUsage?.usagePercentage ?? 0}
|
||||
upperLabel={t("pages.logs.diagnostics.gauges.usedSPercentage")}
|
||||
upperValue={formatPercentage.format(
|
||||
(diagnostics.cpuUsage?.usagePercentage ?? 0) / 100
|
||||
)}
|
||||
/>
|
||||
</Stack>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,51 @@
|
||||
import Stack from "@mui/material/Stack";
|
||||
import { StatBox } from "@/Components/v2/design-elements";
|
||||
|
||||
import prettyBytes from "pretty-bytes";
|
||||
import prettyMilliseconds from "pretty-ms";
|
||||
import { useTheme } from "@mui/material";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import type { Diagnostics } from "@/Types/Diagnostics";
|
||||
|
||||
interface StatsProps {
|
||||
diagnostics: Diagnostics | null;
|
||||
}
|
||||
|
||||
export const Stats = ({ diagnostics }: StatsProps) => {
|
||||
const { t } = useTranslation();
|
||||
const theme = useTheme();
|
||||
|
||||
if (!diagnostics) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<Stack
|
||||
direction={{ xs: "column", md: "row" }}
|
||||
gap={theme.spacing(8)}
|
||||
>
|
||||
<StatBox
|
||||
title={t("pages.logs.diagnostics.stats.eventLoopDelay")}
|
||||
subtitle={prettyMilliseconds(diagnostics.eventLoopDelayMs ?? 0, {
|
||||
millisecondsDecimalDigits: 2,
|
||||
})}
|
||||
/>
|
||||
<StatBox
|
||||
title={t("pages.logs.diagnostics.stats.uptime")}
|
||||
subtitle={prettyMilliseconds(diagnostics.uptimeMs ?? 0, { hideSeconds: true })}
|
||||
/>
|
||||
<StatBox
|
||||
title={t("pages.logs.diagnostics.stats.usedHeapSize")}
|
||||
subtitle={prettyBytes(diagnostics.v8HeapStats?.usedHeapSizeBytes ?? 0)}
|
||||
/>
|
||||
<StatBox
|
||||
title={t("pages.logs.diagnostics.stats.totalHeapSize")}
|
||||
subtitle={prettyBytes(diagnostics.v8HeapStats?.totalHeapSizeBytes ?? 0)}
|
||||
/>
|
||||
<StatBox
|
||||
title={t("pages.logs.diagnostics.stats.osMemoryLimit")}
|
||||
subtitle={prettyBytes(diagnostics.osStats?.totalMemoryBytes ?? 0)}
|
||||
/>
|
||||
</Stack>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,164 @@
|
||||
import { Table } from "@/Components/v2/design-elements";
|
||||
import { Typography, useTheme } from "@mui/material";
|
||||
import prettyMilliseconds from "pretty-ms";
|
||||
import { formatTimestamp } from "@/Utils/TimeUtils";
|
||||
|
||||
import { useTranslation } from "react-i18next";
|
||||
import type { QueueJobFailure, QueueJobSummary, QueueMetrics } from "@/Types/Queue";
|
||||
import type { Header } from "@/Components/v2/design-elements";
|
||||
|
||||
type QueueJobWithId = QueueJobSummary & { id: string | number };
|
||||
|
||||
interface TableJobsProps {
|
||||
jobs: QueueJobSummary[];
|
||||
}
|
||||
|
||||
export const TableJobs = ({ jobs }: TableJobsProps) => {
|
||||
const { t } = useTranslation();
|
||||
const theme = useTheme();
|
||||
|
||||
const jobsWithId: QueueJobWithId[] = jobs.map((job) => ({
|
||||
...job,
|
||||
id: job.monitorId,
|
||||
}));
|
||||
|
||||
const headers: Header<QueueJobWithId>[] = [
|
||||
{
|
||||
id: "id",
|
||||
content: t("common.table.headers.monitorId"),
|
||||
render: (row) => <Typography fontFamily={"monospace"}>{row.monitorId}</Typography>,
|
||||
},
|
||||
{
|
||||
id: "url",
|
||||
content: t("common.table.headers.url"),
|
||||
render: (row) => <Typography>{row.monitorUrl}</Typography>,
|
||||
},
|
||||
{
|
||||
id: "interval",
|
||||
content: t("common.table.headers.interval"),
|
||||
render: (row) => (
|
||||
<Typography>{prettyMilliseconds(row.monitorInterval ?? 0)}</Typography>
|
||||
),
|
||||
},
|
||||
{
|
||||
id: "type",
|
||||
content: t("common.table.headers.type"),
|
||||
render: (row) => <Typography>{row.monitorType}</Typography>,
|
||||
},
|
||||
{
|
||||
id: "active",
|
||||
content: t("common.table.headers.active"),
|
||||
render: (row) => <Typography>{row.active.toString()}</Typography>,
|
||||
},
|
||||
{
|
||||
id: "runCount",
|
||||
content: t("pages.logs.table.headers.runCount"),
|
||||
render: (row) => <Typography>{row.runCount}</Typography>,
|
||||
},
|
||||
{
|
||||
id: "failCount",
|
||||
content: t("pages.logs.table.headers.failCount"),
|
||||
render: (row) => <Typography>{row.failCount}</Typography>,
|
||||
},
|
||||
{
|
||||
id: "lastRun",
|
||||
content: t("pages.logs.table.headers.lastRunAt"),
|
||||
render: (row) => <Typography>{formatTimestamp(row.lastRunAt)}</Typography>,
|
||||
},
|
||||
{
|
||||
id: "lockedAt",
|
||||
content: t("pages.logs.table.headers.lockedAt"),
|
||||
render: (row) => <Typography>{formatTimestamp(row.lockedAt)}</Typography>,
|
||||
},
|
||||
|
||||
{
|
||||
id: "lastFinish",
|
||||
content: t("pages.logs.table.headers.lastFinishedAt"),
|
||||
render: (row) => <Typography>{formatTimestamp(row.lastFinishedAt)}</Typography>,
|
||||
},
|
||||
{
|
||||
id: "lastRunTook",
|
||||
content: t("pages.logs.table.headers.lastRunTook"),
|
||||
render: (row) => {
|
||||
const value = row.lastRunTook ? prettyMilliseconds(row.lastRunTook) : "-";
|
||||
return <Typography>{value}</Typography>;
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<Table
|
||||
headers={headers}
|
||||
data={jobsWithId}
|
||||
getRowSx={(row) => ({
|
||||
...(row.lockedAt && {
|
||||
"& td": { backgroundColor: theme.palette.success.light },
|
||||
}),
|
||||
})}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
type QueueJobFailureWithId = QueueJobFailure & { id: string | number };
|
||||
|
||||
interface TableFailedJobsProps {
|
||||
metrics: QueueMetrics | null;
|
||||
}
|
||||
export const TableFailedJobs = ({ metrics }: TableFailedJobsProps) => {
|
||||
const { t } = useTranslation();
|
||||
if (!metrics) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const jobFailuresWithId: QueueJobFailureWithId[] = metrics.jobsWithFailures.map(
|
||||
(job) => ({
|
||||
...job,
|
||||
id: job.monitorId,
|
||||
})
|
||||
);
|
||||
|
||||
const headers: Header<QueueJobFailureWithId>[] = [
|
||||
{
|
||||
id: "monitorId",
|
||||
content: t("common.table.headers.monitorId"),
|
||||
render: (row) => {
|
||||
return <Typography fontFamily={"monospace"}>{row.monitorId}</Typography>;
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "monitorUrl",
|
||||
content: t("common.table.headers.url"),
|
||||
render: (row) => {
|
||||
return <Typography>{row.monitorUrl}</Typography>;
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "failCount",
|
||||
content: t("pages.logs.table.headers.failCount"),
|
||||
render: (row) => {
|
||||
return <Typography>{row.failCount}</Typography>;
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "failedAt",
|
||||
content: t("pages.logs.table.headers.lastFailedAt"),
|
||||
render: (row) => {
|
||||
return <Typography>{formatTimestamp(row.failedAt)}</Typography>;
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "failReason",
|
||||
content: t("pages.logs.table.headers.failReason"),
|
||||
render: (row) => {
|
||||
return <Typography>{row.failReason}</Typography>;
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<Table
|
||||
headers={headers}
|
||||
data={jobFailuresWithId}
|
||||
/>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,128 @@
|
||||
import Box from "@mui/material/Box";
|
||||
import Typography from "@mui/material/Typography";
|
||||
import { Table } from "@/Components/v2/design-elements";
|
||||
import { Pagination } from "@/Components/v2/design-elements/Table";
|
||||
import { useTheme } from "@mui/material";
|
||||
import type { Header } from "@/Components/v2/design-elements/Table";
|
||||
import type { Log, LogLevel } from "@/Types/Log";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { useSelector, useDispatch } from "react-redux";
|
||||
import type { RootState } from "@/Types/state";
|
||||
import { setRowsPerPage } from "@/Features/UI/uiSlice";
|
||||
import { formatTimestamp } from "@/Utils/TimeUtils";
|
||||
|
||||
type LogWithId = Log & { id: number };
|
||||
|
||||
interface TableLogsProps {
|
||||
logs: LogWithId[];
|
||||
logCount: number;
|
||||
page: number;
|
||||
setPage: (page: number) => void;
|
||||
}
|
||||
|
||||
const LevelBadge = ({ level }: { level: LogLevel }) => {
|
||||
const theme = useTheme();
|
||||
|
||||
const levelColors: Record<LogLevel, string> = {
|
||||
info: theme.palette.success.main,
|
||||
warn: theme.palette.warning.main,
|
||||
error: theme.palette.error.main,
|
||||
debug: theme.palette.info.main,
|
||||
};
|
||||
|
||||
const color = levelColors[level] || theme.palette.text.primary;
|
||||
|
||||
return (
|
||||
<Typography
|
||||
fontWeight={600}
|
||||
color={color}
|
||||
textTransform={"uppercase"}
|
||||
>
|
||||
{level}
|
||||
</Typography>
|
||||
);
|
||||
};
|
||||
|
||||
export const TableLogs = ({ logs, logCount, page, setPage }: TableLogsProps) => {
|
||||
const { t } = useTranslation();
|
||||
const dispatch = useDispatch();
|
||||
const rowsPerPage = useSelector(
|
||||
(state: RootState) => state?.ui?.logs?.rowsPerPage ?? 15
|
||||
);
|
||||
|
||||
const headers: Header<Log & { id: number }>[] = [
|
||||
{
|
||||
id: "timestamp",
|
||||
content: t("pages.logs.table.headers.timestamp"),
|
||||
render: (row) => (
|
||||
<Typography sx={{ fontFamily: "monospace" }}>
|
||||
{formatTimestamp(row.timestamp)}
|
||||
</Typography>
|
||||
),
|
||||
},
|
||||
{
|
||||
id: "level",
|
||||
content: t("pages.logs.table.headers.level"),
|
||||
render: (row) => <LevelBadge level={row.level} />,
|
||||
},
|
||||
{
|
||||
id: "service",
|
||||
content: t("pages.logs.table.headers.service"),
|
||||
render: (row) => <Typography>{row.service || "-"}</Typography>,
|
||||
},
|
||||
{
|
||||
id: "method",
|
||||
content: t("pages.logs.table.headers.method"),
|
||||
render: (row) => (
|
||||
<Typography fontFamily={"monospace"}>{row.method || "-"}</Typography>
|
||||
),
|
||||
},
|
||||
{
|
||||
id: "message",
|
||||
content: t("common.table.headers.message"),
|
||||
render: (row) => (
|
||||
<Typography
|
||||
maxWidth={400}
|
||||
overflow={"hidden"}
|
||||
textOverflow={"ellipsis"}
|
||||
whiteSpace={"nowrap"}
|
||||
>
|
||||
{row.message || "-"}
|
||||
</Typography>
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
const handlePageChange = (
|
||||
_e: React.MouseEvent<HTMLButtonElement> | null,
|
||||
newPage: number
|
||||
) => {
|
||||
setPage(newPage);
|
||||
};
|
||||
|
||||
const handleRowsPerPageChange = (
|
||||
e: React.ChangeEvent<HTMLTextAreaElement | HTMLInputElement>
|
||||
) => {
|
||||
dispatch(setRowsPerPage({ value: Number(e.target.value), table: "logs" }));
|
||||
setPage(0);
|
||||
};
|
||||
|
||||
return (
|
||||
<Box>
|
||||
<Table
|
||||
headers={headers}
|
||||
data={logs}
|
||||
emptyViewText={t("pages.logs.noLogs")}
|
||||
/>
|
||||
<Pagination
|
||||
itemsOnPage={logs.length}
|
||||
component="div"
|
||||
count={logCount}
|
||||
page={page}
|
||||
rowsPerPage={rowsPerPage}
|
||||
onPageChange={handlePageChange}
|
||||
onRowsPerPageChange={handleRowsPerPageChange}
|
||||
/>
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
Reference in new issue
Block a user