From b9bcc893b0ae786c54410a4468e129c58f3961dd Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Wed, 5 Feb 2025 13:31:41 -0800 Subject: [PATCH] Add DU Monitors page --- .../DistributedUptime/Monitors/index.jsx | 187 ++++++++++++++++++ 1 file changed, 187 insertions(+) create mode 100644 Client/src/Pages/DistributedUptime/Monitors/index.jsx diff --git a/Client/src/Pages/DistributedUptime/Monitors/index.jsx b/Client/src/Pages/DistributedUptime/Monitors/index.jsx new file mode 100644 index 000000000..e8fc9421d --- /dev/null +++ b/Client/src/Pages/DistributedUptime/Monitors/index.jsx @@ -0,0 +1,187 @@ +// Components +import { Stack, Box, Button } from "@mui/material"; +import DataTable from "../../Components/Table"; +import Breadcrumbs from "../../Components/Breadcrumbs"; +import Host from "../Uptime/Home/host"; +import BarChart from "../../Components/Charts/BarChart"; +import ActionsMenu from "../Uptime/Home/actionsMenu"; +import { StatusLabel } from "../../Components/Label"; +// Utils +import { networkService } from "../../main"; +import { useTheme } from "@mui/material/styles"; +import { useNavigate } from "react-router-dom"; +import useUtils from "../Uptime/utils"; +import { useEffect, useState } from "react"; +import { useSelector } from "react-redux"; + +// Constants +const BREADCRUMBS = [{ name: `Distributed Uptime`, path: "/distributed-uptime" }]; +const TYPE_MAP = { + distributed_http: "Distributed HTTP", +}; + +const DistributedUptimeMonitors = () => { + // Redux state + const { authToken, user } = useSelector((state) => state.auth); + // Local state + const [monitors, setMonitors] = useState([]); + const [filteredMonitors, setFilteredMonitors] = useState([]); + const [monitorsSummary, setMonitorsSummary] = useState({}); + // Utils + + const { determineState } = useUtils(); + const theme = useTheme(); + const navigate = useNavigate(); + const headers = [ + { + id: "name", + content: Host, + render: (row) => ( + + ), + }, + { + id: "status", + content: Status, + render: (row) => { + const status = determineState(row?.monitor); + return ( + + ); + }, + }, + { + id: "responseTime", + content: "Response Time", + render: (row) => , + }, + { + id: "type", + content: "Type", + render: (row) => {TYPE_MAP[row.monitor.type]}, + }, + { + id: "actions", + content: "Actions", + render: (row) => ( + + ), + }, + ]; + + const getMonitorWithPercentage = (monitor, theme) => { + let uptimePercentage = ""; + let percentageColor = theme.palette.percentage.uptimeExcellent; + + if (monitor.uptimePercentage !== undefined) { + uptimePercentage = + monitor.uptimePercentage === 0 + ? "0" + : (monitor.uptimePercentage * 100).toFixed(2); + + percentageColor = + monitor.uptimePercentage < 0.25 + ? theme.palette.percentage.uptimePoor + : monitor.uptimePercentage < 0.5 + ? theme.palette.percentage.uptimeFair + : monitor.uptimePercentage < 0.75 + ? theme.palette.percentage.uptimeGood + : theme.palette.percentage.uptimeExcellent; + } + + return { + id: monitor._id, + name: monitor.name, + url: monitor.url, + title: monitor.name, + percentage: uptimePercentage, + percentageColor, + monitor: monitor, + }; + }; + + useEffect(() => { + const cleanup = networkService.subscribeToDistributedUptimeMonitors({ + authToken: authToken, + teamId: user.teamId, + limit: 25, + types: ["distributed_http"], + page: 0, + rowsPerPage: 10, + filter: null, + field: null, + order: null, + onUpdate: (data) => { + const res = data.monitors; + const { monitors, filteredMonitors, summary } = res; + const mappedMonitors = filteredMonitors.map((monitor) => + getMonitorWithPercentage(monitor, theme) + ); + setMonitors(monitors); + setFilteredMonitors(mappedMonitors); + setMonitorsSummary(summary); + }, + }); + + return cleanup; + }, [user.teamId, authToken, theme]); + + return ( + + + + + + {monitors.length > 0 && ( + { + navigate(`/distributed-uptime/${row.id}`); + }, + }} + /> + )} + + ); +}; + +export default DistributedUptimeMonitors;