Added avgResponseTime to monitor stats, changed date grouping for aggregate stats
This commit is contained in:
1 parent
295146bbef
commit
e22e374eef
1 file changed
+22
-14
@@ -77,11 +77,11 @@ const getLatestResponseTime = (checks) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper function to get average 24h response time
|
* Helper function to get average response time
|
||||||
* @param {Array} checks Array of check objects.
|
* @param {Array} checks Array of check objects.
|
||||||
* @returns {number} Timestamp of the most recent check.
|
* @returns {number} Timestamp of the most recent check.
|
||||||
*/
|
*/
|
||||||
const getAverageResponseTime24Hours = (checks) => {
|
const getAverageResponseTime = (checks) => {
|
||||||
if (!checks || checks.length === 0) {
|
if (!checks || checks.length === 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -178,11 +178,12 @@ const getMonitorAggregateStats = async (monitorId, dateRange) => {
|
|||||||
// Group checks by hour if range is day
|
// Group checks by hour if range is day
|
||||||
if (dateRange === "day") {
|
if (dateRange === "day") {
|
||||||
groupedChecks = checks.reduce((acc, check) => {
|
groupedChecks = checks.reduce((acc, check) => {
|
||||||
const hour = new Date(check.createdAt).getHours();
|
const time = new Date(check.createdAt);
|
||||||
if (!acc[hour]) {
|
time.setMinutes(0, 0, 0);
|
||||||
acc[hour] = { hour, checks: [] };
|
if (!acc[time]) {
|
||||||
|
acc[time] = { time, checks: [] };
|
||||||
}
|
}
|
||||||
acc[hour].checks.push(check);
|
acc[time].checks.push(check);
|
||||||
return acc;
|
return acc;
|
||||||
}, {});
|
}, {});
|
||||||
}
|
}
|
||||||
@@ -190,11 +191,11 @@ const getMonitorAggregateStats = async (monitorId, dateRange) => {
|
|||||||
// Group checks by day if range is week or month
|
// Group checks by day if range is week or month
|
||||||
else {
|
else {
|
||||||
groupedChecks = checks.reduce((acc, check) => {
|
groupedChecks = checks.reduce((acc, check) => {
|
||||||
const day = new Date(check.createdAt).toISOString().split("T")[0]; // Extract the date part
|
const time = new Date(check.createdAt).toISOString().split("T")[0]; // Extract the date part
|
||||||
if (!acc[day]) {
|
if (!acc[time]) {
|
||||||
acc[day] = { day, checks: [] };
|
acc[time] = { time, checks: [] };
|
||||||
}
|
}
|
||||||
acc[day].checks.push(check);
|
acc[time].checks.push(check);
|
||||||
return acc;
|
return acc;
|
||||||
}, {});
|
}, {});
|
||||||
}
|
}
|
||||||
@@ -210,8 +211,7 @@ const getMonitorAggregateStats = async (monitorId, dateRange) => {
|
|||||||
totalChecks;
|
totalChecks;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
hour: group.hour,
|
time: group.time,
|
||||||
day: group.day,
|
|
||||||
totalChecks,
|
totalChecks,
|
||||||
totalIncidents,
|
totalIncidents,
|
||||||
avgResponseTime,
|
avgResponseTime,
|
||||||
@@ -303,11 +303,19 @@ const getMonitorStatsById = async (req) => {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
// HTTP/PING Specific stats
|
// HTTP/PING Specific stats
|
||||||
|
|
||||||
|
//24 hour data
|
||||||
monitorStats.avgResponseTime24hours =
|
monitorStats.avgResponseTime24hours =
|
||||||
getAverageResponseTime24Hours(checks24Hours);
|
getAverageResponseTime(checks24Hours);
|
||||||
monitorStats.uptime7Days = getUptimePercentage(checks7Days);
|
|
||||||
monitorStats.uptime24Hours = getUptimePercentage(checks24Hours);
|
monitorStats.uptime24Hours = getUptimePercentage(checks24Hours);
|
||||||
|
|
||||||
|
//7 day data
|
||||||
|
monitorStats.uptime7Days = getUptimePercentage(checks7Days);
|
||||||
|
monitorStats.avgResponseTime7days = getAverageResponseTime(checks7Days);
|
||||||
|
// 30 day data
|
||||||
monitorStats.uptime30Days = getUptimePercentage(checks30Days);
|
monitorStats.uptime30Days = getUptimePercentage(checks30Days);
|
||||||
|
monitorStats.avgResponseTime30days = getAverageResponseTime(checks30Days);
|
||||||
|
|
||||||
monitorStats.statusBar = getStatusBarValues(monitor, checks60Mins);
|
monitorStats.statusBar = getStatusBarValues(monitor, checks60Mins);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user