Add real percentages for the uptime of monitors to the main dashboard.
This commit is contained in:
1 parent
319e7c1f3d
commit
654b9d2038
2 files changed
+24
No files matched your search
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user