Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Use UptimeCalculator for PingChart #4264

Merged
merged 26 commits into from
May 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
e78eb5e
WIP: fetch historic data for ping-chart
chakflying Dec 20, 2023
716dffa
Chore: Remove unused
chakflying Dec 20, 2023
cc22a87
Chore: Remove logging
chakflying Dec 20, 2023
bdfdcdb
Fix: chartPeriodHrs is always a string
chakflying Dec 20, 2023
4ab1a03
Fix: Do not show ping if not up
chakflying Dec 20, 2023
b5d1fc5
Chore: Fix comments
chakflying Dec 21, 2023
129dfbb
Feat: simple aggregate function
chakflying Dec 21, 2023
25ebfde
Chore: Change to button to preserve scroll position
chakflying Dec 21, 2023
05641d2
Feat: Improve aggregate using sliding window
chakflying Dec 21, 2023
1ba7935
Fix: css in dark mode
chakflying Dec 22, 2023
caec763
Fix: Use hourly data for chart
chakflying Dec 22, 2023
03b8e82
Fix: Do not push datapoint if ping is 0
chakflying Jan 6, 2024
909415b
Chore: Format code
chakflying Jan 6, 2024
86f2a86
Feat: Periodic refresh chart data
chakflying Jan 6, 2024
499632d
Feat: Support maintenance in chart
chakflying Jan 25, 2024
024db60
Chore: Set 24 Hrs as default
chakflying Jan 26, 2024
1a2a652
Feat: Insert empty datapoint to break time gaps
chakflying Jan 26, 2024
7688a04
Fix: Insert empty datapoint on both sides of the gap
chakflying Jan 26, 2024
2bb3fb1
Fix: Do not save timestamp in extras
chakflying Apr 6, 2024
6b03bb2
Chore: Change logging to debug only
chakflying Apr 6, 2024
1c34f30
Fix: Change role to type
chakflying Apr 9, 2024
73952b8
Chore: Simplify midpoint calc.
chakflying Apr 9, 2024
182f471
Chore: formatting
chakflying Apr 9, 2024
d9da681
Chore: Simplify bar def.
chakflying Apr 9, 2024
ddfe06c
Chore: Apply suggestions
chakflying Apr 13, 2024
c2f363b
Fix: Revert default value change
chakflying Apr 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ const apicache = require("./modules/apicache");
const { resetChrome } = require("./monitor-types/real-browser-monitor-type");
const { EmbeddedMariaDB } = require("./embedded-mariadb");
const { SetupDatabase } = require("./setup-database");
const { chartSocketHandler } = require("./socket-handlers/chart-socket-handler");

app.use(express.json());

Expand Down Expand Up @@ -1522,6 +1523,7 @@ let needSetup = false;
apiKeySocketHandler(socket);
remoteBrowserSocketHandler(socket);
generalSocketHandler(socket, server);
chartSocketHandler(socket);

log.debug("server", "added all socket handlers");

Expand Down
38 changes: 38 additions & 0 deletions server/socket-handlers/chart-socket-handler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const { checkLogin } = require("../util-server");
const { UptimeCalculator } = require("../uptime-calculator");
const { log } = require("../../src/util");

module.exports.chartSocketHandler = (socket) => {
socket.on("getMonitorChartData", async (monitorID, period, callback) => {
try {
checkLogin(socket);

log.debug("monitor", `Get Monitor Chart Data: ${monitorID} User ID: ${socket.userID}`);

if (period == null) {
throw new Error("Invalid period.");
}

let uptimeCalculator = await UptimeCalculator.getUptimeCalculator(monitorID);

let data;
if (period <= 24) {
data = uptimeCalculator.getDataArray(period * 60, "minute");
} else if (period <= 720) {
data = uptimeCalculator.getDataArray(period, "hour");
} else {
data = uptimeCalculator.getDataArray(period / 24, "day");
}

callback({
ok: true,
data,
});
} catch (e) {
callback({
ok: false,
msg: e.message,
});
}
});
};
6 changes: 3 additions & 3 deletions server/uptime-calculator.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ class UptimeCalculator {
dailyStatBean.pingMax = dailyData.maxPing;
{
// eslint-disable-next-line no-unused-vars
const { up, down, avgPing, minPing, maxPing, ...extras } = dailyData;
const { up, down, avgPing, minPing, maxPing, timestamp, ...extras } = dailyData;
if (Object.keys(extras).length > 0) {
dailyStatBean.extras = JSON.stringify(extras);
}
Expand All @@ -305,7 +305,7 @@ class UptimeCalculator {
hourlyStatBean.pingMax = hourlyData.maxPing;
{
// eslint-disable-next-line no-unused-vars
const { up, down, avgPing, minPing, maxPing, ...extras } = hourlyData;
const { up, down, avgPing, minPing, maxPing, timestamp, ...extras } = hourlyData;
if (Object.keys(extras).length > 0) {
hourlyStatBean.extras = JSON.stringify(extras);
}
Expand All @@ -320,7 +320,7 @@ class UptimeCalculator {
minutelyStatBean.pingMax = minutelyData.maxPing;
{
// eslint-disable-next-line no-unused-vars
const { up, down, avgPing, minPing, maxPing, ...extras } = minutelyData;
const { up, down, avgPing, minPing, maxPing, timestamp, ...extras } = minutelyData;
if (Object.keys(extras).length > 0) {
minutelyStatBean.extras = JSON.stringify(extras);
}
Expand Down
Loading
Loading