mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-02-26 13:35:56 +00:00
Compare commits
4 commits
c1e2860c1d
...
900f672005
Author | SHA1 | Date | |
---|---|---|---|
|
900f672005 | ||
|
46d8744fa4 | ||
|
7d8dc55dbe | ||
|
bd719d9987 |
8 changed files with 190 additions and 10 deletions
|
@ -23,7 +23,7 @@ It is a temporary live demo, all data will be deleted after 10 minutes. Sponsore
|
||||||
|
|
||||||
## ⭐ Features
|
## ⭐ Features
|
||||||
|
|
||||||
- Monitoring uptime for HTTP(s) / TCP / HTTP(s) Keyword / HTTP(s) Json Query / Ping / DNS Record / Push / Steam Game Server / Docker Containers
|
- Monitoring uptime for HTTP(s) / TCP / HTTP(s) Keyword / HTTP(s) Json Query / Ping / DNS Record / Push / Steam Game Server / Docker Containers / Docker Services
|
||||||
- Fancy, Reactive, Fast UI/UX
|
- Fancy, Reactive, Fast UI/UX
|
||||||
- Notifications via Telegram, Discord, Gotify, Slack, Pushover, Email (SMTP), and [90+ notification services, click here for the full list](https://github.com/louislam/uptime-kuma/tree/master/src/components/notifications)
|
- Notifications via Telegram, Discord, Gotify, Slack, Pushover, Email (SMTP), and [90+ notification services, click here for the full list](https://github.com/louislam/uptime-kuma/tree/master/src/components/notifications)
|
||||||
- 20-second intervals
|
- 20-second intervals
|
||||||
|
|
11
db/knex_migrations/2024-10-17-0000-add-docker-service.js
Normal file
11
db/knex_migrations/2024-10-17-0000-add-docker-service.js
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
exports.up = function (knex) {
|
||||||
|
return knex.schema.alterTable("monitor", function (table) {
|
||||||
|
table.string("docker_service", 255);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.down = function (knex) {
|
||||||
|
return knex.schema.alterTable("monitor", function (table) {
|
||||||
|
table.dropColumn("docker_service");
|
||||||
|
});
|
||||||
|
};
|
|
@ -27,7 +27,6 @@ RUN mkdir ./data
|
||||||
# ⭐ Main Image
|
# ⭐ Main Image
|
||||||
############################################
|
############################################
|
||||||
FROM $BASE_IMAGE AS release
|
FROM $BASE_IMAGE AS release
|
||||||
USER node
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
LABEL org.opencontainers.image.source="https://github.com/louislam/uptime-kuma"
|
LABEL org.opencontainers.image.source="https://github.com/louislam/uptime-kuma"
|
||||||
|
@ -46,6 +45,7 @@ CMD ["node", "server/server.js"]
|
||||||
# Rootless Image
|
# Rootless Image
|
||||||
############################################
|
############################################
|
||||||
FROM release AS rootless
|
FROM release AS rootless
|
||||||
|
USER node
|
||||||
|
|
||||||
############################################
|
############################################
|
||||||
# Mark as Nightly
|
# Mark as Nightly
|
||||||
|
|
|
@ -9,6 +9,7 @@ const mysql = require("mysql2/promise");
|
||||||
const { Settings } = require("./settings");
|
const { Settings } = require("./settings");
|
||||||
const { UptimeCalculator } = require("./uptime-calculator");
|
const { UptimeCalculator } = require("./uptime-calculator");
|
||||||
const dayjs = require("dayjs");
|
const dayjs = require("dayjs");
|
||||||
|
const { SimpleMigrationServer } = require("./utils/simple-migration-server");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Database & App Data Folder
|
* Database & App Data Folder
|
||||||
|
@ -382,9 +383,11 @@ class Database {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Patch the database
|
* Patch the database
|
||||||
|
* @param {number} port Start the migration server for aggregate tables on this port if provided
|
||||||
|
* @param {string} hostname Start the migration server for aggregate tables on this hostname if provided
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
static async patch() {
|
static async patch(port = undefined, hostname = undefined) {
|
||||||
// Still need to keep this for old versions of Uptime Kuma
|
// Still need to keep this for old versions of Uptime Kuma
|
||||||
if (Database.dbConfig.type === "sqlite") {
|
if (Database.dbConfig.type === "sqlite") {
|
||||||
await this.patchSqlite();
|
await this.patchSqlite();
|
||||||
|
@ -409,7 +412,7 @@ class Database {
|
||||||
await R.exec("PRAGMA foreign_keys = ON");
|
await R.exec("PRAGMA foreign_keys = ON");
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.migrateAggregateTable();
|
await this.migrateAggregateTable(port, hostname);
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// Allow missing patch files for downgrade or testing pr.
|
// Allow missing patch files for downgrade or testing pr.
|
||||||
|
@ -735,9 +738,11 @@ class Database {
|
||||||
* Normally, it should be in transaction, but UptimeCalculator wasn't designed to be in transaction before that.
|
* Normally, it should be in transaction, but UptimeCalculator wasn't designed to be in transaction before that.
|
||||||
* I don't want to heavily modify the UptimeCalculator, so it is not in transaction.
|
* I don't want to heavily modify the UptimeCalculator, so it is not in transaction.
|
||||||
* Run `npm run reset-migrate-aggregate-table-state` to reset, in case the migration is interrupted.
|
* Run `npm run reset-migrate-aggregate-table-state` to reset, in case the migration is interrupted.
|
||||||
|
* @param {number} port Start the migration server on this port if provided
|
||||||
|
* @param {string} hostname Start the migration server on this hostname if provided
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
static async migrateAggregateTable() {
|
static async migrateAggregateTable(port, hostname = undefined) {
|
||||||
log.debug("db", "Enter Migrate Aggregate Table function");
|
log.debug("db", "Enter Migrate Aggregate Table function");
|
||||||
|
|
||||||
// Add a setting for 2.0.0-dev users to skip this migration
|
// Add a setting for 2.0.0-dev users to skip this migration
|
||||||
|
@ -758,6 +763,18 @@ class Database {
|
||||||
throw new Error("Aggregate table migration is already in progress");
|
throw new Error("Aggregate table migration is already in progress");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start migration server for displaying the migration status
|
||||||
|
* @type {SimpleMigrationServer}
|
||||||
|
*/
|
||||||
|
let migrationServer;
|
||||||
|
let msg;
|
||||||
|
|
||||||
|
if (port) {
|
||||||
|
migrationServer = new SimpleMigrationServer();
|
||||||
|
await migrationServer.start(port, hostname);
|
||||||
|
}
|
||||||
|
|
||||||
await Settings.set("migrateAggregateTableState", "migrating");
|
await Settings.set("migrateAggregateTableState", "migrating");
|
||||||
|
|
||||||
log.info("db", "Migrating Aggregate Table");
|
log.info("db", "Migrating Aggregate Table");
|
||||||
|
@ -777,6 +794,7 @@ class Database {
|
||||||
let count = countResult.count;
|
let count = countResult.count;
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
log.warn("db", `Aggregate table ${table} is not empty, migration will not be started (Maybe you were using 2.0.0-dev?)`);
|
log.warn("db", `Aggregate table ${table} is not empty, migration will not be started (Maybe you were using 2.0.0-dev?)`);
|
||||||
|
await migrationServer?.stop();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -811,7 +829,9 @@ class Database {
|
||||||
`, [ monitor.monitor_id, date.date ]);
|
`, [ monitor.monitor_id, date.date ]);
|
||||||
|
|
||||||
if (heartbeats.length > 0) {
|
if (heartbeats.length > 0) {
|
||||||
log.info("db", `[DON'T STOP] Migrating monitor data ${monitor.monitor_id} - ${date.date} [${progressPercent.toFixed(2)}%][${i}/${monitors.length}]`);
|
msg = `[DON'T STOP] Migrating monitor data ${monitor.monitor_id} - ${date.date} [${progressPercent.toFixed(2)}%][${i}/${monitors.length}]`;
|
||||||
|
log.info("db", msg);
|
||||||
|
migrationServer?.update(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let heartbeat of heartbeats) {
|
for (let heartbeat of heartbeats) {
|
||||||
|
@ -829,9 +849,13 @@ class Database {
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
await Database.clearHeartbeatData(true);
|
msg = "Clearing non-important heartbeats";
|
||||||
|
log.info("db", msg);
|
||||||
|
migrationServer?.update(msg);
|
||||||
|
|
||||||
|
await Database.clearHeartbeatData(true);
|
||||||
await Settings.set("migrateAggregateTableState", "migrated");
|
await Settings.set("migrateAggregateTableState", "migrated");
|
||||||
|
await migrationServer?.stop();
|
||||||
|
|
||||||
if (monitors.length > 0) {
|
if (monitors.length > 0) {
|
||||||
log.info("db", "Aggregate Table Migration Completed");
|
log.info("db", "Aggregate Table Migration Completed");
|
||||||
|
|
|
@ -120,6 +120,7 @@ class Monitor extends BeanModel {
|
||||||
dns_resolve_server: this.dns_resolve_server,
|
dns_resolve_server: this.dns_resolve_server,
|
||||||
dns_last_result: this.dns_last_result,
|
dns_last_result: this.dns_last_result,
|
||||||
docker_container: this.docker_container,
|
docker_container: this.docker_container,
|
||||||
|
docker_service: this.docker_service,
|
||||||
docker_host: this.docker_host,
|
docker_host: this.docker_host,
|
||||||
proxyId: this.proxy_id,
|
proxyId: this.proxy_id,
|
||||||
notificationIDList: preloadData.notifications.get(this.id) || {},
|
notificationIDList: preloadData.notifications.get(this.id) || {},
|
||||||
|
@ -757,6 +758,54 @@ class Monitor extends BeanModel {
|
||||||
} else {
|
} else {
|
||||||
throw Error("Container State is " + res.data.State.Status);
|
throw Error("Container State is " + res.data.State.Status);
|
||||||
}
|
}
|
||||||
|
} else if (this.type === "docker-service-availability") { // TODO: add a service-health to count running vs desired (needs services api)
|
||||||
|
log.debug("monitor", `[${this.name}] Prepare Options for Axios`);
|
||||||
|
|
||||||
|
const options = {
|
||||||
|
url: `/tasks?filters={"service":{"${this.docker_service}":true}}`,
|
||||||
|
timeout: this.interval * 1000 * 0.8,
|
||||||
|
headers: {
|
||||||
|
"Accept": "*/*",
|
||||||
|
},
|
||||||
|
httpsAgent: new https.Agent({
|
||||||
|
maxCachedSessions: 0, // Use Custom agent to disable session reuse (https://github.com/nodejs/node/issues/3940)
|
||||||
|
rejectUnauthorized: !this.getIgnoreTls(),
|
||||||
|
secureOptions: crypto.constants.SSL_OP_LEGACY_SERVER_CONNECT,
|
||||||
|
}),
|
||||||
|
httpAgent: new http.Agent({
|
||||||
|
maxCachedSessions: 0,
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
|
||||||
|
const dockerHost = await R.load("docker_host", this.docker_host);
|
||||||
|
|
||||||
|
if (!dockerHost) {
|
||||||
|
throw new Error("Failed to load docker host config");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dockerHost._dockerType === "socket") {
|
||||||
|
options.socketPath = dockerHost._dockerDaemon;
|
||||||
|
} else if (dockerHost._dockerType === "tcp") {
|
||||||
|
options.baseURL = DockerHost.patchDockerURL(dockerHost._dockerDaemon);
|
||||||
|
options.httpsAgent = new https.Agent(
|
||||||
|
DockerHost.getHttpsAgentOptions(dockerHost._dockerType, options.baseURL)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
log.debug("monitor", `[${this.name}] Axios Request (get service tasks)`);
|
||||||
|
let res = await axios.request(options);
|
||||||
|
|
||||||
|
if (res.data.message) {
|
||||||
|
throw Error(res.data.message);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (res.data.filter((task) => task.Status.State === "running").length) {
|
||||||
|
bean.status = UP;
|
||||||
|
bean.msg = `Service: ${this.docker_service} is available`;
|
||||||
|
} else {
|
||||||
|
bean.status = DOWN;
|
||||||
|
bean.msg = `Service: ${this.docker_service} is Down. No replicas available`;
|
||||||
|
}
|
||||||
} else if (this.type === "sqlserver") {
|
} else if (this.type === "sqlserver") {
|
||||||
let startTime = dayjs().valueOf();
|
let startTime = dayjs().valueOf();
|
||||||
|
|
||||||
|
|
|
@ -828,6 +828,7 @@ let needSetup = false;
|
||||||
bean.dns_resolve_server = monitor.dns_resolve_server;
|
bean.dns_resolve_server = monitor.dns_resolve_server;
|
||||||
bean.pushToken = monitor.pushToken;
|
bean.pushToken = monitor.pushToken;
|
||||||
bean.docker_container = monitor.docker_container;
|
bean.docker_container = monitor.docker_container;
|
||||||
|
bean.docker_service = monitor.docker_service;
|
||||||
bean.docker_host = monitor.docker_host;
|
bean.docker_host = monitor.docker_host;
|
||||||
bean.proxyId = Number.isInteger(monitor.proxyId) ? monitor.proxyId : null;
|
bean.proxyId = Number.isInteger(monitor.proxyId) ? monitor.proxyId : null;
|
||||||
bean.mqttUsername = monitor.mqttUsername;
|
bean.mqttUsername = monitor.mqttUsername;
|
||||||
|
@ -1716,7 +1717,7 @@ async function initDatabase(testMode = false) {
|
||||||
log.info("server", "Connected to the database");
|
log.info("server", "Connected to the database");
|
||||||
|
|
||||||
// Patch the database
|
// Patch the database
|
||||||
await Database.patch();
|
await Database.patch(port, hostname);
|
||||||
|
|
||||||
let jwtSecretBean = await R.findOne("setting", " `key` = ? ", [
|
let jwtSecretBean = await R.findOne("setting", " `key` = ? ", [
|
||||||
"jwtSecret",
|
"jwtSecret",
|
||||||
|
|
84
server/utils/simple-migration-server.js
Normal file
84
server/utils/simple-migration-server.js
Normal file
|
@ -0,0 +1,84 @@
|
||||||
|
const express = require("express");
|
||||||
|
const http = require("node:http");
|
||||||
|
const { log } = require("../../src/util");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SimpleMigrationServer
|
||||||
|
* For displaying the migration status of the server
|
||||||
|
* Also, it is used to let Docker healthcheck know the status of the server, as the main server is not started yet, healthcheck will think the server is down incorrectly.
|
||||||
|
*/
|
||||||
|
class SimpleMigrationServer {
|
||||||
|
/**
|
||||||
|
* Express app instance
|
||||||
|
* @type {?Express}
|
||||||
|
*/
|
||||||
|
app;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Server instance
|
||||||
|
* @type {?Server}
|
||||||
|
*/
|
||||||
|
server;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Response object
|
||||||
|
* @type {?Response}
|
||||||
|
*/
|
||||||
|
response;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start the server
|
||||||
|
* @param {number} port Port
|
||||||
|
* @param {string} hostname Hostname
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
start(port, hostname) {
|
||||||
|
this.app = express();
|
||||||
|
this.server = http.createServer(this.app);
|
||||||
|
|
||||||
|
this.app.get("/", (req, res) => {
|
||||||
|
res.set("Content-Type", "text/plain");
|
||||||
|
res.write("Migration is in progress, listening message...\n");
|
||||||
|
if (this.response) {
|
||||||
|
this.response.write("Disconnected\n");
|
||||||
|
this.response.end();
|
||||||
|
}
|
||||||
|
this.response = res;
|
||||||
|
// never ending response
|
||||||
|
});
|
||||||
|
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
this.server.listen(port, hostname, () => {
|
||||||
|
if (hostname) {
|
||||||
|
log.info("migration", `Migration server is running on http://${hostname}:${port}`);
|
||||||
|
} else {
|
||||||
|
log.info("migration", `Migration server is running on http://localhost:${port}`);
|
||||||
|
}
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the message
|
||||||
|
* @param {string} msg Message to update
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
|
update(msg) {
|
||||||
|
this.response?.write(msg + "\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stop the server
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
async stop() {
|
||||||
|
this.response?.write("Finished, please refresh this page.\n");
|
||||||
|
this.response?.end();
|
||||||
|
await this.server?.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
SimpleMigrationServer,
|
||||||
|
};
|
|
@ -42,6 +42,9 @@
|
||||||
<option value="docker">
|
<option value="docker">
|
||||||
{{ $t("Docker Container") }}
|
{{ $t("Docker Container") }}
|
||||||
</option>
|
</option>
|
||||||
|
<option value="docker-service-availability">
|
||||||
|
{{ $t("Docker Service (Simple Availability)") }}
|
||||||
|
</option>
|
||||||
|
|
||||||
<option value="real-browser">
|
<option value="real-browser">
|
||||||
HTTP(s) - Browser Engine (Chrome/Chromium) (Beta)
|
HTTP(s) - Browser Engine (Chrome/Chromium) (Beta)
|
||||||
|
@ -414,9 +417,16 @@
|
||||||
<input id="docker_container" v-model="monitor.docker_container" type="text" class="form-control" required>
|
<input id="docker_container" v-model="monitor.docker_container" type="text" class="form-control" required>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Docker Service Name / ID -->
|
||||||
|
<!-- For Docker Service Type -->
|
||||||
|
<div v-if="monitor.type === 'docker-service-availability'" class="my-3">
|
||||||
|
<label for="docker_service" class="form-label">{{ $t("Service Name / ID") }}</label>
|
||||||
|
<input id="docker_service" v-model="monitor.docker_service" type="text" class="form-control" required>
|
||||||
|
</div>
|
||||||
|
|
||||||
<!-- Docker Host -->
|
<!-- Docker Host -->
|
||||||
<!-- For Docker Type -->
|
<!-- For Docker Type -->
|
||||||
<div v-if="monitor.type === 'docker'" class="my-3">
|
<div v-if="['docker', 'docker-service-availability'].includes(monitor.type)" class="my-3">
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="docker-host" class="form-label">{{ $t("Docker Host") }}</label>
|
<label for="docker-host" class="form-label">{{ $t("Docker Host") }}</label>
|
||||||
<ActionSelect
|
<ActionSelect
|
||||||
|
@ -1150,6 +1160,7 @@ const monitorDefaults = {
|
||||||
dns_resolve_type: "A",
|
dns_resolve_type: "A",
|
||||||
dns_resolve_server: "1.1.1.1",
|
dns_resolve_server: "1.1.1.1",
|
||||||
docker_container: "",
|
docker_container: "",
|
||||||
|
docker_service: "",
|
||||||
docker_host: null,
|
docker_host: null,
|
||||||
proxyId: null,
|
proxyId: null,
|
||||||
mqttUsername: "",
|
mqttUsername: "",
|
||||||
|
@ -1784,7 +1795,7 @@ message HealthCheckResponse {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this.monitor.type === "docker") {
|
if ([ "docker", "docker-service-availability" ].includes(this.monitor.type)) {
|
||||||
if (this.monitor.docker_host == null) {
|
if (this.monitor.docker_host == null) {
|
||||||
toast.error(this.$t("DockerHostRequired"));
|
toast.error(this.$t("DockerHostRequired"));
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Add table
Reference in a new issue