mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-03-04 00:15:57 +00:00
extracted the redis monitor ot a different monitoring type
This commit is contained in:
parent
36196f632d
commit
c06eab0647
4 changed files with 48 additions and 43 deletions
|
@ -5,7 +5,7 @@ const { log, UP, DOWN, PENDING, MAINTENANCE, flipStatus, MAX_INTERVAL_SECOND, MI
|
||||||
SQL_DATETIME_FORMAT
|
SQL_DATETIME_FORMAT
|
||||||
} = require("../../src/util");
|
} = require("../../src/util");
|
||||||
const { tcping, ping, checkCertificate, checkStatusCode, getTotalClientInRoom, setting, mssqlQuery, postgresQuery, mysqlQuery, setSetting, httpNtlm, radius, grpcQuery,
|
const { tcping, ping, checkCertificate, checkStatusCode, getTotalClientInRoom, setting, mssqlQuery, postgresQuery, mysqlQuery, setSetting, httpNtlm, radius, grpcQuery,
|
||||||
redisPingAsync, mongodbPing, kafkaProducerAsync, getOidcTokenClientCredentials, rootCertificatesFingerprints, axiosAbortSignal
|
mongodbPing, kafkaProducerAsync, getOidcTokenClientCredentials, rootCertificatesFingerprints, axiosAbortSignal
|
||||||
} = require("../util-server");
|
} = 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");
|
||||||
|
@ -850,13 +850,6 @@ class Monitor extends BeanModel {
|
||||||
bean.msg = resp.code;
|
bean.msg = resp.code;
|
||||||
bean.status = UP;
|
bean.status = UP;
|
||||||
bean.ping = dayjs().valueOf() - startTime;
|
bean.ping = dayjs().valueOf() - startTime;
|
||||||
} else if (this.type === "redis") {
|
|
||||||
let startTime = dayjs().valueOf();
|
|
||||||
|
|
||||||
bean.msg = await redisPingAsync(this.databaseConnectionString);
|
|
||||||
bean.status = UP;
|
|
||||||
bean.ping = dayjs().valueOf() - startTime;
|
|
||||||
|
|
||||||
} else if (this.type in UptimeKumaServer.monitorTypeList) {
|
} else if (this.type in UptimeKumaServer.monitorTypeList) {
|
||||||
let startTime = dayjs().valueOf();
|
let startTime = dayjs().valueOf();
|
||||||
const monitorType = UptimeKumaServer.monitorTypeList[this.type];
|
const monitorType = UptimeKumaServer.monitorTypeList[this.type];
|
||||||
|
|
45
server/monitor-types/redis.js
Normal file
45
server/monitor-types/redis.js
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
const { MonitorType } = require("./monitor-type");
|
||||||
|
const { UP } = require("../../src/util");
|
||||||
|
const redis = require("redis");
|
||||||
|
|
||||||
|
class RedisMonitorType extends MonitorType {
|
||||||
|
name = "redis";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritdoc
|
||||||
|
*/
|
||||||
|
async check(monitor, heartbeat, _server) {
|
||||||
|
heartbeat.msg = await this.redisPingAsync(monitor.databaseConnectionString);
|
||||||
|
heartbeat.status = UP;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Redis server ping
|
||||||
|
* @param {string} dsn The redis connection string
|
||||||
|
* @returns {Promise<any>} Response from redis server
|
||||||
|
*/
|
||||||
|
async redisPingAsync(dsn) {
|
||||||
|
const client = redis.createClient({
|
||||||
|
url: dsn,
|
||||||
|
});
|
||||||
|
client.on("error", (err) => {
|
||||||
|
if (client.isOpen) {
|
||||||
|
client.disconnect();
|
||||||
|
}
|
||||||
|
throw err;
|
||||||
|
});
|
||||||
|
await client.connect();
|
||||||
|
if (!client.isOpen) {
|
||||||
|
throw new Error("connection isn't open after trying to connect");
|
||||||
|
}
|
||||||
|
const pingResult = client.ping();
|
||||||
|
if (client.isOpen) {
|
||||||
|
client.disconnect();
|
||||||
|
}
|
||||||
|
return pingResult;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
RedisMonitorType,
|
||||||
|
};
|
|
@ -113,6 +113,7 @@ class UptimeKumaServer {
|
||||||
UptimeKumaServer.monitorTypeList["tailscale-ping"] = new TailscalePing();
|
UptimeKumaServer.monitorTypeList["tailscale-ping"] = new TailscalePing();
|
||||||
UptimeKumaServer.monitorTypeList["dns"] = new DnsMonitorType();
|
UptimeKumaServer.monitorTypeList["dns"] = new DnsMonitorType();
|
||||||
UptimeKumaServer.monitorTypeList["mqtt"] = new MqttMonitorType();
|
UptimeKumaServer.monitorTypeList["mqtt"] = new MqttMonitorType();
|
||||||
|
UptimeKumaServer.monitorTypeList["redis"] = new RedisMonitorType();
|
||||||
|
|
||||||
// Allow all CORS origins (polling) in development
|
// Allow all CORS origins (polling) in development
|
||||||
let cors = undefined;
|
let cors = undefined;
|
||||||
|
@ -516,3 +517,4 @@ const { RealBrowserMonitorType } = require("./monitor-types/real-browser-monitor
|
||||||
const { TailscalePing } = require("./monitor-types/tailscale-ping");
|
const { TailscalePing } = require("./monitor-types/tailscale-ping");
|
||||||
const { DnsMonitorType } = require("./monitor-types/dns");
|
const { DnsMonitorType } = require("./monitor-types/dns");
|
||||||
const { MqttMonitorType } = require("./monitor-types/mqtt");
|
const { MqttMonitorType } = require("./monitor-types/mqtt");
|
||||||
|
const { RedisMonitorType } = require("./monitor-types/redis");
|
||||||
|
|
|
@ -17,7 +17,6 @@ const { Settings } = require("./settings");
|
||||||
const grpc = require("@grpc/grpc-js");
|
const grpc = require("@grpc/grpc-js");
|
||||||
const protojs = require("protobufjs");
|
const protojs = require("protobufjs");
|
||||||
const radiusClient = require("node-radius-client");
|
const radiusClient = require("node-radius-client");
|
||||||
const redis = require("redis");
|
|
||||||
const oidc = require("openid-client");
|
const oidc = require("openid-client");
|
||||||
const tls = require("tls");
|
const tls = require("tls");
|
||||||
|
|
||||||
|
@ -502,40 +501,6 @@ exports.radius = function (
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Redis server ping
|
|
||||||
* @param {string} dsn The redis connection string
|
|
||||||
* @returns {Promise<any>} Response from redis server
|
|
||||||
*/
|
|
||||||
exports.redisPingAsync = function (dsn) {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
const client = redis.createClient({
|
|
||||||
url: dsn
|
|
||||||
});
|
|
||||||
client.on("error", (err) => {
|
|
||||||
if (client.isOpen) {
|
|
||||||
client.disconnect();
|
|
||||||
}
|
|
||||||
reject(err);
|
|
||||||
});
|
|
||||||
client.connect().then(() => {
|
|
||||||
if (!client.isOpen) {
|
|
||||||
client.emit("error", new Error("connection isn't open"));
|
|
||||||
}
|
|
||||||
client.ping().then((res, err) => {
|
|
||||||
if (client.isOpen) {
|
|
||||||
client.disconnect();
|
|
||||||
}
|
|
||||||
if (err) {
|
|
||||||
reject(err);
|
|
||||||
} else {
|
|
||||||
resolve(res);
|
|
||||||
}
|
|
||||||
}).catch(error => reject(error));
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve value of setting based on key
|
* Retrieve value of setting based on key
|
||||||
* @param {string} key Key of setting to retrieve
|
* @param {string} key Key of setting to retrieve
|
||||||
|
|
Loading…
Add table
Reference in a new issue