initial commit
This commit is contained in:
1 parent
7cb985116e
commit
75acf7b38f
955 files changed
+37333
-87054
No files matched your search
@@ -0,0 +1,25 @@
|
||||
import Stack from "@mui/material/Stack";
|
||||
import Typography from "@mui/material/Typography";
|
||||
|
||||
import { useTheme, alpha } from "@mui/material/styles";
|
||||
import type { ILogEntry } from "@/types/log";
|
||||
|
||||
export const DiagnosticLogDetails = ({ logEntry }: { logEntry: ILogEntry }) => {
|
||||
const theme = useTheme();
|
||||
|
||||
return (
|
||||
<Stack
|
||||
bgcolor={alpha(theme.palette.error.main, 0.1)}
|
||||
sx={{
|
||||
p: theme.spacing(4),
|
||||
}}
|
||||
>
|
||||
<Typography variant="h2" textTransform={"capitalize"}>
|
||||
{"Stack trace"}
|
||||
</Typography>
|
||||
<Typography sx={{ wordBreak: "break-word", whiteSpace: "pre-wrap" }}>
|
||||
{logEntry.stack}{" "}
|
||||
</Typography>
|
||||
</Stack>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,38 @@
|
||||
import { BasePage, Tab, Tabs, InfoBox } from "@/components/design-elements";
|
||||
import { DiagnosticsLogTab } from "@/pages/diagnostic/DiagnosticsLogTab";
|
||||
import { DiagnosticsQueueTab } from "@/pages/diagnostic/DiagnosticsQueueTab";
|
||||
import { FileText, ListTodo } from "lucide-react";
|
||||
import { useState } from "react";
|
||||
|
||||
const DiagnosticPage = () => {
|
||||
const [tabValue, setTabValue] = useState("logs");
|
||||
|
||||
const handleTabChange = (_: React.SyntheticEvent, newValue: string) => {
|
||||
setTabValue(newValue);
|
||||
};
|
||||
|
||||
return (
|
||||
<BasePage>
|
||||
<InfoBox
|
||||
title="System Diagnostics"
|
||||
description="Review system logs and background job status to troubleshoot issues. Monitor the health of your monitoring infrastructure and investigate any problems."
|
||||
/>
|
||||
<Tabs value={tabValue} onChange={handleTabChange}>
|
||||
<Tab
|
||||
label="Logs"
|
||||
value="logs"
|
||||
icon={<FileText size={18} strokeWidth={1.5} />}
|
||||
/>
|
||||
<Tab
|
||||
label="Jobs"
|
||||
value="jobs"
|
||||
icon={<ListTodo size={18} strokeWidth={1.5} />}
|
||||
/>
|
||||
</Tabs>
|
||||
{tabValue === "logs" && <DiagnosticsLogTab />}
|
||||
{tabValue === "jobs" && <DiagnosticsQueueTab />}
|
||||
</BasePage>
|
||||
);
|
||||
};
|
||||
|
||||
export default DiagnosticPage;
|
||||
@@ -0,0 +1,103 @@
|
||||
import Stack from "@mui/material/Stack";
|
||||
import Typography from "@mui/material/Typography";
|
||||
import { Select } from "@/components/inputs";
|
||||
import MenuItem from "@mui/material/MenuItem";
|
||||
import { Table } from "@/components/design-elements";
|
||||
import type { Header } from "@/components/design-elements/Table";
|
||||
import { DiagnosticLogDetails } from "@/pages/diagnostic/DiagnosticLogDetails";
|
||||
|
||||
import { useState } from "react";
|
||||
import { useGet } from "@/hooks/UseApi";
|
||||
import { useTheme } from "@mui/material/styles";
|
||||
import type { ILogEntry } from "@/types/log";
|
||||
import type { ApiResponse } from "@/hooks/UseApi";
|
||||
|
||||
export const DiagnosticsLogTab = () => {
|
||||
const theme = useTheme();
|
||||
const [logLevel, setLogLevel] = useState("all");
|
||||
const { response } = useGet<ApiResponse<ILogEntry[]>>(
|
||||
`/diagnostic/logs`,
|
||||
{},
|
||||
{ refreshInterval: 5000 }
|
||||
);
|
||||
|
||||
const logEntries = response?.data || [];
|
||||
|
||||
const levelColors = {
|
||||
info: theme.palette.success.main,
|
||||
warn: theme.palette.warning.main,
|
||||
error: theme.palette.error.main,
|
||||
debug: theme.palette.accent.main,
|
||||
};
|
||||
|
||||
const headers: Header<ILogEntry>[] = [
|
||||
{
|
||||
id: "timestamp",
|
||||
content: "Timestamp",
|
||||
render: (log: ILogEntry) => log.timestamp,
|
||||
},
|
||||
{
|
||||
id: "level",
|
||||
content: "Level",
|
||||
render: (log: ILogEntry) => {
|
||||
const color =
|
||||
levelColors[log.level] || theme.palette.primary.contrastText;
|
||||
return (
|
||||
<span
|
||||
style={{ color, fontWeight: "bold", textTransform: "uppercase" }}
|
||||
>
|
||||
{log.level}
|
||||
</span>
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "service",
|
||||
content: "Service",
|
||||
render: (log: ILogEntry) => log.service,
|
||||
},
|
||||
{
|
||||
id: "message",
|
||||
content: "Message",
|
||||
render: (log: ILogEntry) => log.message,
|
||||
},
|
||||
];
|
||||
|
||||
const filteredLogEntries = logEntries
|
||||
.filter((log: ILogEntry) => {
|
||||
if (logLevel === "all") return true;
|
||||
return log.level === logLevel;
|
||||
})
|
||||
.map((log, idx) => ({ ...log, id: `${log.timestamp}-${idx}` }));
|
||||
|
||||
return (
|
||||
<Stack spacing={theme.spacing(4)}>
|
||||
<Stack direction="row" spacing={theme.spacing(4)} alignItems={"center"}>
|
||||
<Typography variant="h2">Log level: </Typography>
|
||||
<Select
|
||||
value={logLevel}
|
||||
onChange={(e) => {
|
||||
setLogLevel(e.target.value);
|
||||
}}
|
||||
>
|
||||
<MenuItem value="all">All</MenuItem>
|
||||
<MenuItem value="error">Error</MenuItem>
|
||||
<MenuItem value="warn">Warn</MenuItem>
|
||||
<MenuItem value="info">Info</MenuItem>
|
||||
<MenuItem value="debug">Debug</MenuItem>
|
||||
</Select>
|
||||
</Stack>
|
||||
|
||||
<Table
|
||||
headers={headers}
|
||||
data={filteredLogEntries}
|
||||
expandableRows={true}
|
||||
renderExpandedContent={(row) => {
|
||||
if (!row.stack) return null;
|
||||
return <DiagnosticLogDetails logEntry={row} />;
|
||||
}}
|
||||
cardsOnSmallScreens={true}
|
||||
/>
|
||||
</Stack>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,165 @@
|
||||
import Stack from "@mui/material/Stack";
|
||||
import { StatBox } from "@/components/design-elements";
|
||||
import { Table } from "@/components/design-elements";
|
||||
|
||||
import { useTheme } from "@mui/material/styles";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { useGet } from "@/hooks/UseApi";
|
||||
import type { ApiResponse } from "@/hooks/UseApi";
|
||||
import type { IJob, IJobMetrics } from "@/types/job";
|
||||
import type { Header } from "@/components/design-elements/Table";
|
||||
|
||||
export const DiagnosticsQueueTab = () => {
|
||||
const { t } = useTranslation();
|
||||
const theme = useTheme();
|
||||
const { response } = useGet<
|
||||
ApiResponse<{ jobs: IJob[]; metrics: IJobMetrics }>
|
||||
>(`/diagnostic/jobs`, {}, { refreshInterval: 5000 });
|
||||
|
||||
const jobs: IJob[] = response?.data?.jobs || [];
|
||||
const metrics = response?.data?.metrics;
|
||||
|
||||
if (!metrics) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const getHeaders = () => {
|
||||
const headers: Header<IJob>[] = [
|
||||
{
|
||||
id: "name",
|
||||
content: t("diagnosticsPage.tableHeaderId"),
|
||||
render: (row) => {
|
||||
return row?.id || "-";
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "url",
|
||||
content: t("diagnosticsPage.tableHeaderUrl"),
|
||||
render: (row) => {
|
||||
return row?.data?.url || "-";
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "interval",
|
||||
content: t("diagnosticsPage.tableHeaderInterval"),
|
||||
render: (row) => {
|
||||
if (!row?.data?.interval) return "-";
|
||||
const seconds = row.data.interval / 1000;
|
||||
return `${seconds}s`;
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "type",
|
||||
content: t("diagnosticsPage.tableHeaderType"),
|
||||
render: (row) => {
|
||||
return row?.data?.type || "-";
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "active",
|
||||
content: t("diagnosticsPage.tableHeaderActive"),
|
||||
render: (row) => {
|
||||
return row?.data?.isActive ? "true" : "false";
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
id: "runCount",
|
||||
content: t("diagnosticsPage.tableHeaderRunCount"),
|
||||
render: (row) => {
|
||||
return row?.runCount || "-";
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "lastRun",
|
||||
content: t("diagnosticsPage.tableHeaderLastRun"),
|
||||
render: (row) => {
|
||||
if (!row?.lastRunAt) return "-";
|
||||
const date = new Date(row.lastRunAt);
|
||||
return (
|
||||
<Stack>
|
||||
<div>{date.toLocaleDateString()}</div>
|
||||
<div>{date.toLocaleTimeString()}</div>
|
||||
</Stack>
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "lockedAt",
|
||||
content: t("diagnosticsPage.tableHeaderLockedAt"),
|
||||
render: (row) => {
|
||||
if (!row?.lockedAt) return "-";
|
||||
const date = new Date(row.lockedAt);
|
||||
return (
|
||||
<Stack>
|
||||
<div>{date.toLocaleDateString()}</div>
|
||||
<div>{date.toLocaleTimeString()}</div>
|
||||
</Stack>
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "lastFinishedAt",
|
||||
content: t("diagnosticsPage.tableHeaderLastFinishedAt"),
|
||||
render: (row) => {
|
||||
if (!row?.lastFinishedAt) return "-";
|
||||
const date = new Date(row.lastFinishedAt);
|
||||
return (
|
||||
<Stack>
|
||||
<div>{date.toLocaleDateString()}</div>
|
||||
<div>{date.toLocaleTimeString()}</div>
|
||||
</Stack>
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "lastRunTook",
|
||||
content: t("diagnosticsPage.tableHeaderLastRunTook"),
|
||||
render: (row) => {
|
||||
return row?.lastRunTook || "-";
|
||||
},
|
||||
},
|
||||
];
|
||||
return headers;
|
||||
};
|
||||
|
||||
const headers = getHeaders();
|
||||
|
||||
return (
|
||||
<Stack spacing={theme.spacing(8)}>
|
||||
<Stack direction={{ s: "column", md: "row" }} gap={theme.spacing(8)}>
|
||||
<StatBox
|
||||
title={t("diagnosticsPage.statBoxJobsTitle")}
|
||||
subtitle={`${metrics?.jobs}`}
|
||||
sx={{ width: "100%" }}
|
||||
tooltip="Total number of monitoring jobs in the queue"
|
||||
/>
|
||||
<StatBox
|
||||
title={t("diagnosticsPage.statBoxActiveJobsTitle")}
|
||||
subtitle={`${metrics.activeJobs}`}
|
||||
sx={{ width: "100%" }}
|
||||
tooltip="Jobs currently running or locked for execution"
|
||||
/>
|
||||
<StatBox
|
||||
title={t("diagnosticsPage.statBoxFailingJobsTitle")}
|
||||
subtitle={`${metrics.failingJobs}`}
|
||||
sx={{ width: "100%" }}
|
||||
tooltip="Jobs that failed on their last execution"
|
||||
/>
|
||||
<StatBox
|
||||
title={t("diagnosticsPage.statBoxTotalRunsTitle")}
|
||||
subtitle={`${metrics.totalRuns}`}
|
||||
sx={{ width: "100%" }}
|
||||
tooltip="Total number of job executions across all jobs"
|
||||
/>
|
||||
<StatBox
|
||||
title={t("diagnosticsPage.statBoxTotalFailuresTitle")}
|
||||
subtitle={`${metrics.totalFailures}`}
|
||||
sx={{ width: "100%" }}
|
||||
tooltip="Total number of failed job executions across all jobs"
|
||||
/>
|
||||
</Stack>
|
||||
<Table headers={headers} data={jobs} />
|
||||
</Stack>
|
||||
);
|
||||
};
|
||||
Reference in new issue
Block a user