Moved http/ping specific data
This commit is contained in:
1 parent
5ccb85e755
commit
df16bf3db5
2 files changed
+34
-31
No files matched your search
@@ -145,7 +145,6 @@ const getMonitorStatsById = async (req) => {
|
|||||||
if (monitor === null || monitor === undefined) {
|
if (monitor === null || monitor === undefined) {
|
||||||
throw new Error(errorMessages.DB_FIND_MONTIOR_BY_ID(monitorId));
|
throw new Error(errorMessages.DB_FIND_MONTIOR_BY_ID(monitorId));
|
||||||
}
|
}
|
||||||
|
|
||||||
// This effectively removes limit, returning all checks
|
// This effectively removes limit, returning all checks
|
||||||
if (limit === undefined) limit = 0;
|
if (limit === undefined) limit = 0;
|
||||||
|
|
||||||
@@ -185,37 +184,8 @@ const getMonitorStatsById = async (req) => {
|
|||||||
// HTTP/PING Specific stats
|
// HTTP/PING Specific stats
|
||||||
monitorStats.avgResponseTime = getAverageResponseTime(checksForDateRange);
|
monitorStats.avgResponseTime = getAverageResponseTime(checksForDateRange);
|
||||||
monitorStats.uptime = getUptimePercentage(checksForDateRange);
|
monitorStats.uptime = getUptimePercentage(checksForDateRange);
|
||||||
}
|
|
||||||
|
|
||||||
monitorStats.incidents = getIncidents(checksForDateRange);
|
|
||||||
|
|
||||||
// If more than numToDisplay checks, pick every nth check
|
|
||||||
|
|
||||||
let nthChecks = checksForDateRange;
|
|
||||||
|
|
||||||
if (
|
|
||||||
numToDisplay !== undefined &&
|
|
||||||
checksForDateRange &&
|
|
||||||
checksForDateRange.length > numToDisplay
|
|
||||||
) {
|
|
||||||
const n = Math.ceil(checksForDateRange.length / numToDisplay);
|
|
||||||
nthChecks = checksForDateRange.filter((_, index) => index % n === 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Normalize checks if requested
|
|
||||||
if (normalize !== undefined) {
|
|
||||||
const normailzedChecks = NormalizeData(checksForDateRange, 1, 100);
|
|
||||||
monitorStats.checks = normailzedChecks;
|
|
||||||
} else {
|
|
||||||
monitorStats.checks = nthChecks;
|
|
||||||
}
|
|
||||||
|
|
||||||
monitorStats.uptimeDuration = calculateUptimeDuration(checksAll);
|
|
||||||
monitorStats.lastChecked = getLastChecked(checksAll);
|
|
||||||
monitorStats.latestResponseTime = getLatestResponseTime(checksAll);
|
|
||||||
|
|
||||||
// Aggregate data
|
// Aggregate data
|
||||||
|
|
||||||
let groupedChecks;
|
let groupedChecks;
|
||||||
// Group checks by hour if range is day
|
// Group checks by hour if range is day
|
||||||
if (dateRange === "day") {
|
if (dateRange === "day") {
|
||||||
@@ -248,8 +218,38 @@ const getMonitorStatsById = async (req) => {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
monitorStats.aggregateData = aggregateData;
|
monitorStats.aggregateData = aggregateData;
|
||||||
|
}
|
||||||
|
|
||||||
|
monitorStats.incidents = getIncidents(checksForDateRange);
|
||||||
|
|
||||||
|
// If more than numToDisplay checks, pick every nth check
|
||||||
|
|
||||||
|
let nthChecks = checksForDateRange;
|
||||||
|
|
||||||
|
if (
|
||||||
|
numToDisplay !== undefined &&
|
||||||
|
checksForDateRange &&
|
||||||
|
checksForDateRange.length > numToDisplay
|
||||||
|
) {
|
||||||
|
const n = Math.ceil(checksForDateRange.length / numToDisplay);
|
||||||
|
nthChecks = checksForDateRange.filter((_, index) => index % n === 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Normalize checks if requested
|
||||||
|
if (normalize !== undefined) {
|
||||||
|
const normailzedChecks = NormalizeData(checksForDateRange, 1, 100);
|
||||||
|
monitorStats.checks = normailzedChecks;
|
||||||
|
} else {
|
||||||
|
monitorStats.checks = nthChecks;
|
||||||
|
}
|
||||||
|
|
||||||
|
monitorStats.uptimeDuration = calculateUptimeDuration(checksAll);
|
||||||
|
monitorStats.lastChecked = getLastChecked(checksAll);
|
||||||
|
monitorStats.latestResponseTime = getLatestResponseTime(checksAll);
|
||||||
|
|
||||||
return monitorStats;
|
return monitorStats;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
error.methodName = "getMonitorStatsById";
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -5,7 +5,10 @@ const handleErrors = (error, req, res, next) => {
|
|||||||
const status = error.status || 500;
|
const status = error.status || 500;
|
||||||
const message = error.message || errorMessages.FRIENDLY_ERROR;
|
const message = error.message || errorMessages.FRIENDLY_ERROR;
|
||||||
const service = error.service || errorMessages.UNKNOWN_SERVICE;
|
const service = error.service || errorMessages.UNKNOWN_SERVICE;
|
||||||
logger.error(error.message, { service: service });
|
logger.error(error.message, {
|
||||||
|
service: service,
|
||||||
|
methodName: error.methodName,
|
||||||
|
});
|
||||||
res.status(status).json({ success: false, msg: message });
|
res.status(status).json({ success: false, msg: message });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user