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) => {
|
const createCheck = async (checkData) => {
|
||||||
try {
|
try {
|
||||||
|
const { monitorId, status } = checkData;
|
||||||
|
|
||||||
const check = await new Check({ ...checkData }).save();
|
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;
|
return check;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw error;
|
throw error;
|
||||||
|
|||||||
@@ -44,6 +44,10 @@ const MonitorSchema = mongoose.Schema(
|
|||||||
type: Number,
|
type: Number,
|
||||||
default: 60000,
|
default: 60000,
|
||||||
},
|
},
|
||||||
|
uptimePercentage: {
|
||||||
|
type: Number,
|
||||||
|
default: undefined,
|
||||||
|
},
|
||||||
notifications: [
|
notifications: [
|
||||||
{
|
{
|
||||||
type: mongoose.Schema.Types.ObjectId,
|
type: mongoose.Schema.Types.ObjectId,
|
||||||
|
|||||||
Reference in new issue
Block a user