-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: fetch historic data for ping-chart
- Loading branch information
1 parent
72e94a0
commit e7bd396
Showing
5 changed files
with
217 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
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.info("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 { | ||
data = uptimeCalculator.getDataArray(period / 24, "day"); | ||
} | ||
|
||
console.log(data); | ||
|
||
callback({ | ||
ok: true, | ||
data, | ||
}); | ||
} catch (e) { | ||
callback({ | ||
ok: false, | ||
msg: e.message, | ||
}); | ||
} | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters