GroupedChecks
This commit is contained in:
1 parent
cdc58e5905
commit
3182141d0a
14 files changed
+592
-62
No files matched your search
@@ -33,6 +33,7 @@ export const XTick = ({ x, y, payload, range }: XTickProps) => {
|
||||
const format = tickDateFormatLookup(range);
|
||||
const theme = useTheme();
|
||||
const uiTimezone = useAppSelector((state: any) => state.ui.timezone);
|
||||
console.log(payload);
|
||||
return (
|
||||
<Text
|
||||
x={x}
|
||||
@@ -124,7 +125,7 @@ export const ChartResponseTime = ({
|
||||
<XAxis
|
||||
axisLine={false}
|
||||
tickLine={false}
|
||||
dataKey="_id"
|
||||
dataKey="bucketDate"
|
||||
tick={(props) => <XTick {...props} range={range} />}
|
||||
/>
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ import { Fragment, useId } from "react";
|
||||
import { XTick } from "./ChartResponseTime";
|
||||
|
||||
import { useTheme } from "@mui/material/styles";
|
||||
import type { IInfraCheck } from "@/types/check";
|
||||
import type { GroupedCheck } from "@/types/check";
|
||||
|
||||
const AREA_COLORS = [
|
||||
// Blues
|
||||
@@ -104,7 +104,7 @@ export const HistogramInfrastructure = ({
|
||||
title: string;
|
||||
type: string;
|
||||
idx: number | null;
|
||||
checks: IInfraCheck[];
|
||||
checks: GroupedCheck[];
|
||||
xKey: string;
|
||||
yDomain?: number[];
|
||||
dataKeys: string[];
|
||||
@@ -118,15 +118,15 @@ export const HistogramInfrastructure = ({
|
||||
const theme = useTheme();
|
||||
const uniqueId = useId();
|
||||
|
||||
let avgTemps: { _id: string; avg_temp: number | null }[] = [];
|
||||
let avgTemps: { bucketDate: Date; avg_temp: number | null }[] = [];
|
||||
let tempYDomain: number[] = [];
|
||||
if (type === "temp") {
|
||||
avgTemps = checks.map((check) => {
|
||||
const temps = check.cpu.temperature || [];
|
||||
const temps = check.cpu?.temperature || [];
|
||||
if (temps.length === 0) return { ...check, avg_temp: null };
|
||||
const totalTemp = temps.reduce((sum, temp) => sum + (temp || 0), 0);
|
||||
const avgTemp = totalTemp / temps.length;
|
||||
return { _id: check._id, avg_temp: avgTemp };
|
||||
return { bucketDate: check.bucketDate, avg_temp: avgTemp };
|
||||
});
|
||||
|
||||
const maxTemp: number = avgTemps.reduce((max, item) => {
|
||||
|
||||
@@ -64,7 +64,7 @@ export const HistogramPageSpeedScores = ({
|
||||
<ResponsiveContainer width="100%" minWidth={25} height={215}>
|
||||
<AreaChart data={checks}>
|
||||
<XAxis
|
||||
dataKey={"_id"}
|
||||
dataKey={"bucketDate"}
|
||||
tick={(props) => <XTick {...props} range={range} />}
|
||||
/>
|
||||
<CartesianGrid
|
||||
|
||||
@@ -43,7 +43,7 @@ const XLabel = ({
|
||||
fontSize={11}
|
||||
fill={theme.palette.text.secondary}
|
||||
>
|
||||
{formatDateWithTz(p1._id, dateFormat, uiTimezone)}
|
||||
{formatDateWithTz(p1.bucketDate, dateFormat, uiTimezone)}
|
||||
</text>
|
||||
<text
|
||||
x="100%"
|
||||
@@ -53,7 +53,7 @@ const XLabel = ({
|
||||
fontSize={11}
|
||||
fill={theme.palette.text.secondary}
|
||||
>
|
||||
{formatDateWithTz(p2._id, dateFormat, uiTimezone)}
|
||||
{formatDateWithTz(p2.bucketDate, dateFormat, uiTimezone)}
|
||||
</text>
|
||||
</>
|
||||
);
|
||||
@@ -91,8 +91,8 @@ export const HistogramStatus = ({
|
||||
const titleText = t("common.charts.uptime.avgResponseTime");
|
||||
const fmt = range === "30d" ? "MMM D, YYYY" : "ddd, MMM D, YYYY, h:mm A";
|
||||
let dateLabel = "";
|
||||
if (d?._id) {
|
||||
const base = new Date(d._id as any);
|
||||
if (d?.bucketDate) {
|
||||
const base = new Date(d.bucketDate);
|
||||
const midBucket =
|
||||
range === "30d" ? new Date(base.getTime() + 12 * 60 * 60 * 1000) : base;
|
||||
dateLabel = formatDateWithTz(midBucket.toISOString(), fmt, uiTimezone);
|
||||
@@ -174,7 +174,7 @@ export const HistogramStatus = ({
|
||||
);
|
||||
return (
|
||||
<Cell
|
||||
key={groupedCheck._id}
|
||||
key={groupedCheck.bucketDate}
|
||||
fill={theme.palette[fillColor].main}
|
||||
/>
|
||||
);
|
||||
|
||||
@@ -12,7 +12,6 @@ import { useTheme } from "@mui/material/styles";
|
||||
import { useParams } from "react-router";
|
||||
import type { ApiResponse } from "@/types/api";
|
||||
import type { IMonitor, IMonitorWithMonitorStats } from "@/types/monitor";
|
||||
import type { IInfraCheck } from "@/types/check";
|
||||
import {
|
||||
getFrequency,
|
||||
getCores,
|
||||
@@ -43,16 +42,16 @@ const InfraDetailsPage = () => {
|
||||
|
||||
const monitor = response?.data?.monitor;
|
||||
const stats = response?.data?.stats;
|
||||
const checks = (response?.data?.checks || []) as IInfraCheck[];
|
||||
const palette = getStatusPalette(monitor?.status || "initializing");
|
||||
const checks = Array.isArray(response?.data?.checks)
|
||||
? response?.data?.checks
|
||||
: [];
|
||||
const palette = getStatusPalette(monitor?.status ?? "initializing");
|
||||
|
||||
const streakDuration = stats?.currentStreakStartedAt
|
||||
? Date.now() - stats?.currentStreakStartedAt
|
||||
: 0;
|
||||
const streakStartedAt = stats?.currentStreakStartedAt ?? 0;
|
||||
const streakDuration = streakStartedAt > 0 ? Date.now() - streakStartedAt : 0;
|
||||
|
||||
const lastChecked = stats?.lastCheckTimestamp
|
||||
? Date.now() - stats?.lastCheckTimestamp
|
||||
: -1;
|
||||
const lastCheckTs = stats?.lastCheckTimestamp ?? -1;
|
||||
const lastChecked = lastCheckTs >= 0 ? Date.now() - lastCheckTs : -1;
|
||||
|
||||
if (!monitor) {
|
||||
return null;
|
||||
@@ -88,36 +87,38 @@ const InfraDetailsPage = () => {
|
||||
<StatBox
|
||||
title={t("monitors.common.stats.lastResponseTime")}
|
||||
subtitle={
|
||||
stats?.lastResponseTime ? `${stats?.lastResponseTime} ms` : "N/A"
|
||||
typeof stats?.lastResponseTime === "number"
|
||||
? `${stats.lastResponseTime} ms`
|
||||
: "N/A"
|
||||
}
|
||||
/>
|
||||
<StatBox
|
||||
title={t("monitors.common.stats.cpuPhysical")}
|
||||
subtitle={getCores(checks[0]?.cpu?.physical_core)}
|
||||
subtitle={getCores(checks?.[0]?.cpu?.physical_core || 0)}
|
||||
/>
|
||||
<StatBox
|
||||
title={t("monitors.common.stats.cpuLogical")}
|
||||
subtitle={getCores(checks[0]?.cpu?.logical_core)}
|
||||
subtitle={getCores(checks?.[0]?.cpu?.logical_core || 0)}
|
||||
/>
|
||||
<StatBox
|
||||
title={t("monitors.common.stats.cpuFrequency")}
|
||||
subtitle={getFrequency(checks[0]?.cpu?.current_frequency)}
|
||||
subtitle={getFrequency(checks?.[0]?.cpu?.current_frequency || 0)}
|
||||
/>
|
||||
<StatBox
|
||||
title={t("monitors.common.stats.cpuTemperature")}
|
||||
subtitle={getAvgTemp(checks[0]?.cpu?.temperature)}
|
||||
subtitle={getAvgTemp(checks?.[0]?.cpu?.temperature || [])}
|
||||
/>
|
||||
<StatBox
|
||||
title={t("monitors.common.stats.memory")}
|
||||
subtitle={getGbs(checks[0]?.memory?.total_bytes)}
|
||||
subtitle={getGbs(checks?.[0]?.memory?.total_bytes || 0)}
|
||||
/>
|
||||
<StatBox
|
||||
title={t("monitors.common.stats.disk")}
|
||||
subtitle={getDiskTotalGbs(checks[0]?.disk)}
|
||||
subtitle={getDiskTotalGbs(checks?.[0]?.disk)}
|
||||
/>
|
||||
<StatBox
|
||||
title={t("monitors.common.stats.os")}
|
||||
subtitle={getOsAndPlatform(checks[0]?.host)}
|
||||
subtitle={getOsAndPlatform(checks?.[0]?.host || {})}
|
||||
/>
|
||||
</Stack>
|
||||
|
||||
|
||||
@@ -5,9 +5,9 @@ import { Gauge } from "@/components/design-elements";
|
||||
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { getGbs, getFrequency } from "./InfraUtils";
|
||||
import type { IInfraCheck } from "@/types/check";
|
||||
import { useTheme } from "@mui/material/styles";
|
||||
import useMediaQuery from "@mui/material/useMediaQuery";
|
||||
import type { GroupedCheck } from "@/types/check";
|
||||
|
||||
const InfraDetailGauge = ({
|
||||
title,
|
||||
@@ -42,7 +42,7 @@ const InfraDetailGauge = ({
|
||||
);
|
||||
};
|
||||
|
||||
export const InfraDetailsGauges = ({ checks }: { checks: IInfraCheck[] }) => {
|
||||
export const InfraDetailsGauges = ({ checks }: { checks: GroupedCheck[] }) => {
|
||||
const { t } = useTranslation();
|
||||
const theme = useTheme();
|
||||
const isSmall = useMediaQuery(theme.breakpoints.down("md"));
|
||||
@@ -54,31 +54,31 @@ export const InfraDetailsGauges = ({ checks }: { checks: IInfraCheck[] }) => {
|
||||
>
|
||||
<InfraDetailGauge
|
||||
title={t("monitors.infrastructure.gauges.memory.title")}
|
||||
progress={(checks[0]?.memory.usage_percent || 0) * 100}
|
||||
progress={(checks[0]?.memory?.usage_percent || 0) * 100}
|
||||
upperLabel={t("monitors.infrastructure.gauges.memory.upperLabel")}
|
||||
upperValue={getGbs(checks[0]?.memory.used_bytes)}
|
||||
upperValue={getGbs(checks[0]?.memory?.used_bytes || 0)}
|
||||
lowerLabel={t("monitors.infrastructure.gauges.memory.lowerLabel")}
|
||||
lowerValue={getGbs(checks[0]?.memory.total_bytes)}
|
||||
lowerValue={getGbs(checks[0]?.memory?.total_bytes || 0)}
|
||||
/>
|
||||
<InfraDetailGauge
|
||||
title={t("monitors.infrastructure.gauges.cpu.title")}
|
||||
progress={(checks[0]?.cpu.usage_percent || 0) * 100}
|
||||
progress={(checks[0]?.cpu?.usage_percent || 0) * 100}
|
||||
upperLabel={t("monitors.infrastructure.gauges.cpu.upperLabel")}
|
||||
upperValue={getFrequency(checks[0]?.cpu.current_frequency)}
|
||||
upperValue={getFrequency(checks[0]?.cpu?.current_frequency || 0)}
|
||||
lowerLabel={t("monitors.infrastructure.gauges.cpu.lowerLabel")}
|
||||
lowerValue={getFrequency(checks[0]?.cpu.frequency)}
|
||||
lowerValue={getFrequency(checks[0]?.cpu?.frequency || 0)}
|
||||
/>
|
||||
{checks[0]?.disk?.map((disk, idx) => {
|
||||
return (
|
||||
<InfraDetailGauge
|
||||
key={disk.device + idx}
|
||||
key={disk?.device || 0 + idx}
|
||||
// title={`Disk ${idx} usage`}
|
||||
title={t("monitors.infrastructure.gauges.disk.title", { idx })}
|
||||
progress={(disk.usage_percent || 0) * 100}
|
||||
upperLabel={t("monitors.infrastructure.gauges.disk.upperLabel")}
|
||||
upperValue={getGbs(disk.used_bytes)}
|
||||
upperValue={getGbs(disk?.used_bytes || 0)}
|
||||
lowerLabel={t("monitors.infrastructure.gauges.disk.lowerLabel")}
|
||||
lowerValue={getGbs(disk.total_bytes)}
|
||||
lowerValue={getGbs(disk?.total_bytes || 0)}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
|
||||
@@ -2,12 +2,12 @@ import Grid from "@mui/material/Grid";
|
||||
import { HistogramInfrastructure } from "@/components/monitors";
|
||||
|
||||
import { useTranslation } from "react-i18next";
|
||||
import type { IInfraCheck } from "@/types/check";
|
||||
import type { GroupedCheck } from "@/types/check";
|
||||
import { useMemo } from "react";
|
||||
import { useTheme } from "@mui/material/styles";
|
||||
import useMediaQuery from "@mui/material/useMediaQuery";
|
||||
|
||||
const getChartConfigs = (theme: any, checks: IInfraCheck[], t: any) => {
|
||||
const getChartConfigs = (theme: any, checks: GroupedCheck[], t: any) => {
|
||||
return [
|
||||
{
|
||||
title: t("common.charts.infrastructure.memory.title"),
|
||||
@@ -52,7 +52,7 @@ export const InfraDetailsGraphs = ({
|
||||
checks,
|
||||
range,
|
||||
}: {
|
||||
checks: IInfraCheck[];
|
||||
checks: GroupedCheck[];
|
||||
range: string;
|
||||
}) => {
|
||||
const theme = useTheme();
|
||||
|
||||
@@ -36,7 +36,10 @@ export const getGbs = (bytes: number): string => {
|
||||
}
|
||||
};
|
||||
|
||||
export const getDiskTotalGbs = (disk: IDiskInfo[]): string => {
|
||||
export const getDiskTotalGbs = (disk?: Partial<IDiskInfo>[]): string => {
|
||||
if (!disk) {
|
||||
return getGbs(0);
|
||||
}
|
||||
const totalBytes =
|
||||
disk?.reduce((acc, disk) => acc + (disk.total_bytes || 0), 0) || 0;
|
||||
return getGbs(totalBytes);
|
||||
|
||||
@@ -146,16 +146,32 @@ export interface CheckWithMonitor {
|
||||
updatedAt: string;
|
||||
timings: CheckTimings;
|
||||
}
|
||||
|
||||
export interface GroupedCheck {
|
||||
_id: string;
|
||||
avgResponseTime: number;
|
||||
count: number;
|
||||
upChecks?: number;
|
||||
downChecks?: number;
|
||||
avgResponseTimeUp?: number | null;
|
||||
avgResponseTimeDown?: number | null;
|
||||
runningContainersSnapshot?: IDockerContainerSummary[];
|
||||
bucketDate: Date;
|
||||
|
||||
count?: number;
|
||||
avgResponseTime?: number;
|
||||
|
||||
totalContainers?: number;
|
||||
runningContainers?: number;
|
||||
healthyContainers?: number;
|
||||
|
||||
accessibility?: number | null;
|
||||
bestPractices?: number | null;
|
||||
seo?: number | null;
|
||||
performance?: number | null;
|
||||
cls?: number | null;
|
||||
si?: number | null;
|
||||
fcp?: number | null;
|
||||
lcp?: number | null;
|
||||
tbt?: number | null;
|
||||
|
||||
// Infrastructure aggregates (optional snapshot/averages)
|
||||
cpu?: Partial<ICpuInfo>;
|
||||
memory?: Partial<IMemoryInfo>;
|
||||
disk?: Partial<IDiskInfo>[];
|
||||
host?: Partial<IHostInfo>;
|
||||
net?: Array<Pick<INetInfo, "name" | "bytes_recv" | "bytes_sent">>;
|
||||
}
|
||||
|
||||
export interface LatestCheck {
|
||||
|
||||
Reference in new issue
Block a user