stats fixes
This commit is contained in:
1 parent
f1a6afb860
commit
6447c315ce
6 files changed
+36
-13
No files matched your search
@@ -243,6 +243,7 @@ export const useFetchPageSpeedMonitorById = ({ monitorId, dateRange, updateTrigg
|
|||||||
const [isLoading, setIsLoading] = useState(true);
|
const [isLoading, setIsLoading] = useState(true);
|
||||||
const [networkError, setNetworkError] = useState(false);
|
const [networkError, setNetworkError] = useState(false);
|
||||||
const [monitor, setMonitor] = useState(undefined);
|
const [monitor, setMonitor] = useState(undefined);
|
||||||
|
const [monitorStats, setMonitorStats] = useState(undefined);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchMonitor = async () => {
|
const fetchMonitor = async () => {
|
||||||
@@ -254,7 +255,8 @@ export const useFetchPageSpeedMonitorById = ({ monitorId, dateRange, updateTrigg
|
|||||||
monitorId: monitorId,
|
monitorId: monitorId,
|
||||||
dateRange: dateRange,
|
dateRange: dateRange,
|
||||||
});
|
});
|
||||||
setMonitor(response.data.data);
|
setMonitor(response.data.data.monitor);
|
||||||
|
setMonitorStats(response.data.data.monitorStats);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setNetworkError(true);
|
setNetworkError(true);
|
||||||
} finally {
|
} finally {
|
||||||
@@ -263,7 +265,7 @@ export const useFetchPageSpeedMonitorById = ({ monitorId, dateRange, updateTrigg
|
|||||||
};
|
};
|
||||||
fetchMonitor();
|
fetchMonitor();
|
||||||
}, [monitorId, dateRange, updateTrigger]);
|
}, [monitorId, dateRange, updateTrigger]);
|
||||||
return [monitor, isLoading, networkError];
|
return [monitor, monitorStats, isLoading, networkError];
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useFetchUptimeMonitorById = ({ monitorId, dateRange, trigger }) => {
|
export const useFetchUptimeMonitorById = ({ monitorId, dateRange, trigger }) => {
|
||||||
|
|||||||
@@ -4,9 +4,21 @@ import { Typography } from "@mui/material";
|
|||||||
import { getHumanReadableDuration } from "../../../../../Utils/timeUtils.js";
|
import { getHumanReadableDuration } from "../../../../../Utils/timeUtils.js";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
|
||||||
const PageSpeedStatusBoxes = ({ shouldRender, monitor }) => {
|
const PageSpeedStatusBoxes = ({ shouldRender, monitorStats }) => {
|
||||||
const uptimeDuration = getHumanReadableDuration(monitor?.uptimeDuration);
|
const lastChecked = monitorStats?.lastCheckTimestamp
|
||||||
const time = getHumanReadableDuration(monitor?.lastChecked);
|
? Date.now() - monitorStats.lastCheckTimestamp
|
||||||
|
: 0;
|
||||||
|
|
||||||
|
// Determine time since last failure
|
||||||
|
const timeOfLastFailure = monitorStats?.timeOfLastFailure;
|
||||||
|
const timeSinceLastFailure =
|
||||||
|
timeOfLastFailure > 0
|
||||||
|
? Date.now() - timeOfLastFailure
|
||||||
|
: Date.now() - new Date(monitorStats?.createdAt);
|
||||||
|
|
||||||
|
const streakTime = getHumanReadableDuration(timeSinceLastFailure);
|
||||||
|
|
||||||
|
const time = getHumanReadableDuration(lastChecked);
|
||||||
|
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
@@ -16,7 +28,7 @@ const PageSpeedStatusBoxes = ({ shouldRender, monitor }) => {
|
|||||||
heading="checks since"
|
heading="checks since"
|
||||||
subHeading={
|
subHeading={
|
||||||
<>
|
<>
|
||||||
{uptimeDuration}
|
{streakTime}
|
||||||
<Typography component="span">{t("ago")}</Typography>
|
<Typography component="span">{t("ago")}</Typography>
|
||||||
</>
|
</>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ const PageSpeedDetails = () => {
|
|||||||
});
|
});
|
||||||
const [trigger, setTrigger] = useState(false);
|
const [trigger, setTrigger] = useState(false);
|
||||||
// Network
|
// Network
|
||||||
const [monitor, isLoading, networkError] = useFetchPageSpeedMonitorById({
|
const [monitor, monitorStats, isLoading, networkError] = useFetchPageSpeedMonitorById({
|
||||||
monitorId,
|
monitorId,
|
||||||
dateRange: "day",
|
dateRange: "day",
|
||||||
updateTrigger: trigger,
|
updateTrigger: trigger,
|
||||||
@@ -95,7 +95,7 @@ const PageSpeedDetails = () => {
|
|||||||
/>
|
/>
|
||||||
<PageSpeedStatusBoxes
|
<PageSpeedStatusBoxes
|
||||||
shouldRender={!isLoading}
|
shouldRender={!isLoading}
|
||||||
monitor={monitor}
|
monitorStats={monitorStats}
|
||||||
/>
|
/>
|
||||||
<MonitorTimeFrameHeader
|
<MonitorTimeFrameHeader
|
||||||
shouldRender={!isLoading}
|
shouldRender={!isLoading}
|
||||||
|
|||||||
@@ -18,7 +18,10 @@ const UptimeStatusBoxes = ({
|
|||||||
|
|
||||||
// Determine time since last failure
|
// Determine time since last failure
|
||||||
const timeOfLastFailure = monitorStats?.timeOfLastFailure;
|
const timeOfLastFailure = monitorStats?.timeOfLastFailure;
|
||||||
const timeSinceLastFailure = timeOfLastFailure > 0 ? Date.now() - timeOfLastFailure : 0;
|
const timeSinceLastFailure =
|
||||||
|
timeOfLastFailure > 0
|
||||||
|
? Date.now() - timeOfLastFailure
|
||||||
|
: Date.now() - new Date(monitorStats?.createdAt);
|
||||||
|
|
||||||
// Determine time since last check
|
// Determine time since last check
|
||||||
const timeOfLastCheck = monitorStats?.lastCheckTimestamp;
|
const timeOfLastCheck = monitorStats?.lastCheckTimestamp;
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ class MonitorController {
|
|||||||
const dateRange = requireString(req?.query?.dateRange, "dateRange");
|
const dateRange = requireString(req?.query?.dateRange, "dateRange");
|
||||||
const teamId = requireTeamId(req?.user?.teamId);
|
const teamId = requireTeamId(req?.user?.teamId);
|
||||||
|
|
||||||
const monitor = await this.monitorService.getPageSpeedDetailsById({
|
const data = await this.monitorService.getPageSpeedDetailsById({
|
||||||
teamId,
|
teamId,
|
||||||
monitorId,
|
monitorId,
|
||||||
dateRange,
|
dateRange,
|
||||||
@@ -133,7 +133,7 @@ class MonitorController {
|
|||||||
return res.status(200).json({
|
return res.status(200).json({
|
||||||
success: true,
|
success: true,
|
||||||
msg: "Page speed details retrieved successfully",
|
msg: "Page speed details retrieved successfully",
|
||||||
data: monitor,
|
data,
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
next(error);
|
next(error);
|
||||||
|
|||||||
@@ -330,9 +330,15 @@ export class MonitorService implements IMonitorService {
|
|||||||
if (checksData.monitorType !== "pagespeed") {
|
if (checksData.monitorType !== "pagespeed") {
|
||||||
throw new AppError({ message: "Unable to load pagespeed stats for this monitor", status: 500 });
|
throw new AppError({ message: "Unable to load pagespeed stats for this monitor", status: 500 });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const monitorStats = await this.monitorStatsRepository.findByMonitorId(monitor.id);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...monitor,
|
monitor: {
|
||||||
checks: checksData.checks,
|
...monitor,
|
||||||
|
checks: checksData.checks,
|
||||||
|
},
|
||||||
|
monitorStats,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
getMonitorById = async ({ teamId, monitorId }: { teamId: string; monitorId: string }): Promise<any> => {
|
getMonitorById = async ({ teamId, monitorId }: { teamId: string; monitorId: string }): Promise<any> => {
|
||||||
|
|||||||
Reference in new issue
Block a user