|
|
@ -6,7 +6,7 @@ dayjs.extend(utc)
|
|
|
|
dayjs.extend(timezone)
|
|
|
|
dayjs.extend(timezone)
|
|
|
|
const axios = require("axios");
|
|
|
|
const axios = require("axios");
|
|
|
|
const { Prometheus } = require("../prometheus");
|
|
|
|
const { Prometheus } = require("../prometheus");
|
|
|
|
const { debug, UP, DOWN, PENDING, flipStatus } = require("../../src/util");
|
|
|
|
const { debug, UP, DOWN, PENDING, flipStatus, TimeLogger } = require("../../src/util");
|
|
|
|
const { tcping, ping, checkCertificate, checkStatusCode } = require("../util-server");
|
|
|
|
const { tcping, ping, checkCertificate, checkStatusCode } = require("../util-server");
|
|
|
|
const { R } = require("redbean-node");
|
|
|
|
const { R } = require("redbean-node");
|
|
|
|
const { BeanModel } = require("redbean-node/dist/bean-model");
|
|
|
|
const { BeanModel } = require("redbean-node/dist/bean-model");
|
|
|
@ -133,7 +133,6 @@ class Monitor extends BeanModel {
|
|
|
|
bean.ping = dayjs().valueOf() - startTime;
|
|
|
|
bean.ping = dayjs().valueOf() - startTime;
|
|
|
|
|
|
|
|
|
|
|
|
// Check certificate if https is used
|
|
|
|
// Check certificate if https is used
|
|
|
|
|
|
|
|
|
|
|
|
let certInfoStartTime = dayjs().valueOf();
|
|
|
|
let certInfoStartTime = dayjs().valueOf();
|
|
|
|
if (this.getUrl()?.protocol === "https:") {
|
|
|
|
if (this.getUrl()?.protocol === "https:") {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
@ -311,10 +310,10 @@ class Monitor extends BeanModel {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static async sendStats(io, monitorID, userID) {
|
|
|
|
static async sendStats(io, monitorID, userID) {
|
|
|
|
Monitor.sendAvgPing(24, io, monitorID, userID);
|
|
|
|
await Monitor.sendAvgPing(24, io, monitorID, userID);
|
|
|
|
Monitor.sendUptime(24, io, monitorID, userID);
|
|
|
|
await Monitor.sendUptime(24, io, monitorID, userID);
|
|
|
|
Monitor.sendUptime(24 * 30, io, monitorID, userID);
|
|
|
|
await Monitor.sendUptime(24 * 30, io, monitorID, userID);
|
|
|
|
Monitor.sendCertInfo(io, monitorID, userID);
|
|
|
|
await Monitor.sendCertInfo(io, monitorID, userID);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -322,6 +321,8 @@ class Monitor extends BeanModel {
|
|
|
|
* @param duration : int Hours
|
|
|
|
* @param duration : int Hours
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
static async sendAvgPing(duration, io, monitorID, userID) {
|
|
|
|
static async sendAvgPing(duration, io, monitorID, userID) {
|
|
|
|
|
|
|
|
const timeLogger = new TimeLogger();
|
|
|
|
|
|
|
|
|
|
|
|
let avgPing = parseInt(await R.getCell(`
|
|
|
|
let avgPing = parseInt(await R.getCell(`
|
|
|
|
SELECT AVG(ping)
|
|
|
|
SELECT AVG(ping)
|
|
|
|
FROM heartbeat
|
|
|
|
FROM heartbeat
|
|
|
@ -332,6 +333,8 @@ class Monitor extends BeanModel {
|
|
|
|
monitorID,
|
|
|
|
monitorID,
|
|
|
|
]));
|
|
|
|
]));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
timeLogger.print(`[Monitor: ${monitorID}] avgPing`);
|
|
|
|
|
|
|
|
|
|
|
|
io.to(userID).emit("avgPing", monitorID, avgPing);
|
|
|
|
io.to(userID).emit("avgPing", monitorID, avgPing);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -351,6 +354,8 @@ class Monitor extends BeanModel {
|
|
|
|
* @param duration : int Hours
|
|
|
|
* @param duration : int Hours
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
static async sendUptime(duration, io, monitorID, userID) {
|
|
|
|
static async sendUptime(duration, io, monitorID, userID) {
|
|
|
|
|
|
|
|
const timeLogger = new TimeLogger();
|
|
|
|
|
|
|
|
|
|
|
|
let sec = duration * 3600;
|
|
|
|
let sec = duration * 3600;
|
|
|
|
|
|
|
|
|
|
|
|
let heartbeatList = await R.getAll(`
|
|
|
|
let heartbeatList = await R.getAll(`
|
|
|
@ -362,6 +367,8 @@ class Monitor extends BeanModel {
|
|
|
|
monitorID,
|
|
|
|
monitorID,
|
|
|
|
]);
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
timeLogger.print(`[Monitor: ${monitorID}][${duration}] sendUptime`);
|
|
|
|
|
|
|
|
|
|
|
|
let downtime = 0;
|
|
|
|
let downtime = 0;
|
|
|
|
let total = 0;
|
|
|
|
let total = 0;
|
|
|
|
let uptime;
|
|
|
|
let uptime;
|
|
|
|