Implemented basic gauge chart
This commit is contained in:
1 parent
38fddf5b9b
commit
2a1afc8610
5 files changed
+109
-63
No files matched your search
@@ -182,8 +182,9 @@ const getMonitorStatsById = async (req) => {
|
||||
|
||||
if (monitor.type === "http" || monitor.type === "ping") {
|
||||
// HTTP/PING Specific stats
|
||||
monitorStats.avgResponseTime = getAverageResponseTime(checksForDateRange);
|
||||
monitorStats.uptime = getUptimePercentage(checksForDateRange);
|
||||
monitorStats.periodAvgResponseTime =
|
||||
getAverageResponseTime(checksForDateRange);
|
||||
monitorStats.periodUptime = getUptimePercentage(checksForDateRange);
|
||||
|
||||
// Aggregate data
|
||||
let groupedChecks;
|
||||
@@ -198,11 +199,21 @@ const getMonitorStatsById = async (req) => {
|
||||
acc[time].checks.push(check);
|
||||
return acc;
|
||||
}, {});
|
||||
} else {
|
||||
groupedChecks = checksForDateRange.reduce((acc, check) => {
|
||||
const time = new Date(check.createdAt).toISOString().split("T")[0]; // Extract the date part
|
||||
if (!acc[time]) {
|
||||
acc[time] = { time, checks: [] };
|
||||
}
|
||||
acc[time].checks.push(check);
|
||||
return acc;
|
||||
}, {});
|
||||
}
|
||||
|
||||
// Map grouped checks to stats
|
||||
const aggregateData = Object.values(groupedChecks).map((group) => {
|
||||
const totalChecks = group.checks.length;
|
||||
const uptimePercentage = getUptimePercentage(group.checks);
|
||||
const totalIncidents = group.checks.filter(
|
||||
(check) => check.status === false
|
||||
).length;
|
||||
@@ -212,6 +223,7 @@ const getMonitorStatsById = async (req) => {
|
||||
|
||||
return {
|
||||
time: group.time,
|
||||
uptimePercentage,
|
||||
totalChecks,
|
||||
totalIncidents,
|
||||
avgResponseTime,
|
||||
@@ -220,7 +232,8 @@ const getMonitorStatsById = async (req) => {
|
||||
monitorStats.aggregateData = aggregateData;
|
||||
}
|
||||
|
||||
monitorStats.incidents = getIncidents(checksForDateRange);
|
||||
monitorStats.periodIncidents = getIncidents(checksForDateRange);
|
||||
monitorStats.periodTotalChecks = checksForDateRange.length;
|
||||
|
||||
// If more than numToDisplay checks, pick every nth check
|
||||
|
||||
|
||||
Reference in new issue
Block a user