Merge pull request #773 from bluewave-labs/update/FE-738-uptime_percentage

Adds real percentages to the uptime monitoring dashboard. Fixes #738
This commit is contained in:
Alexander Holliday authored and GitHub committed 2024-08-31 23:02:05 -07:00
commit 45575a4b0c
3 files changed
+36 -1

No files matched your search

+12 -1
View File
@@ -31,10 +31,18 @@ export const buildData = (monitors, isAdmin, navigate) => {
const theme = useTheme();
data.rows = monitors.map((monitor, idx) => {
let uptimePercentage = "";
if (monitor.uptimePercentage !== undefined) {
uptimePercentage =
monitor.uptimePercentage === 0
? "0"
: (monitor.uptimePercentage * 100).toFixed(2);
}
const params = {
url: monitor.url,
title: monitor.name,
percentage: 100,
percentage: uptimePercentage,
percentageColor:
monitor.status === true
? theme.palette.success.main
@@ -78,3 +86,6 @@ export const buildData = (monitors, isAdmin, navigate) => {
});
return data;
};
+20
View File
@@ -22,7 +22,27 @@ const dateRangeLookup = {
const createCheck = async (checkData) => {
try {
const { monitorId, status } = checkData;
const n = await Check.countDocuments({ monitorId }) + 1;
const check = await new Check({ ...checkData }).save();
const monitor = await Monitor.findById(monitorId);
if (!monitor) {
throw new Error("Monitor not found");
}
if (monitor.uptimePercentage === undefined) {
monitor.uptimePercentage = (status === true) ? 1 : 0;
} else {
monitor.uptimePercentage =
(monitor.uptimePercentage * (n - 1) + (status === true ? 1: 0)) / n;
}
await monitor.save();
return check;
} catch (error) {
throw error;
+4
View File
@@ -44,6 +44,10 @@ const MonitorSchema = mongoose.Schema(
type: Number,
default: 60000,
},
uptimePercentage: {
type: Number,
default: undefined,
},
notifications: [
{
type: mongoose.Schema.Types.ObjectId,