Add real percentages for the uptime of monitors to the main dashboard.

This commit is contained in:
M M committed 2024-08-31 17:58:23 -07:00
1 parent 319e7c1f3d
commit 654b9d2038
2 files changed
+24

No files matched your search

+20
View File
@@ -22,7 +22,27 @@ const dateRangeLookup = {
const createCheck = async (checkData) => {
try {
const { monitorId, status } = checkData;
const check = await new Check({ ...checkData }).save();
const n = await Check.countDocuments({ monitorId }) + 1;
const monitor = await Monitor.findById(monitorId);
if (!monitor) {
throw new Error("Monitor not found");
}
if (monitor.uptimePercentage === undefined) {
monitor.uptimePercentage = status ? 100 : 0;
} else {
monitor.uptimePercentage =
(monitor.uptimePercentage * (n - 1) + (status ? 100 : 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,