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:
3 files changed
+36
-1
No files matched your search
@@ -31,10 +31,18 @@ export const buildData = (monitors, isAdmin, navigate) => {
|
|||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
|
|
||||||
data.rows = monitors.map((monitor, idx) => {
|
data.rows = monitors.map((monitor, idx) => {
|
||||||
|
let uptimePercentage = "";
|
||||||
|
if (monitor.uptimePercentage !== undefined) {
|
||||||
|
uptimePercentage =
|
||||||
|
monitor.uptimePercentage === 0
|
||||||
|
? "0"
|
||||||
|
: (monitor.uptimePercentage * 100).toFixed(2);
|
||||||
|
}
|
||||||
|
|
||||||
const params = {
|
const params = {
|
||||||
url: monitor.url,
|
url: monitor.url,
|
||||||
title: monitor.name,
|
title: monitor.name,
|
||||||
percentage: 100,
|
percentage: uptimePercentage,
|
||||||
percentageColor:
|
percentageColor:
|
||||||
monitor.status === true
|
monitor.status === true
|
||||||
? theme.palette.success.main
|
? theme.palette.success.main
|
||||||
@@ -78,3 +86,6 @@ export const buildData = (monitors, isAdmin, navigate) => {
|
|||||||
});
|
});
|
||||||
return data;
|
return data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -22,7 +22,27 @@ const dateRangeLookup = {
|
|||||||
|
|
||||||
const createCheck = async (checkData) => {
|
const createCheck = async (checkData) => {
|
||||||
try {
|
try {
|
||||||
|
const { monitorId, status } = checkData;
|
||||||
|
|
||||||
|
const n = await Check.countDocuments({ monitorId }) + 1;
|
||||||
|
|
||||||
const check = await new Check({ ...checkData }).save();
|
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;
|
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